-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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.