[BUG] Java and javascript generators don't create suitable polymorphic types
Created by: ccpulse
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
See https://stackoverflow.com/questions/63411617/how-can-i-generate-an-openapi-definition-which-supports-a-polymorphic-request-bo for a full description, but essentially: polymorphism just seems to not be functional in the way I'd expect for request bodies. Given a base type and two extensions of that type, I should be able to define an endpoint which accepts either of the extension types and have the generated code infer that they have a common supertype, and use that as the acceptable type parameter in generated code
Is what I'm trying to do just not supported by the spec? Or is it a problem with the generators themselves?
openapi-generator version
4.2.3
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080'
description: Generated server url
paths:
/widgets:
post:
tags:
- widget-controller
operationId: createWidgets
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/WidgetGroup'
required: true
responses:
'200':
description: OK
components:
schemas:
BarWidget:
type: object
allOf:
- $ref: '#/components/schemas/Widget'
- type: object
properties:
bar:
type: string
FooWidget:
type: object
allOf:
- $ref: '#/components/schemas/Widget'
- type: object
properties:
foo:
type: string
Widget:
required:
- type
type: object
properties:
type:
type: string
discriminator:
propertyName: type
WidgetGroup:
type: object
properties:
widgets:
type: array
items:
oneOf:
- $ref: '#/components/schemas/BarWidget'
- $ref: '#/components/schemas/FooWidget'
Generation Details
The above spec was generated by writing the Java server code first and is the output from springdoc. Have then attempted to generate server stubs and JS client libs using the maven plugin.