OpenAPITools / OpenAPITools/openapi-generator
Polymorphic typed arrays are not supported in java code generation
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [x ] Have you provided a full/minimal spec to reproduce the issue?
- [ x] Have you validated the input using an OpenAPI validator (example)?
- [x ] What's the version of OpenAPI Generator used?
- [x ] Have you search for related issues/PRs?
- [x ] What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
Generated code does not compile becuse of this construct:
FmlOutputList:
type: array
items:
oneOf:
- $ref: '#/components/schemas/FmlTjanst'
- $ref: '#/components/schemas/FmlXml'
- $ref: '#/components/schemas/FmlAntal'
Compiler output:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project fmf-formansformedling-app: Compilation failure: Compilation failure:
[ERROR] PrefixFmlOutput.java:[26,57] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXmlFmlAntal
[ERROR] location: package model
[ERROR] PrefixFmlOutput.java:[38,16] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXmlFmlAntal
[ERROR] location: class model.PrefixFmlOutput
[ERROR] PrefixFmlOutput.java:[41,64] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXmlFmlAntal
[ERROR] location: class model.PrefixFmlOutput
[ERROR] PrefixFmlOutput.java:[47,66] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXmlFmlAntal
[ERROR] location: class model.PrefixFmlOutput
[ERROR] PrefixFmlOutput.java:[64,15] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXmlFmlAntal
[ERROR] location: class model.PrefixFmlOutput
[ERROR] PrefixFmlOutput.java:[69,42] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXmlFmlAntal
[ERROR] location: class model.PrefixFmlOutput
[ERROR] PrefixFmlInput.java:[26,57] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXml
[ERROR] location: package model
[ERROR] PrefixFmlInput.java:[38,16] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXml
[ERROR] location: class model.PrefixFmlInput
[ERROR] PrefixFmlInput.java:[41,52] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXml
[ERROR] location: class model.PrefixFmlInput
[ERROR] PrefixFmlInput.java:[47,54] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXml
[ERROR] location: class model.PrefixFmlInput
[ERROR] PrefixFmlInput.java:[64,15] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXml
[ERROR] location: class model.PrefixFmlInput
[ERROR] PrefixFmlInput.java:[69,31] cannot find symbol
[ERROR] symbol: class PrefixOneOfFmlTjanstFmlXml
[ERROR] location: class model.PrefixFmlInput
This construct works:
FmlOutputList:
type: array
items:
type: object
openapi-generator version
4.2.2
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: example
description: >-
Generated by rose-link-swaggerator.groovy
version: 1.0.0
contact: {}
paths:
/something/request:
post:
operationId: post
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/FmlInput'
parameters:
- name: example
description: example
in: header
required: true
schema:
type: string
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/FmlOutput'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
security: []
servers: []
components:
links: {}
callbacks: {}
schemas:
Error:
type: object
properties:
error:
type: string
FmlInput:
type: object
properties:
payload:
$ref: '#/components/schemas/FmlInputList'
FmlOutput:
type: object
properties:
serviceReturnValue:
$ref: '#/components/schemas/FmlOutputList'
FmlInputList:
type: array
items:
oneOf:
- $ref: '#/components/schemas/FmlTjanst'
- $ref: '#/components/schemas/FmlXml'
FmlOutputList:
type: array
items:
oneOf:
- $ref: '#/components/schemas/FmlTjanst'
- $ref: '#/components/schemas/FmlXml'
- $ref: '#/components/schemas/FmlAntal'
FmlTjanst:
type: object
properties:
FML_TJANST:
type: string
FmlXml:
type: object
properties:
FML_XML:
type: string
FmlAntal:
type: object
properties:
FML_ANTAL:
type: integer
Command line used for generation
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.2.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>spec.yaml</inputSpec>
<generatorName>java</generatorName>
<modelPackage>model</modelPackage>
<modelNamePrefix>Prefix</modelNamePrefix>
<configHelp>false</configHelp>
<configOptions>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
</configOptions>
<library>jersey2</library>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
mvn clean install
Related issues/PRs
Suggest a fix
Should work
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 with the provided spec.yaml and the Java generator output, especially PrefixFmlInput.java and PrefixFmlOutput.java, then run mvn clean install to reproduce the missing polymorphic classes. Compare the generated references with the schemas using oneOf in the array items; done means the generated Java project compiles for this specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100