Skip to content

Commit 8a8b74e

Browse files
committed
1385 Generate constants for path in spring boot @RequestMapping
1 parent 008c1a4 commit 8a8b74e

File tree

5,471 files changed

+7836
-6682
lines changed

Some content is hidden

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

5,471 files changed

+7836
-6682
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.fasterxml.jackson.databind.JsonNode;
2121
import com.fasterxml.jackson.databind.node.ArrayNode;
2222
import com.google.common.base.Strings;
23+
import com.google.common.collect.ImmutableMap;
2324
import com.google.common.collect.Sets;
2425
import com.samskivert.mustache.Mustache;
2526
import io.swagger.v3.oas.models.OpenAPI;
@@ -45,6 +46,7 @@
4546
import org.openapitools.codegen.model.ModelsMap;
4647
import org.openapitools.codegen.model.OperationMap;
4748
import org.openapitools.codegen.model.OperationsMap;
49+
import org.openapitools.codegen.templating.mustache.ReplaceAllLambda;
4850
import org.openapitools.codegen.utils.CamelizeOption;
4951
import org.openapitools.codegen.utils.ModelUtils;
5052
import org.slf4j.Logger;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public interface {{classname}} {
127127
{{/jdk8-default-interface}}
128128
{{#operation}}
129129

130+
public static final String PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}} = "{{{path}}}";
130131
/**
131132
* {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
132133
{{#notes}}
@@ -232,7 +233,7 @@ public interface {{classname}} {
232233
{{/implicitHeadersParams.0}}
233234
@RequestMapping(
234235
method = RequestMethod.{{httpMethod}},
235-
value = "{{{path}}}"{{#singleContentTypes}}{{#hasProduces}},
236+
value = {{classname}}.PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}{{#singleContentTypes}}{{#hasProduces}},
236237
produces = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{/hasProduces}}{{#hasConsumes}},
237238
consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}},
238239
produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}},

modules/openapi-generator/src/test/java/org/openapitools/codegen/config/MergedSpecBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void assertFilesFromMergedSpec(String mergedSpec) throws IOException {
7575
.assertMethod("spec1OperationComplex")
7676
.hasReturnType("ResponseEntity<Spec1Model>")
7777
.assertMethodAnnotations()
78-
.containsWithNameAndAttributes("RequestMapping", ImmutableMap.of("value", "\"/spec1/complex/{param1}/path\""))
78+
.containsWithNameAndAttributes("RequestMapping", ImmutableMap.of("value", "Spec1Api.PATH_SPEC1_OPERATION_COMPLEX"))
7979
.toMethod()
8080
.assertParameter("param1")
8181
.hasType("String")

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void doAnnotateDatesOnModelParameters() throws IOException {
123123
.containsWithNameAndAttributes("Operation", ImmutableMap.of("operationId", "\"getZebras\""))
124124
.containsWithNameAndAttributes("RequestMapping", ImmutableMap.of(
125125
"method", "RequestMethod.GET",
126-
"value", "\"/zebras\""
126+
"value", "ZebrasApi.PATH_GET_ZEBRAS"
127127
))
128128
.toMethod()
129129
.assertParameter("limit").hasType("BigDecimal")
@@ -201,7 +201,7 @@ public void doAnnotateDatesOnModelParametersWithOptionalAndJsonNullable() throws
201201
.containsWithNameAndAttributes("Operation", ImmutableMap.of("operationId", "\"getZebras\""))
202202
.containsWithNameAndAttributes("RequestMapping", ImmutableMap.of(
203203
"method", "RequestMethod.GET",
204-
"value", "\"/zebras\""
204+
"value", "ZebrasApi.PATH_GET_ZEBRAS"
205205
))
206206
.toMethod()
207207
.assertParameter("limit").hasType("Optional<BigDecimal>")
@@ -1108,8 +1108,10 @@ public void testRequestMappingAnnotation() throws IOException {
11081108
final Map<String, File> files = generateFiles(codegen, "src/test/resources/2_0/petstore.yaml");
11091109

11101110
// Check that the @RequestMapping annotation is generated in the Api file
1111-
final File petApiFile = files.get("PetApi.java");
1112-
assertFileContains(petApiFile.toPath(), "@RequestMapping(\"${openapi.openAPIPetstore.base-path:/v2}\")");
1111+
JavaFileAssert.assertThat(files.get("PetApi.java"))
1112+
.fileContains("@RequestMapping(\"${openapi.openAPIPetstore.base-path:/v2}\")",
1113+
"public static final String PATH_ADD_PET = \"/pet\";",
1114+
"value = PetApi.PATH_ADD_PET");
11131115

11141116
// Check that the @RequestMapping annotation is not generated in the Controller file
11151117
final File petApiControllerFile = files.get("PetApiController.java");
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.10.0-SNAPSHOT
1+
7.9.0-SNAPSHOT

samples/client/echo_api/csharp-restsharp/README.md

Lines changed: 1 addition & 1 deletion
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.10.0-SNAPSHOT
1+
7.9.0-SNAPSHOT

samples/client/echo_api/go-external-refs/README.md

Lines changed: 1 addition & 1 deletion
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.10.0-SNAPSHOT
1+
7.9.0-SNAPSHOT

samples/client/echo_api/go/README.md

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)