OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Python] Arbitrary typed arrays are not handled property in OpenAPI version 2.0
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
I am trying to generate a Python client from a Swagger 2.0 schema but the generated types are not what I expect them to be.
openapi-generator version
I am using version 7.8.0-SNAPSHOT but have also downloaded and tried the 8.0.0-SNAPSHOT.
OpenAPI declaration file content or url
swagger: '2.0'
paths:
/workflows/start:
post:
parameters:
- in: body
name: body
required: true
schema:
$ref: '#/definitions/PayloadDefinition'
responses:
'200':
description: Request succeeded
definitions:
PayloadDefinition:
properties:
ArrayArgs:
type: array
items: {}
If I convert this to what I think is an equivalent OpenAPI 3.0.3 schema like:
openapi: '3.0.3'
info:
title: Example API
version: 1.0.0
paths:
/workflows/start:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PayloadDefinition'
responses:
'200':
description: Request succeeded
components:
schemas:
PayloadDefinition:
properties:
ArrayArgs:
type: array
items: {}
the generated type is correct, i.e. array_args: Optional[List[Any]] = Field(default=None, alias="ArrayArgs").
Generation Details
openapi-generator generate -i ./schema.yaml -g python -o ./client
Steps to reproduce
- Run the generate command above
- Check
client/openapi_client/models/payload_definition.py - Line 29 is incorrect:
The type annotation should bearray_args: Optional[List[Dict[str, Any]]] = Field(default=None, alias="ArrayArgs")Optional[List[Any]]
Related issues/PRs
N/A
Suggest a fix
The generated type should be a list of Any.
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
Run the supplied openapi-generator command with the Swagger 2.0 schema, then inspect client/openapi_client/models/payload_definition.py and compare it with the OpenAPI 3.0.3 result. The work is done when the Swagger 2.0 generated annotation for ArrayArgs is Optional[List[Any]] rather than Optional[List[Dict[str, Any]]].
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100