Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Python generated code is incorrect when including 'oneOf' #1919

Closed
5 of 6 tasks
andrew-matteson opened this issue Jan 15, 2019 · 2 comments
Closed
5 of 6 tasks

Comments

@andrew-matteson
Copy link
Contributor

andrew-matteson commented Jan 15, 2019

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 for schema with discriminator doesn't populate discriminator_value_class_map in generated code. The generated code from the minimal example below is missing the discriminator_value_class_map.

Generated code:

class Distribution(object):
    """NOTE: This class is auto generated by OpenAPI Generator.
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    """
    Attributes:
      openapi_types (dict): The key is attribute name
                            and the value is attribute type.
      attribute_map (dict): The key is attribute name
                            and the value is json key in definition.
    """
    openapi_types = {
        'class_name': 'str',
        'list': 'str'
    }

    attribute_map = {
        'class_name': 'class_name',
        'list': 'list'
    }

    discriminator_value_class_map = {
        
    }

When a ListDistribution or GridDistribution is received from the server, it is not deserialized into it's correct class.

openapi-generator version

Built from most recent master 963c002

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 value of discriminator_value_class_map.
Related issues/PRs

#1662

Suggest a fix

I think the lines in this example should be:

    discriminator_value_class_map = {
        'GridDistribution': 'GridDistribution'
        'ListDistribution': 'ListDistribution'
    }

I'm happy to do some work to try to fix this, but would need to be pointed in the right direction.

@andrew-matteson andrew-matteson changed the title [BUG] Description [BUG] Python generated code is incorrect when including 'oneOf' Jan 15, 2019
@andrew-matteson
Copy link
Contributor Author

@wing328 This is the biggest issue of the problems you asked me to elaborate on. I'll open separate issues for the other problems and tag you on them.

@spacether
Copy link
Contributor

The composition feature addition in the above PR fixed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants