-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Labels
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
This appears to be a regression from handling 3.0 specs. If I switch the openapi version from 3.1.0 to 3.0.0 then the correct output is produced.
When a field is of type
anyOf:
- type: string
- type: array
items:
type: string
The generated code ignores the array and produces
field: Optional[StrictStr] = Field(...)
It does the right thing when it's
anyOf:
- type: string
- type: number
Producing
field: Field = Field(...)
openapi-generator version
latest/7.2.0
docker pull openapitools/openapi-generator-cli:latest
latest: Pulling from openapitools/openapi-generator-cli
Digest: sha256:7bfcb402ec4fef3af86c5ff38cec26c772db138120f931755da4a63a3cec5189
OpenAPI declaration file content or url
openapi: 3.1.0
paths: {}
info:
version: 1.0.0
title: Swagger Petstore
components:
schemas:
Cat:
type: object
title: Cat
description: a cat
required: [field]
properties:
field:
title: field
anyOf:
- type: string
- items:
type: stringGeneration Details
$ pip install openapi-spec-validator
$ openapi-spec-validator openapi.yaml
openapi.yaml: OK
$ docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -g python --additional-properties=generateSourceCodeOnly=true,packageName=client -o /local/ -i /local/openapi.yaml
Output has no warnings/errors.
Steps to reproduce
- Create openapi.yaml and generate code
- Look in client/model/cat.py and observe list[str] is missing in the type of field
- Switch to 3.0.0 in yaml
- Regenerate code and observe the field now points to a new type which correctly expresses the union type
Related issues/PRs
None that I could find.
Suggest a fix
It seems like the array handling logic is incorrect.
Reactions are currently unavailable