OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

[BUG] [dart-dio] The array is recognized as an object (3.1.0 - only) #16933

Open DisDis opened 10 months ago

DisDis commented 10 months ago

Bug Report Checklist

Description

When use $ref with file 'api.json', 'array' in spec will generate code for 'object' type,

openapi-generator version

3.1.0 - bug 3.0.3 - work fine

OpenAPI declaration file content or url

Create api.json, it reproduce only when use $ref with file.

{
    "paths": {
        "/testUrl": {
            "post": {
                "operationId": "testUrl1",
                "tags": [
                    "test"
                ],
                "requestBody": {
                    "required": true,
                    "description": "Input data",
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "api.json#/components/schemas/Type1"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Updated data",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "api.json#/components/schemas/Type2"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Type1": {
                "type": "object",
                "properties": {
                    "arr3": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "arr4": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                }
            },
            "Type2": {
                "type": "object",
                "properties": {
                    "arr1": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "arr2": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                }
            }

        }
    },
    "openapi": "3.1.0",
    "info": {
        "version": "1.0.0",
        "title": "API part",
        "license": {
            "name": "MIT",
            "identifier": "MIT"
        }
    },
    "servers": [
        {
            "url": "http://localhost:8090/v1"
        },
        {
            "url": "http://localhost:8080/v1"
        }
    ]
}
Generation Details

CLI generates incorrect TestUrl1200Response class, when use $ref with file

  @BuiltValueField(wireName: r'arr1')
  BuiltList<String>? get arr1;

  @BuiltValueField(wireName: r'arr2')
  JsonObject? get arr2;

expected

  BuiltList<String>? get arr2;

for spec:

"Type2": {
    "type": "object",
    "properties": {
        "arr1": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "arr2": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    }
}
Steps to reproduce
  1. Create 'api.json'
  2. Run openapi-generator 3.1.0
mickroll commented 9 months ago

I think the author of the issue wanted to say that generation using spec version "openapi": "3.1.0" is broken, whereas it works with "openapi": "3.0.3".