OpenAPITools / OpenAPITools/openapi-generator
readonly fields in parents generate invalid code with 'microprofile' generator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When using allOff and having readonly fields in the parent, then the 'microprofile' generator creates a constructor that does not compile:
@JsonbCreator
public Child(
@JsonbProperty(value = "parentField") String parentField
) {
this.parentField = parentField; //As parentField is private, this is not allowed.
}
openapi-generator version
7.19.0
OpenAPI declaration file content or url
info:
title: Reproduce
version: 'v1'
components:
schemas:
Child:
required:
- childField1
type: object
allOf:
- $ref: "#/components/schemas/Parent"
properties:
childField1:
type: string
Parent:
required:
- parentField
type: object
properties:
parentField:
type: string
readOnly: true
discriminator:
propertyName: classType
mapping:
Child: "#/components/schemas/Child"
paths:
'/v1/reproduce':
get:
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Child'
description: 'reproduce'
Generation Details
generatorName = "java"
library = "resteasy"
...
configOptions = [
generatorName : "java",
library : "microprofile",
]
Steps to reproduce
Just generate the code.
Related issues/PRs
#16374 but for generator 'resteasy'
Suggest a fix
The bug is caused by this line https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache#L70.
A fix could be to either call the constructor in the superclass with the parents readonly fields, or by changing the access modifiers from 'private' to 'package' on the readonly parent fields.
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/Java/libraries/microprofile/pojo.mustache at the referenced line, then generate Java code from the provided OpenAPI declaration using the microprofile library. Check the Child constructor and Parent readonly field access in the generated output. Done means the generated code compiles without breaking the readonly parent-field behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100