-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Closed
Copy link
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
[JAVA][SPRING] Missing @nullable import for array-type models in 7.19.0
openapi-generator version
7.19.0
OpenAPI declaration file content or url
ResultCodes:
type: array
items:
type: object
properties:
type:
type: string
example: Comment, Match, Warning, Mismatch
code:
type: integer
format: int32
example: 3013
override:
type: string
description: >-
If Item Check results have been overriden, this property contains
any override text supplied for the Force Override operation
description:
type: stringGeneration Details
openapi-generator-cli generate \
-g spring \
-i spec.yaml \
-o output \
--additional-properties=useJakartaEe=truespec.yaml:
openapi: 3.0.1
info:
title: Test
version: v1
components:
schemas:
ResultCodes:
type: array
items:
type: object
properties:
code:
type: stringSteps to reproduce
- Create an OpenAPI spec with an array-type schema (as above)
- Generate with spring generator using version 7.19.0+
- Compile the generated code
Expected: Code compiles successfully
Actual: Compilation fails with:
error: cannot find symbol
private String toIndentedString(@Nullable Object o) {
^
symbol: class Nullable
The generated ResultCodes.java uses @nullable annotation but is missing import org.springframework.lang.Nullable;
Related issues/PRs
- PR fix: [JAVA][SPRING] Nullaways warn with JSpecify => add missing annotation to parameter of method toIndentedString #22685 introduced @nullable annotation to toIndentedString() method parameter in pojo.mustache
Suggest a fix
The bug is in SpringCodegen.java. The Nullable import is added inside postProcessModelProperty() (line ~974):
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
// ...
if (getName().contains("spring")) {
model.imports.add("Nullable");
}
}This method is only called for models that have properties. Array-type schemas generate classes extending ArrayList with no properties, so postProcessModelProperty() is never called and the import is never added.
However, pojo.mustache uses {{>nullableAnnotation}} in toIndentedString() for ALL models:
private String toIndentedString({{>nullableAnnotation}}Object o) {Fix options:
- Move model.imports.add("Nullable") to postProcessModels() or fromModel() so it runs for all models
- Or add import org.springframework.lang.Nullable; unconditionally in model.mustache
Reactions are currently unavailable