Bug Report Checklist
Description
When creating a python client from an openapi spec that has a schema named Field, it causes a naming conflict with pydantic's Field class.
openapi-generator version
7.4.0 and 7.5.0-SNAPSHOT
OpenAPI declaration file content or url
https://developer.atlassian.com/cloud/jira/platform/swagger-v3.json
Generation Details
openapi-generator-config.yml
packageName: jira_client
projectName: jira-client
packageVersion: 1.0.0
inputSpec: swagger-v3.json
outputDir: .
Steps to reproduce
Download swagger file from jira -> swagger-v3.json
Build docker image jira-client:
FROM openjdk:17-slim
ARG OPENAPI_GENERATOR_VERSION=7.4.0
RUN apt-get update && \
apt-get install -y \
wget && \
apt-get clean
RUN wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${OPENAPI_GENERATOR_VERSION}/openapi-generator-cli-${OPENAPI_GENERATOR_VERSION}.jar -O /opt/openapi-generator-cli.jar
RUN echo '#!/bin/bash\njava -jar /opt/openapi-generator-cli.jar "$@"' > /usr/bin/openapi-generator && \
chmod +x /usr/bin/openapi-generator
WORKDIR /app
COPY . /app/
CMD openapi-generator generate \
--generator-name python \
--config openapi-generator-config.yml
Run:
docker run -v $(pwd):/app jira-client
Output file with Field name conflict: jira_client/models/page_bean_field.py
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from jira_client.models.field import Field
from typing import Optional, Set
from typing_extensions import Self
class PageBeanField(BaseModel):
"""
A page of items.
""" # noqa: E501
is_last: Optional[StrictBool] = Field(default=None, description="Whether this is the last page.", alias="isLast")
max_results: Optional[StrictInt] = Field(default=None, description="The maximum number of items that could be returned.", alias="maxResults")
next_page: Optional[StrictStr] = Field(default=None, description="If there is another page of results, the URL of the next page.", alias="nextPage")
var_self: Optional[StrictStr] = Field(default=None, description="The URL of the page.", alias="self")
start_at: Optional[StrictInt] = Field(default=None, description="The index of the first item returned.", alias="startAt")
total: Optional[StrictInt] = Field(default=None, description="The number of items returned.")
values: Optional[List[Field]] = Field(default=None, description="The list of items.")
__properties: ClassVar[List[str]] = ["isLast", "maxResults", "nextPage", "self", "startAt", "total", "values"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
This leads to all tests failing
________________ ERROR collecting test/test_actor_input_bean.py ________________
test/test_actor_input_bean.py:18: in <module>
from jira_client.models.actor_input_bean import ActorInputBean
jira_client/__init__.py:21: in <module>
from jira_client.api.announcement_banner_api import AnnouncementBannerApi
jira_client/api/__init__.py:4: in <module>
from jira_client.api.announcement_banner_api import AnnouncementBannerApi
jira_client/api/announcement_banner_api.py:20: in <module>
from jira_client.models.announcement_banner_configuration import AnnouncementBannerConfiguration
jira_client/models/__init__.py:405: in <module>
from jira_client.models.page_bean_field import PageBeanField
jira_client/models/page_bean_field.py:27: in <module>
class PageBeanField(BaseModel):
jira_client/models/page_bean_field.py:31: in PageBeanField
is_last: Optional[StrictBool] = Field(default=None, description="Whether this is the last page.", alias="isLast")
E pydantic_core._pydantic_core.ValidationError: 3 validation errors for Field
E id
E Field required [type=missing, input_value={'default': None, 'descri...ge.', 'alias': 'isLast'}, input_type=dict]
E For further information visit https://errors.pydantic.dev/2.6/v/missing
E name
E Field required [type=missing, input_value={'default': None, 'descri...ge.', 'alias': 'isLast'}, input_type=dict]
E For further information visit https://errors.pydantic.dev/2.6/v/missing
E schema
E Field required [type=missing, input_value={'default': None, 'descri...ge.', 'alias': 'isLast'}, input_type=dict]
E For further information visit https://errors.pydantic.dev/2.6/v/missing
I would expect the generator to recognize Field as a class that shouldn't have a conflict and generate something like:
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from jira_client.models.field import Field_
from typing import Optional, Set
from typing_extensions import Self
class PageBeanField(BaseModel):
"""
A page of items.
""" # noqa: E501
is_last: Optional[StrictBool] = Field(default=None, description="Whether this is the last page.", alias="isLast")
max_results: Optional[StrictInt] = Field(default=None, description="The maximum number of items that could be returned.", alias="maxResults")
next_page: Optional[StrictStr] = Field(default=None, description="If there is another page of results, the URL of the next page.", alias="nextPage")
var_self: Optional[StrictStr] = Field(default=None, description="The URL of the page.", alias="self")
start_at: Optional[StrictInt] = Field(default=None, description="The index of the first item returned.", alias="startAt")
total: Optional[StrictInt] = Field(default=None, description="The number of items returned.")
values: Optional[List[Field_]] = Field(default=None, description="The list of items.")
__properties: ClassVar[List[str]] = ["isLast", "maxResults", "nextPage", "self", "startAt", "total", "values"]
Related issues/PRs
N/A
Suggest a fix
I tried --import-mappings and --type-mappings individually and in combination, but could not map the api Field to JiraField
Should Field be a reserved word for the python generator? I'm not sure what other approach could be used.
Any input would be much appreciated.
Bug Report Checklist
Description
When creating a python client from an openapi spec that has a schema named Field, it causes a naming conflict with pydantic's Field class.
openapi-generator version
7.4.0and7.5.0-SNAPSHOTOpenAPI declaration file content or url
https://developer.atlassian.com/cloud/jira/platform/swagger-v3.json
Generation Details
openapi-generator-config.ymlSteps to reproduce
Download swagger file from jira ->
swagger-v3.jsonBuild docker image
jira-client:Run:
docker run -v $(pwd):/app jira-clientOutput file with Field name conflict:
jira_client/models/page_bean_field.pyThis leads to all tests failing
I would expect the generator to recognize Field as a class that shouldn't have a conflict and generate something like:
Related issues/PRs
N/A
Suggest a fix
I tried
--import-mappingsand--type-mappingsindividually and in combination, but could not map the api Field to JiraFieldShould Field be a reserved word for the python generator? I'm not sure what other approach could be used.
Any input would be much appreciated.