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
  • Merge requests
  • !6674

[Python][test] oneOf with overlapping types

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/jirikuncar/python-experimental/one-of into master Jun 15, 2020
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 62

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.shto 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

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/jirikuncar/python-experimental/one-of