OpenAPITools / OpenAPITools/openapi-generator
[BUG] Java and javascript generators don't create suitable polymorphic types
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the supplied OpenAPI 3.0.1 declaration and reproduce generation through the Maven plugin for Java server stubs and JavaScript client libraries. Compare how Widget, BarWidget, FooWidget, WidgetGroup, allOf, oneOf, and the discriminator are handled; done means request bodies accept the polymorphic extensions through their common Widget type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100