OpenAPITools / OpenAPITools/openapi-generator

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

Open
#16,933 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the api.json reproduction and run the OpenAPI Generator CLI for the Dart Dio target using the reported 3.1.0 setup; compare the generated TestUrl1200Response fields for arr1 and arr2. Check the generated output against the 3.0.3 result and the expected BuiltList type for arr2. Done means an external $ref no longer causes this array to be generated as JsonObject.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.