OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][Spring] allOf with nullable produces JsonNullable<Object>
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The generated code for definitions which include allOf annotation with nullable properties produces JsonNullable<Object> when the property type is defined in parent object.
public class UpdateFirmJson {
@JsonProperty("firmName")
private JsonNullable<String> firmName = JsonNullable.undefined();
@JsonProperty("addressId")
private JsonNullable<Object> addressId = JsonNullable.undefined();
...
openapi-generator version
4.1.3
OpenAPI declaration file content or url
swagger: "2.0"
info:
title: Test for JsonNullable
version: 1.0.0
paths:
/firm/{firmId}:
patch:
tags:
- firm
summary: Update a firm
operationId: updateFirm
consumes:
- application/json
parameters:
- in: path
name: firmId
required: true
description: "Firm ID"
type: integer
format: int64
- in: body
name: updateFirm
description: Field to be updated
schema:
$ref: "#/definitions/UpdateFirm"
responses:
204:
description: Updated
definitions:
FirmProperties:
properties:
addressId:
type: string
UpdateFirm:
allOf:
- $ref: '#/definitions/FirmProperties'
- properties:
firmName:
type: string
x-nullable: true
addressId:
x-nullable: true
Command line used for generation
./gradlew openApiGenerate
Steps to reproduce
Just run the generator
Related issues/PRs
Nothing found.
Suggest a fix
Support deriving the type from the parent object, i.e. JsonNullabe<String>.
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 by running ./gradlew openApiGenerate with the supplied OpenAPI YAML and inspect the Java Spring generator path handling allOf and x-nullable properties. Trace how addressId inherits its type from FirmProperties, then verify the generated field uses JsonNullable rather than JsonNullable. Add coverage for this reproduction if the generator's existing tests provide a suitable location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100