Bug Report Checklist
Description
The Java Spring generator does not add @Deprecated to generated enum classes when their OpenAPI schema specifies deprecated: true.
Deprecated object schemas are correctly annotated with @Deprecated. Enum schemas are not, although the generator exposes the schema deprecation state through CodegenModel.isDeprecated.
As a result, Java consumers receive no compiler warning when using an enum type that is deprecated in the OpenAPI contract.
The issue was reproduced locally from master at commit 66f697325c1273ce1aa26813afd286a984acdb49.
The Java Spring enum templates at that commit do not include conditional deprecation handling:
openapi-generator version
The issue occurs with OpenAPI Generator 7.24.0.
It was also reproduced with version 7.25.0-SNAPSHOT built from the latest master commit at the time of testing:
66f697325c1273ce1aa26813afd286a984acdb49
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Deprecated enum example
version: 1.0.0
paths:
/status:
get:
operationId: getStatus
responses:
"200":
description: Current status
content:
application/json:
schema:
$ref: "#/components/schemas/DeprecatedStatus"
components:
schemas:
DeprecatedStatus:
type: string
deprecated: true
description: A deprecated status type.
enum:
- ACTIVE
- INACTIVE
Generation Details
The issue can be reproduced with OpenAPI Generator 7.24.0:
java -jar openapi-generator-cli-7.24.0.jar generate \
--generator-name spring \
--library spring-boot \
--input-spec openapi.yaml \
--output generated
The latest master CLI was built and tested locally:
./mvnw -pl modules/openapi-generator-cli -am package \
-Dmaven.test.skip=true \
-Dmaven.javadoc.skip=true
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar \
validate \
--input-spec openapi.yaml
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar \
generate \
--generator-name spring \
--library spring-boot \
--input-spec openapi.yaml \
--output generated
The specification passes validation without issues.
No additional generator options are required to reproduce the issue.
Steps to reproduce
- Save the minimal OpenAPI document as
openapi.yaml.
- Generate Java Spring sources using one of the commands above.
- Inspect the generated
DeprecatedStatus.java.
Relevant actual output:
/**
* A deprecated status type.
*/
public enum DeprecatedStatus {
ACTIVE("ACTIVE"),
INACTIVE("INACTIVE");
}
Expected output:
/**
* A deprecated status type.
*/
@Deprecated
public enum DeprecatedStatus {
ACTIVE("ACTIVE"),
INACTIVE("INACTIVE");
}
Enum schemas without deprecated: true must remain unchanged.
Related issues/PRs
- #22311 reported the same general problem for Java enum generation.
- #22312 fixed it for several Java generators but did not update the Java Spring templates.
Suggest a fix
Use CodegenModel.isDeprecated in enumOuterClass.mustache and CodegenProperty.deprecated in enumClass.mustache to emit @Deprecated when the corresponding enum schema is deprecated.
For top level enums:
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
For inline enums:
{{#deprecated}}
@Deprecated
{{/deprecated}}
Apply the corresponding condition to each Java Spring enum template, with tests confirming that:
- Deprecated top level enum schemas receive
@Deprecated.
- Deprecated inline enum schemas receive
@Deprecated.
- Enum schemas that are not deprecated remain unchanged.
Bug Report Checklist
Description
The Java Spring generator does not add
@Deprecatedto generated enum classes when their OpenAPI schema specifiesdeprecated: true.Deprecated object schemas are correctly annotated with
@Deprecated. Enum schemas are not, although the generator exposes the schema deprecation state throughCodegenModel.isDeprecated.As a result, Java consumers receive no compiler warning when using an enum type that is deprecated in the OpenAPI contract.
The issue was reproduced locally from
masterat commit66f697325c1273ce1aa26813afd286a984acdb49.The Java Spring enum templates at that commit do not include conditional deprecation handling:
JavaSpring/enumOuterClass.mustacheJavaSpring/enumClass.mustacheopenapi-generator version
The issue occurs with OpenAPI Generator 7.24.0.
It was also reproduced with version 7.25.0-SNAPSHOT built from the latest master commit at the time of testing:
66f697325c1273ce1aa26813afd286a984acdb49OpenAPI declaration file content or url
Generation Details
The issue can be reproduced with OpenAPI Generator 7.24.0:
The latest master CLI was built and tested locally:
The specification passes validation without issues.
No additional generator options are required to reproduce the issue.
Steps to reproduce
openapi.yaml.DeprecatedStatus.java.Relevant actual output:
Expected output:
Enum schemas without
deprecated: truemust remain unchanged.Related issues/PRs
Suggest a fix
Use
CodegenModel.isDeprecatedinenumOuterClass.mustacheandCodegenProperty.deprecatedinenumClass.mustacheto emit@Deprecatedwhen the corresponding enum schema is deprecated.For top level enums:
For inline enums:
Apply the corresponding condition to each Java Spring enum template, with tests confirming that:
@Deprecated.@Deprecated.