0
votes

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:

  • Missing required property: paths
  • Additional properties not allowed: models,apis,resourcePath,swaggerVersion,apiVersion
  • ...

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/#/

1
Please open a ticket via github.com/swagger-api/swagger-codegen/issues with the spec to reproduce the issue. You can also try github.com/lucybot/api-spec-converter to convert your swagger spec from 1.2 to 2.0 before using swagger codegen to generate client libraries or server stubs.William Cheng
Hello, I've tried this, but the spec that I used was "downsized" meaning, calls with the same path (although different amount of arguments) were removed and it appears that only one remained. I will make a ticket for this :-)Xabre

1 Answers

2
votes

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).