Search code examples
openapiopenapi-generator

Parse error generating server stub with openapitools/openapi-generator-cli using OAS 3.0


I am trying to generate server code using openapitools/openapi-generator-cli which I installed globally using NPM.

When I run the command: openapi-generator generate -i MyApi.yaml -g aspnetcore -o ./src

I get the following error:

[main] ERROR i.s.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')

I have also tried converting my spec file to json and encountered the same error.

How can I resolve this error with parsing the yaml file?


Solution

  • I ran my spec file through the online editor at http://editor.swagger.io/ and found an error in my yaml (I forgot to add a parameter entry for a path with a parameter in the path). Once I fixed the error, the generator worked correctly.

    So this was user error, though the error message could be better.