[BUG] DefaultCodeGen doesn't recurse into nested types when looking for imports
Created by: eak24
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?
Description
When specifying schemas that have nested types (for instance, Map<String, Map<String, MyType>>
), the MyType
custom type doesn't get added to the list of imports and so all the generated clients fail to resolve the MyType
symbol in the related API. I noticed this with Python Client, but I believe it would effect others as well.
openapi-generator version
5.3.1
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Test additional properties with ref
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/ping:
post:
operationId: ping
responses:
default:
description: default response
content:
application/json:
schema:
type: object
additionalProperties:
type: object
additionalProperties:
type: object
additionalProperties:
"$ref": "#/components/schemas/Person"
components:
schemas:
Person:
type: object
properties:
lastName:
type: string
firstName:
type: string
Also here
Generation Details
A simple generation command, like openapi-generator generate -g python
will make a Python client that fails during symbol resolution because Person
won't be imported in default_api.py
.
Steps to reproduce
Assuming pipenv and openapi-generator-cli are both installed and on the path...
openapi-generator-cli generate -g python -i https://gist.githubusercontent.com/ethan92429/07a09ac228dcd2f9ec0b957ddb44148b/raw/074beff13727280dd8119c3547ac36d28e58559b/openApi_generator_issue_11220.yaml &&
pipenv install -r requirements.txt &&
pipenv install -r test-requirements.txt &&
pytest --cov=openapi_client
Related issues/PRs
Suggest a fix
Working on this...