Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swagger-codegen using JSON parser when YML is provided

Trying to generate API classes for PHP using swagger-codegen.

[According to the docs][1], it should automatically know the difference between JSON and YML.

It does not look like to be the case tho:

docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate \
    -i https://.../interface.yml \
    -l php \
    -o /local/out/php

Exception:

[main] ERROR io.swagger.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')
 at [Source: (String)"openapi: 3.0.1
info:
  title: Orders
  description: This API documentation describes all endpoints for orders
...

What are the correct instructions to generate a client and entities from from YML?

like image 716
Daniel W. Avatar asked Aug 31 '25 02:08

Daniel W.


1 Answers

You are using Swagger Codegen 2.x which does not support OpenAPI 3.0.

Use codegen version 3.x instead:
https://hub.docker.com/r/swaggerapi/swagger-codegen-cli-v3/

like image 73
Helen Avatar answered Sep 03 '25 22:09

Helen