[BUG][Python] Generated Python Code with `oneOf` and `required` is incorrect
Created by: andrew-matteson
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
Generated Python code includes ValueError
where it shouldn't
Generated code:
@list.setter
def list(self, list):
"""Sets the list of this Distribution.
:param list: The list of this Distribution. # noqa: E501
:type: str
"""
if list is None:
raise ValueError("Invalid value for `list`, must not be `None`") # noqa: E501
self._list = list
But this setter is invalid when applied to Distribution
or GridDistribution
from the example below.
openapi-generator version
Built from most recent master 963c0028
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Batch Simulator
servers:
- url: /foo/
paths:
/foo/:
get:
summary: Dummy
description: dummy
responses:
'200':
description: dummy
content:
application/json:
schema:
$ref: '#/components/schemas/distribution'
components:
schemas:
distribution:
description: An abstract distribution
type: object
additionalProperties: false
properties:
dummy:
type: string # Without this "Distribution" isn't generatred because "it's a free-form object"
discriminator:
propertyName: class_name
oneOf:
- $ref: '#/components/schemas/list-distribution'
- $ref: '#/components/schemas/grid-distribution'
list-distribution:
description: version 1
type: object
properties:
class_name:
type: string
list:
type: string
required:
- list # This gets applied to distribution, when it should only be applied to list-distribution
grid-distribution:
description: version 2
properties:
class_name:
type: string
Command line used for generation
java -jar ~/Repos/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g python -i test.yaml -o test_client
Steps to reproduce
- Build from most recent master (or grab appropriate snapshot)
- Run CLI generator on the provided minimal example
- Inspect
openapi_client.models.distribution
and look at the generated setter forlist
. This should not raise aValueError
because this is applied to all objects of theDistribution
before the final class is resolved.
Related issues/PRs
Suggest a fix
The ValueError
should only be applied when generating the final classes, in this case ListDistribution
. I don't have any ideas about how to address this.