[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