OpenAPITools / OpenAPITools/openapi-generator
[BUG] client generator in multiple languages ignores URI object type defined in schema in favor of generic type
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?
- 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
When generating client SDKs in at least two languages, a OpenAPI 2.0 schema that contains a definition for a URI object is ignored and instances of the URI object are turned into either java URIs (in the case of groovy) or python strings in the case of python and python-pydantic-v1. Here is a small example OpenAPI document:
{
"swagger": "2.0",
"info": {
"title": "Fuzzball API",
"version": "2.0",
"contact": {
"name": "CtrlIQ, Inc",
"url": "https://ciq.co",
"email": "info@ciq.co"
}
},
"schemes": ["https"],
"consumes": ["application/json"],
"produces": ["application/json"],
"paths": {
"/file": {
"get": {
"operationId": "GetFile",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/File"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/Status"
}
}
},
"parameters": [],
"tags": [
"FileService"
]
}
}
},
"definitions": {
"File": {
"type": "object",
"properties": {
"source": {
"$ref": "#/definitions/URI",
"description": "Source is the origin of the data. The type of URIs supported are\ndetermined by whether this is specified under ingress or egress."
},
"destination": {
"$ref": "#/definitions/URI",
"description": "Destination is the location to move the data. The type of URIs\nsupported are determined by whether this is specified under ingress or\negress."
}
},
"description": "File specifies details of workflow volume data movement."
},
"URI": {
"type": "object",
"properties": {
"uri": {
"type": "string",
"description": "uri is the uri of the resource to be accessed."
},
"secrets": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "secrets is a map of key value pairs to use to access resource.\nThe key specifies the type of data that is being used and the value\nspecifies raw data or a template for the workflow system to populate with\ndata internally from the secrets engine."
},
"secret": {
"type": "string"
},
"decryptionSecret": {
"type": "string"
}
},
"description": "URI contains the specification for a resource to access as well as\nadditional data necessary for access such as credentials."
},
"Status": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
Generate an SDK with
java -jar bin/openapi-generator-cli-7.14.0.jar generate -g python-pydntic-v1 -o pp -i mini.json --additional-properties="packageName=mini"
cat pp/mini/models/file.py | tail -n +15 | head -n 20
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import Optional
from pydantic import BaseModel
class File(BaseModel):
"""
File specifies details of workflow volume data movement. # noqa: E501
"""
source: Optional[str] = None
destination: Optional[str] = None
__properties = ["source", "destination"]
class Config:
"""Pydantic configuration"""
The model class is using Optional[str] instead of Optional[URI] with URI imported from model/uri.py (which is generated as expected). Same is true for -g python. For -g groovy or -g java it uses java.net.URI instead of the definition from the spec.
openapi-generator version
tested with the following jar releases/snapshots:
- openapi-generator-cli-7.13.0.jar
- openapi-generator-cli-7.14.0-20250602.095643-46.jar
- openapi-generator-cli-7.14.0.jar
- openapi-generator-cli-8.0.0-20240727.184357-6.jar
OpenAPI declaration file content or url
Full document is available at https://api.stable.fuzzball.ciq.dev/v2/schema
Minimal example see above
Generation Details
for gen in python python-pydantic-v1 java groovy ; do
java -jar $jar generate -g python-pydntic-v1 -o mini-${gen} -i mini.json --additional-properties="packageName=mini"
done
Steps to reproduce
see above
Related issues/PRs
couldn't find anything
Suggest a fix
don't know the code base well enough
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 minimal OpenAPI document and the listed generator commands, then inspect the generated File and URI models. Trace how the URI schema reference is mapped for python, python-pydantic-v1, java, and groovy; done means each generated File uses the declared URI model rather than a language-native generic type, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100