OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Python] Path contains several parameters, only the first parameter is assigned the correct schema
Nobody has claimed this yet.
- 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
If path contains several parameters, only the first parameter is assigned the correct schema, the remaining parameters are all assigned the Any type.
If the parameter is an array, this information is lost. In the generated Python client api, the parameters are therefore not declared in the "_collection_formats" variable. Arrays are therefore not serialized properly!
openapi-generator version
Tested with all versions 7.4.0 and higher
OpenAPI declaration file content or url
Excerpt from my the openapi 3.1 json file. Generated by python Litestar Framework
Path /apps.
A number of apps should be displayed. Several id filters are available for selection
"/apps": {
"get": {
"tags": [
"Apps"
],
"summary": "List apps",
"description": "Retrieve the apps.",
"operationId": "list_apps",
"parameters": [
{
"name": "ids",
"in": "query",
"schema": {
"oneOf": [
{
"type": "null"
},
{
"items": {
"type": "string",
"format": "uuid"
},
"type": "array"
}
]
},
"required": false,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
},
{
"name": "workspace_ids",
"in": "query",
"schema": {
"oneOf": [
{
"type": "null"
},
{
"items": {
"type": "string",
"format": "uuid"
},
"type": "array"
}
]
},
"required": false,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
},
{
"name": "category_ids",
"in": "query",
"schema": {
"oneOf": [
{
"type": "null"
},
{
"items": {
"type": "string",
"format": "uuid"
},
"type": "array"
}
]
},
"required": false,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
},
{
"name": "publisher_ids",
"in": "query",
"schema": {
"oneOf": [
{
"type": "null"
},
{
"items": {
"type": "string",
"format": "uuid"
},
"type": "array"
}
]
},
"required": false,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
},
],
Generation Details
openapi-generator-cli version-manager set 7.7.0
openapi-generator-cli generate -i "${SPEC_FILE}" \
-g python \
-c ./config/client/python.yml.proc.yml \
--inline-schema-options SKIP_SCHEMA_REUSE=true \
The python.yml.proc.yml file contains:
projectName: Example
packageName: example
packageVersion: 0.1.0
library: asyncio
disallowAdditionalPropertiesIfNotPresent: false
Result:
Excerpt:
...
@validate_call
async def list_apps(
self,
ids: Optional[List[StrictStr]] = None,
workspace_ids: Optional[Any] = None, # <---------------- !
category_ids: Optional[Any] = None, # <---------------- !
publisher_ids: Optional[Any] = None, # <---------------- !
) -> ListApps200Response:
...
def _list_apps_serialize(
self,
ids,
workspace_ids,
category_ids,
publisher_ids,
_request_auth,
_content_type,
_headers,
_host_index,
) -> RequestSerialized:
_host = None
_collection_formats: Dict[str, str] = {
"ids": "multi",
# Missing workspace_ids, category_ids and so on <---------------- !
}
Steps to reproduce
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied OpenAPI declaration, Python generator command, and python.yml.proc.yml configuration, then trace how the Python client generator processes the path parameters after the first one. Done means workspace_ids, category_ids, publisher_ids, and similar parameters receive their schemas and array parameters appear in _collection_formats with correct serialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100