-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] DefaultCodeGen doesn't recurse into nested types when looking for imports #11220
Comments
Its not just the import library that's missing, its also the type information (at least in pyhon-flask, although I suspect its everything.) This does not show up until the object is loaded. It will write the object OK, but when a serialized version is loaded, it causes a runtime error on the type information. For example vector:
type: array
items:
type: number
format: float
minItems: 2
maxItems: 2
description: image vector in the format [x,y]
polygon:
type: array
items:
$ref: '#/vector'
path:
$ref: '#/polygon'
description: Path in some object.
self.openapi_types = {
...,
'path': List[List],
...
} when it should be self.openapi_types = {
...,
'path': List[List[float]],
...
} The |
I thought I it would be a good idea to create a better and extended test for the type problem, so I built the following set of test cases $schema: http://json-schema.org/draft-07/schema#
vector:
type: array
items:
type: number
format: float
minItems: 2
maxItems: 2
description: image vector in the format [x,y]
polygon:
type: array
items:
$ref: '#/vector'
ext_polygon:
type: array
items:
type: array
items:
$ref: '#/vector'
raw_polygon:
type: array
items:
type: array
items:
type: number
format: float
minItems: 2
maxItems: 2
ext_raw_polygon:
type: array
items:
type: array
items:
type: array
items:
type: number
format: float
minItems: 2
maxItems: 2
shape: # Can be referenced via '#/shape'
type: object
description: path element
properties:
path:
$ref: '#/polygon'
ext_path:
$ref: '#/ext_polygon'
raw_path:
$ref: '#/raw_polygon'
ext_raw_path:
$ref: '#/ext_raw_polygon' I did the following tests on 5.3.0, but the problem goes back at least as far as 4.3, probably it goes back a lot earlier. The
The resultant type is @cached_property
def openapi_types():
lazy_import()
return {
'value': ([[ERRORUNKNOWN]],),
} This is the best attempt of the generators I have tried so far, so its probably the best place to look for a possible solution. The self.openapi_types = {
'path': List[List],
'ext_path': List[List[object]],
'raw_path': List[List[float]],
'ext_raw_path': List[List[List[float]]]
} It should read: self.openapi_types = {
'path': List[List[float]],
'ext_path': List[List[List[float]]],
'raw_path': List[List[float]],
'ext_raw_path': List[List[List[float]]]
} I actually came across this using the rust generators, where both options produce odd results. My understanding of Rust and the associated generators is limited, so my interpretation may be suspect. The pub struct Shape {
#[serde(rename = "path", skip_serializing_if = "Option::is_none")]
pub path: Option<Vec<crate::models::Array>>,
#[serde(rename = "ext_path", skip_serializing_if = "Option::is_none")]
pub ext_path: Option<Vec<Vec<serde_json::Value>>>,
#[serde(rename = "raw_path", skip_serializing_if = "Option::is_none")]
pub raw_path: Option<Vec<Vec<f32>>>,
#[serde(rename = "ext_raw_path", skip_serializing_if = "Option::is_none")]
pub ext_raw_path: Option<Vec<Vec<Vec<f32>>>>,
} There is no The pub struct Shape {
#[serde(rename = "path")]
#[serde(skip_serializing_if="Option::is_none")]
pub path: Option<Vec<models::Vector>>,
#[serde(rename = "ext_path")]
#[serde(skip_serializing_if="Option::is_none")]
pub ext_path: Option<Vec<Vec<#Vector>>>,
#[serde(rename = "raw_path")]
#[serde(skip_serializing_if="Option::is_none")]
pub raw_path: Option<Vec<Vec<f32>>>,
#[serde(rename = "ext_raw_path")]
#[serde(skip_serializing_if="Option::is_none")]
pub ext_raw_path: Option<Vec<Vec<Vec<f32>>>>,
} The errors are not so similar to those seen in either python case, it looks OK for the This confirms the problem runs across languages, but because of the differences I am not sure if there is a common cause, or if there is, there are additional errors. It might be related to the method ...
} else if (ModelUtils.isMapSchema(schema)) {
return "map";
} else if (ModelUtils.isArraySchema(schema)) {
return "array";
}
... simply assigns the container type and does not look any deeper, but I don't know enough to know if this is anything to do with it. |
#11221) * recursively search for types during import type collection in deeply nested schemas #11220 * composed schema recursive type import handling * change Importable to ComplexType to modularize related type-wrangling. * Problems... * Revert "Problems..." This reverts commit 6154f202a0f4db7a706fe3d61b45573581d164d4. * Reverted attempts to reuse recursive type-finding code. * add javadoc comments * fix javadoc warning. * fix NPE * PR feedback incorporation * Include additionalProperties recursion. * More feedback * More feedback * Add comments from feedback
Was this fixed in #11221? Issue is still open. |
Bug Report Checklist
Description
When specifying schemas that have nested types (for instance,
Map<String, Map<String, MyType>>
), theMyType
custom type doesn't get added to the list of imports and so all the generated clients fail to resolve theMyType
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
Also here
Generation Details
A simple generation command, like
openapi-generator generate -g python
will make a Python client that fails during symbol resolution becausePerson
won't be imported indefault_api.py
.Steps to reproduce
Assuming pipenv and openapi-generator-cli are both installed and on the path...
Related issues/PRs
#10279
Suggest a fix
Working on this...
The text was updated successfully, but these errors were encountered: