Created by: jirikuncar
tl;dr Shows a serialization problem of oneOf
models in python-experimental
with overlapping types.
Minimal specification
Two models with overlapping field definition of named enum type.
openapi: 3.0.1
info:
title: fruity
version: 0.0.1
paths:
/:
get:
responses:
"200":
description: desc
content:
application/json:
schema:
$ref: "#/components/schemas/fruit"
components:
schemas:
fruit:
title: fruit
oneOf:
- $ref: "#/components/schemas/apple"
- $ref: "#/components/schemas/banana"
appleColor:
type: string
enum:
- yellow
- green
- red
apple:
title: apple
type: object
properties:
kind:
type: string
color:
$ref: '#/components/schemas/appleColor'
bananaColor:
type: string
enum:
- yellow
- green
banana:
title: banana
type: object
properties:
count:
type: number
color:
$ref: '#/components/schemas/bananaColor'
Problem
The generated model contains all fields and the overlapping field has wrong type.
@cached_property
def openapi_types():
"""..."""
return {
'kind': (str,), # noqa: E501
'color': (banana_color.BananaColor,), # noqa: E501
'count': (float,), # noqa: E501
}
# ...
attribute_map = {
'kind': 'kind', # noqa: E501
'color': 'color', # noqa: E501
'count': 'count', # noqa: E501
}
This prevents deserialization of {"kind": "sweet", "color": "red"}
response.
How do I get expected behavior?
Simply remove definition of openapi_types
and attribute_map
and let the oneOf
models do the job.
PR checklist
-
Read the contribution guidelines. -
If contributing template-only or documentation-only changes which will change sample output, build the project beforehand. -
Run the shell script ./bin/generate-samples.sh
to update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/config/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
-
Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
cc @sebastien-rosset