openapi icon indicating copy to clipboard operation
openapi copied to clipboard

Swagger-codegen OpenAPI 2.0 fails

Open jvelilla opened this issue 7 years ago • 6 comments

I've run swagger codegen with spec2.json and I got the following issue

[main] ERROR io.swagger.codegen.Codegen - Could not process operation: Tag: Tag { name: default description: null externalDocs: null extensions:{}} Operation: UpdateAccountBankAccount .....

Reading the specification file [spec2.json] https://github.com/stripe/openapi/blob/master/openapi/spec2.json), I've found the issue is the way it describes an array of strings not following the specification.

 "type": ["array","string" ]

instead of the standard way

 "type": "array",
 "items": "string"
              

After doing that the swagger-codegen works fine.

jvelilla avatar Sep 12 '17 15:09 jvelilla

Interesting! We also had a previous report of this in #5, but I'll keep this open since it seems that you were able to fix it.

So those two blocks that you've posted are a little bit different: the first says that the described object may be an array or a string, and the second says that it will be an array where each item in the array is a string.

It's good to know that this is the reason for the failure though. How many places did you have to fix manually to get it working?

brandur-stripe avatar Sep 12 '17 16:09 brandur-stripe

Neither OpenAPI 2.0 or 3.0 supports type taking an array. I believe this is an error of omission in the 2.0 spec, but it is called out explicitly for 3.0

type - Value MUST be a string. Multiple types via an array are not supported.

OpenAPI 3.0 supports the anyOf construct which would allow:

anyOf:
  - type: string
  - type: array

In 2.0 you can omit the type property entirely and any type will be permitted.

MikeRalphson avatar Nov 14 '17 10:11 MikeRalphson

Running into the same issue. The stripe api definition starts like this:

  "definitions": {
    "account": {
      "properties": {
        "business_name": {
          "description": "The publicly visible name of the business.",
          "type": [
            "string"
          ]
        },

but it should be

  "definitions": {
    "account": {
      "properties": {
        "business_name": {
          "description": "The publicly visible name of the business.",
          "type": "string"
        },

The swagger parser ignores all properties with types declared as arrays.

dflorey avatar Jan 10 '18 17:01 dflorey

So I believe we're already generating type as just a string for OpenAPI 3.0.

OpenAPI 2.0 is definitely an array, but it should be a relatively easy fix. I'll look into it. Thanks for the details!

brandur-stripe avatar Jan 10 '18 18:01 brandur-stripe

Alright, I've pushed a new version of the 2.0 OpenAPI spec in 8241e4c03ca5229d59632d183dfbccae9782f901. Thanks for letting me know about this!

brandur-stripe avatar Jan 10 '18 20:01 brandur-stripe

Thanks for the quick fix!

dflorey avatar Jan 11 '18 09:01 dflorey