openapi
openapi copied to clipboard
Swagger-codegen OpenAPI 2.0 fails
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.
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?
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.
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.
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!
Alright, I've pushed a new version of the 2.0 OpenAPI spec in 8241e4c03ca5229d59632d183dfbccae9782f901. Thanks for letting me know about this!
Thanks for the quick fix!