OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Python] Problems with nested `allOf` -> `anyOf` types
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
Generated Python code seemingly fails to properly deserialize allOf with nested anyOf objects.
Given following input:
from openapi_client.models.availability_with_shipping_time import AvailabilityWithShippingTime
DATA = {'availability': {'type': 'Stock', 'shipping_time_in_days': None}}
AvailabilityWithShippingTime.from_dict(DATA)
openapi-generator version
openapi-generator-cli 7.18.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
contact:
email: info@example.org
title: API
version: 1.0.0
paths:
/availability:
get:
operationId: getAvailability
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/AvailabilityWithShippingTime'
description: Example
components:
schemas:
Availability:
oneOf:
- type: object
description: There is sufficient stock for the required quantity.
required:
- type
properties:
type:
type: string
enum:
- Stock
- type: object
description: |-
There is not sufficient stock, but enough stock with on order quantities
by the given lead time in days.
required:
- days
- type
properties:
days:
type: integer
format: int64
description: |-
There is not sufficient stock, but enough stock with on order quantities
by the given lead time in days.
minimum: 0
type:
type: string
enum:
- OnOrder
- type: object
description: |-
There is not sufficient stock, but enough stock with on order quantities
without a given date or lead time
required:
- type
properties:
type:
type: string
enum:
- OnOrderWithUnknownLeadTime
- type: object
description: |-
There is not sufficient stock, even with on order quantities, but there is a given
factory lead time by which the required quantity can be obtained.
required:
- days
- type
properties:
days:
type: integer
format: int64
description: |-
There is not sufficient stock, even with on order quantities, but there is a given
factory lead time by which the required quantity can be obtained.
minimum: 0
type:
type: string
enum:
- LeadTimeDays
description: |-
Availability of a solution or purchase option, indicating if it is in stock
or the method and number of days until the required quantity is obtained.
AvailabilityWithShippingTime:
allOf:
- $ref: '#/components/schemas/Availability'
- type: object
properties:
shipping_time_in_days:
type:
- integer
- 'null'
format: int64
minimum: 0
Generation Details
openapi-generator-cli generate -i allof-anyof-bundle.yaml -g python -o outputdir
Steps to reproduce
- Get the yaml openapi bundle from this issue report
- Generate python code using
openapi-generator-cli generate -i allof-anyof-bundle.yaml -g python -o outputdir - Place the example python code given in description in the
outputdir - Run the python code and see conclude that it fails to deserialize the
AvailabilityWithShippingTimeobject properly...
Related issues/PRs
There are many similar issues given, though they are not related to Python or do not have proper reproduction steps...
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
Start by running the reported generation command with allof-anyof-bundle.yaml, then inspect the generated AvailabilityWithShippingTime and Availability model deserialization around from_dict. Use the supplied DATA example to reproduce the failure. Done means the nested allOf/anyOf data deserializes into the expected Python object without losing the shipping_time_in_days value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100