Skip to content

Commit be76d3a

Browse files
committed
modify enum template. field should be final. add testcase & sample updates.
1 parent c4a6c4a commit be76d3a

248 files changed

Lines changed: 392 additions & 344 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/JavaSpring/enumClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{/allowableValues}}
3131
{{/gson}}
3232

33-
private {{{dataType}}} value;
33+
private final {{{dataType}}} value;
3434

3535
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{dataType}}} value) {
3636
this.value = value;

modules/openapi-generator/src/main/resources/JavaSpring/enumOuterClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatyp
3131
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
3232
{{/gson}}
3333

34-
private {{{dataType}}} value;
34+
private final {{{dataType}}} value;
3535

3636
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
3737
this.value = value;

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5432,4 +5432,17 @@ public void shouldDisableBuiltInValidationOptionByDefault() throws IOException {
54325432
.assertTypeAnnotations()
54335433
.containsWithName("Validated");
54345434
}
5435+
5436+
@Test
5437+
public void testEnumFieldShouldBeFinal_issue21018() throws IOException {
5438+
SpringCodegen codegen = new SpringCodegen();
5439+
codegen.setLibrary(SPRING_BOOT);
5440+
Map<String, File> files = generateFiles(codegen, "src/test/resources/bugs/issue_21018.yaml");
5441+
5442+
JavaFileAssert.assertThat(files.get("SomeEnum.java"))
5443+
.fileContains("private final String value;");
5444+
5445+
JavaFileAssert.assertThat(files.get("SomeObject.java"))
5446+
.fileContains("private final String value");
5447+
}
54355448
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: "3.0.3"
2+
info:
3+
version: 1.0.0
4+
title: test
5+
paths:
6+
/test:
7+
get:
8+
summary: test
9+
operationId: test
10+
responses:
11+
'200':
12+
description: OK
13+
components:
14+
schemas:
15+
SomeEnum:
16+
type: string
17+
enum:
18+
- Cat
19+
- Dog
20+
x-enum-varnames:
21+
- CAT
22+
- DOG
23+
SomeObject:
24+
type: object
25+
properties:
26+
name:
27+
type: string
28+
type:
29+
type: string
30+
enum:
31+
- Cat
32+
- Dog
33+
x-enum-varnames:
34+
- CAT
35+
- DOG
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# OpenAPI Petstore
1+
# #OpenAPI Petstore
22
#
3-
# This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
3+
##This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
44
#
5-
# The version of the OpenAPI document: 1.0.0
5+
#The version of the OpenAPI document: 1.0.0
66
#
7-
# Generated by: https://openapi-generator.tech
8-
# Generator version: 7.13.0-SNAPSHOT
7+
#Generated by: https://openapi-generator.tech
8+
#Generator version: 7.13.0-SNAPSHOT
99
#
1010

1111
# load modules
@@ -17,7 +17,7 @@ require "../src/petstore"
1717
def assert_compilation_error(path : String, message : String) : Nil
1818
buffer = IO::Memory.new
1919
result = Process.run("crystal", ["run", "--no-color", "--no-codegen", path], error: buffer)
20-
expect(result.success?).to be_false
21-
expect(buffer.to_s).to contain message
20+
result.success?.should be_false
21+
buffer.to_s.should contain message
2222
buffer.close
2323
end

samples/client/petstore/spring-cloud-deprecated/src/main/java/org/openapitools/model/Order.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum StatusEnum {
4747

4848
DELIVERED("delivered");
4949

50-
private String value;
50+
private final String value;
5151

5252
StatusEnum(String value) {
5353
this.value = value;

samples/client/petstore/spring-cloud-deprecated/src/main/java/org/openapitools/model/Pet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public enum StatusEnum {
5252

5353
SOLD("sold");
5454

55-
private String value;
55+
private final String value;
5656

5757
StatusEnum(String value) {
5858
this.value = value;

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/model/Order.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public enum StatusEnum {
4646

4747
DELIVERED("delivered");
4848

49-
private String value;
49+
private final String value;
5050

5151
StatusEnum(String value) {
5252
this.value = value;

samples/client/petstore/spring-cloud-feign-without-url/src/main/java/org/openapitools/model/Pet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public enum StatusEnum {
5252

5353
SOLD("sold");
5454

55-
private String value;
55+
private final String value;
5656

5757
StatusEnum(String value) {
5858
this.value = value;

samples/client/petstore/spring-cloud-tags/src/main/java/org/openapitools/model/Order.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public enum StatusEnum {
4646

4747
DELIVERED("delivered");
4848

49-
private String value;
49+
private final String value;
5050

5151
StatusEnum(String value) {
5252
this.value = value;

0 commit comments

Comments
 (0)