-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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][python-experimental] generation of oneOf interfaces not working for oneOf usage in properties - leads to import error #6161
Comments
also the same thing happening with anyOf |
This happens in python-flask as well... |
@niderhoff have you tried making transformation into its own model? like:
That should produce code which works as you intend. |
This happens with go and java too. @spacether the workaround you mentioned isn't working. Is there any other workaround you can think of? This spec produces {
"openapi": "3.0.0",
"info": {
"title": "",
"version": "v2"
},
"servers": [
{
"url": ""
}
],
"externalDocs": {
"description": "",
"x-amf-title": "About",
"url": ""
},
"paths": {
"/database/databases": {
"get": {
"description": "List databases.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/database_databases_query"
}
}
}
},
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/database_databases"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"database_databases": {
"description": ".",
"type": "array",
"items": {}
},
"string_array":{
"description": "string array",
"type": "array",
"additionalProperties": false,
"items": {
"type": "string"
}
},
"string":{
"description": "string",
"type": "string",
"additionalProperties": false
},
"database_databases_query": {
"description": ".",
"type": "object",
"additionalProperties": false,
"properties": {
"uuid": {
"description": "Database uuid filter",
"oneOf": [
{
"$ref": "#/components/schemas/string"
},
{
"$ref": "#/components/schemas/string_array"
}
]
},
"status": {
"description": "Database status filter",
"oneOf": [
{
"type": "array",
"items": {
"enum": [
"CREATE_IN_PROGRESS",
"CREATED",
"UPDATE_IN_PROGRESS",
"DELETE_IN_PROGRESS",
"DELETED"
],
"type": "string"
}
},
{
"enum": [
"CREATE_IN_PROGRESS",
"CREATED",
"UPDATE_IN_PROGRESS",
"DELETE_IN_PROGRESS",
"DELETED"
]
}
]
}
}
}
}
}
}
|
I am running into the same issue. |
@haisum what about my work around specifically didn't work? |
I am running into the same issue in Golang:
|
I have the following in my api.json file: "properties": {
"id": {
"type": "string"
},
"recipients": {
"type": "integer",
"description": "my description"
},
"external_id": {
"type": "string"
},
"errors": {
"oneOf": [
{
"type": "object",
"properties": {
"invalid_external_user_ids": {
"type": "array",
"items": {
"type": "string"
},
"description": "my description"
},
"invalid_player_ids": {
"type": "array",
"items": {
"type": "string"
},
"description": "my description"
}
}
},
{
"type": "array",
"items": {
"type": "string"
},
"description": "my description"
}
]
}
} Which results in the following in the resulting Go build: // NotificationPropertiesTransformation struct for NotificationPropertiesTransformation
type NotificationPropertiesTransformation struct {
Id *string `json:"id,omitempty"`
// Estimated number of subscribers targetted by notification.
Recipients *int32 `json:"recipients,omitempty"`
ExternalId *string `json:"external_id,omitempty"`
Errors *OneOfobjectarray `json:"errors,omitempty"`
AdditionalProperties map[string]interface{}
} The object type The above solutions didn't work for me. I notice in your example, you use Any guidance? @spacether |
For the following:
Instead of defining the oneOf schema (and oneOf member schemas) inline, can you try defining these separately and referencing them instead as a workaround? |
Thanks @wing328 Ok, so I made some slight progress: "InvalidIdentifierError": {
"type": "object",
"properties": {
"invalid_external_user_ids": {
"type": "array",
"items": {
"type": "string"
},
"description": "Returned if using include_external_user_ids and some were valid and others were not.\nIf multiple devices or the same device with multiple player ids gets the same external_user_id,\nthen this indicates how many were unsubscribed.\nMore details on why the same device might have multiple records here: https://documentation.onesignal.com/docs/player-id\n"
},
"invalid_player_ids": {
"type": "array",
"items": {
"type": "string"
},
"description": "Returned if using include_player_ids and some were valid and others were not.\nPlease process these on your server and remove them from your database if you are tracking them.\n"
}
}
},
"NoSubscribersError": {
"type": "array",
"items": {
"type": "string"
},
"description": "Returned if no subscribed players.\n"
},
"Notification200Errors": {
"oneOf": [{
"$ref": "#/components/schemas/InvalidIdentifierError"
},
{
"$ref": "#/components/schemas/NoSubscribersError"
}]
}, results in the following struct: type Notification200Errors struct {
InvalidIdentifierError *InvalidIdentifierError
[]string *[]string // <-- error
} and the following functions: // []stringAsNotification200Errors is a convenience function that returns []string wrapped in Notification200Errors
func []stringAsNotification200Errors(v *[]string) Notification200Errors {
return Notification200Errors{ []string: v}
} notice the function name Digging into the source code a bit, it looks like the problem occurs in // {{classname}} - {{#description}}{{{description}}}{{/description}}{{^description}}struct for {{{classname}}}{{/description}}
type {{classname}} struct {
{{#oneOf}}
{{{.}}} *{{{.}}}
{{/oneOf}}
}
{{#oneOf}}
// {{{.}}}As{{classname}} is a convenience function that returns {{{.}}} wrapped in {{classname}}
func {{{.}}}As{{classname}}(v *{{{.}}}) {{classname}} {
return {{classname}}{ {{{.}}}: v}
}
{{/oneOf}} In particular, this portion: The correct result would be something like: type Notification200Errors struct {
InvalidIdentifierError *InvalidIdentifierError
NoSubscribersError *[]string // <-- no error
} |
@rgomezp can you please move your discussion to a go issue because it is not caused by the python or python-experimental generator? |
This issue has been fixed in the new python-experimental which was released in 5.4.0. |
Bug Report Checklist
Description
When using oneOf to match properties inside a schema, the oneOf-classes are not generated which leads to an import error.
openapi-generator version
OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce
output:
Related issues/PRs
original PR adding this functionality: #5341
background info: #5791
similar PR: #5400 (merged)
similar issues: #5903 (open), #5730 (open)
Suggest a fix
Implement generation of models.one_of_xxxx-classes
The text was updated successfully, but these errors were encountered: