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
  • #6149
Closed
Open
Issue created May 03, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [go-experimental] makes uncompilable code for valid composed schemas

Created by: spacether

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

When generating a go-experimental client with the below document the generator produces uncompilable code

openapi-generator version

master branch

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: >-
    This spec is mainly for testing Petstore server and contains fake endpoints,
    models. Please do not use this for any other purpose. Special characters: "
    \
  version: 1.0.0
  title: OpenAPI Petstore
  license:
    name: Apache-2.0
    url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
  - name: store
    description: Access to Petstore orders
  - name: user
    description: Operations about user
paths:
  /foo:
    get:
      responses:
        default:
          description: response
          content:
            application/json:
              schema:
                type: object
                properties:
                  string:
                    $ref: '#/components/schemas/Shape'
servers:
  - url: 'http://{server}.swagger.io:{port}/v2'
    description: petstore server
    variables:
      server:
        enum:
          - 'petstore'
          - 'qa-petstore'
          - 'dev-petstore'
        default: 'petstore'
      port:
        enum:
          - "80"
          - "8080"
        default: "80"
  - url: https://localhost:8080/{version}
    description: The local server
    variables:
      version:
        enum:
          - 'v1'
          - 'v2'
        default: 'v2'
components:
    # go-experimental is unable to make Triangle and Quadrilateral correctly
    Shape:
      oneOf:
        - $ref: '#/components/schemas/Triangle'
        - $ref: '#/components/schemas/Quadrilateral'
      discriminator:
        propertyName: shapeType
    ShapeInterface:
      properties:
        shapeType:
          type: string
      required:
        - shapeType
    TriangleInterface:
      properties:
        triangleType:
          type: string
      required:
        - triangleType
    Triangle:
      oneOf:
        - $ref: '#/components/schemas/EquilateralTriangle'
        - $ref: '#/components/schemas/IsoscelesTriangle'
        - $ref: '#/components/schemas/ScaleneTriangle'
      discriminator:
        propertyName: triangleType
    EquilateralTriangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/TriangleInterface'
    IsoscelesTriangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/TriangleInterface'
    ScaleneTriangle:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/TriangleInterface'
    QuadrilateralInterface:
      properties:
        quadrilateralType:
          type: string
      required:
        - quadrilateralType
    Quadrilateral:
      oneOf:
        - $ref: '#/components/schemas/SimpleQuadrilateral'
        - $ref: '#/components/schemas/ComplexQuadrilateral'
      discriminator:
        propertyName: quadrilateralType
    SimpleQuadrilateral:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/QuadrilateralInterface'
    ComplexQuadrilateral:
      allOf:
        - $ref: '#/components/schemas/ShapeInterface'
        - $ref: '#/components/schemas/QuadrilateralInterface'
Command line used for generation

bin/openapi3/go-experimental-petstore.sh

Steps to reproduce

Geenerate the v3 go-experimental sample with this document + run CI tests

Related issues/PRs

This came up in this PR: https://github.com/OpenAPITools/openapi-generator/pull/6124 This issue is related: https://github.com/OpenAPITools/openapi-generator/issues/6143

Suggest a fix

I am seeing these errors in CI: https://circleci.com/gh/OpenAPITools/openapi-generator/15047#config/containers/1 But those interfaces are not required in python-experimental because we iterate over:

{{#requiredVars}} '{{name}}': ({{{dataType}}},), # noqa: E501 {{/requiredVars}} {{#optionalVars}} '{{name}}': ({{{dataType}}},), # noqa: E501 {{/optionalVars}} in the composed models Shape/Triangle/Quadrilateral

The go-experimental template is assuming that oneOf child models contain the full interfaces at the composed model level. One fix may be to have the go-experimental use requiredVars to set the interfaces on composed schemas.

@sebastien-rosset

Assignee
Assign to
Time tracking