Xabre
Xabre

Reputation: 1320

Swagger Codegen reverse compatibility

I have started on using Swagger. At this point, I have received a swagger file for swagger version 1.2. However, if I want to generate something with this file, it just gives me a bunch of errors that look more like it just ignores the fact that my swagger file is in version 1.2 spec and just goes ahead and validates it against version 2.0 of the spec.

Some of the errors I got:

The last error tells me that apiVersion is unknown, although the gitHub page claims that the latest stable is supposed to be compatible with version 1.0, 1.1, 1.2 and 2.0. Is there a way that I can "force" the generator to think 1.2 spec instead of 2.0 spec?

I've verified with an official 1.2 spec yaml file too: https://raw.githubusercontent.com/swagger-api/swagger-codegen/v2.0.18/samples/yaml/pet.yml

But it gives the same errors when you load it in the Swagger editor: http://editor.swagger.io/#/

Upvotes: 0

Views: 878

Answers (1)

fehguy
fehguy

Reputation: 6824

The swagger-codegen project relies on the swagger-parser, which has a module called swagger-compat-spec-parser which will actually convert your 1.2 specification into 2.0 format before passing on to the code generator.

The errors you're seeing are because that conversion has failed. You can save you swagger 1.2 files locally, tweak them, and re-run the processing.

The challenge with the 1.2 to 2.0 conversion is that swagger 1.2 did not initially have a schema to validate against. Thus there are a lot of invalid swaggers out there, and it's technically impossible to convert all the different issues in 1.2 specs into 2.0.

That said, we are always trying to make the tooling better so if you find a "repeatable" bug in the 1.2 converter, file an issue in the swagger-spec project and we'll see about fixing it (most are easy).

Upvotes: 2

Related Questions