Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1920
Closed
Open
Issue created Jan 15, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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
  1. Build from most recent master (or grab appropriate snapshot)
  2. Run CLI generator on the provided minimal example
  3. Inspect openapi_client.models.distribution and look at the generated setter for list. This should not raise a ValueError because this is applied to all objects of the Distribution before the final class is resolved.
Related issues/PRs

#1662 (closed)

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.

Assignee
Assign to
Time tracking