OpenAPITools / OpenAPITools/openapi-generator
[BUG] [SPRING] Incorrect initialization class of model's property
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
While generating Model with Map/Dictionary Properties with the help of 'additionalProperties' i receive
public class Error400AIS {
@JsonProperty("_links")
private LinksAll links = new HashMap<>();
but expecting
public class Error400AIS {
@JsonProperty("_links")
private LinksAll links = new LinksAll();
openapi-generator version
4.3.1
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: NextGenPSD2 XS2A Framework
version: "1.3.4_2019-07-17v1"
paths:
/v2/ping:
get:
summary: Ping service
description: Ping-pong
responses:
'200':
description: OK
content:
text/plain:
schema:
type: string
components:
schemas:
hrefType:
description: Link to a resource
type: object
properties:
href:
type: string
_linksAll:
description: |
A _link object with all availabel link types
type: object
additionalProperties:
$ref: "#/components/schemas/hrefType"
properties:
last:
$ref: "#/components/schemas/hrefType"
Error400_AIS:
description: Standardised definition of reporting error information according to [RFC7807]
type: object
properties:
_links:
$ref: "#/components/schemas/_linksAll"
Command line used for generation
openApiGenerate {
verbose.set(false)
generatorName.set("spring")
validateSpec.set(false)
inputSpec.set("$rootDir/specs/psd2-api 1.3.4 20190717v1_short.yaml")
configFile.set("$rootDir/specs/config.json")
outputDir.set("$projectDir/src/main/java-generated")
additionalProperties.set(mapOf("sourceFolder" to ""))
systemProperties.set(mapOf("modelDocs" to "false", "models" to ""))
supportingFilesConstrainedTo.set(emptyList())
}
{
"dateLibrary": "java8",
"hideGenerationTimestamp": true,
"apiPackage": "psd2.api",
"modelPackage": "psd2.dto",
"configPackage": "psd2.conf"
}
Steps to reproduce
Just try to create model with 4.3.1 generator
Related issues/PRs
Could not find
Suggest a fix
Probably fix should goes "modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache" 40th line. Or "defaultValue" should be equals to "datatypeWithEnum" (but have no idea what could be broken in this case)
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 modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache around line 40 and reproduce the model using the OpenAPI declaration in the issue. Compare the generated initialization for the _links property with the declared _linksAll type and verify that the output uses LinksAll rather than HashMap.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100