From 244b34a668688379865d4de5e22500a0c7b087ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flemming=20N=C3=B8rnberg=20Larsen?= Date: Wed, 13 Mar 2024 10:51:20 +0100 Subject: [PATCH 1/3] #18090 Insert missing quote: `{{{tokenUrl}}}"` -> `"{{{tokenUrl}}}"` --- .../spring-cloud/clientPropertiesConfiguration.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientPropertiesConfiguration.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientPropertiesConfiguration.mustache index a84aebfe0c1e..2bdc55c15ca3 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientPropertiesConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/clientPropertiesConfiguration.mustache @@ -17,7 +17,7 @@ public class ClientPropertiesConfiguration { {{#isCode}} properties.put("spring.security.oauth2.client.registration.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}.authorization-grant-type", "authorization_code" ); properties.put("spring.security.oauth2.client.registration.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}.redirect-uri", "set-{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}-redirect-uri" ); - properties.put("spring.security.oauth2.client.provider.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}.token-uri", {{{tokenUrl}}}" ); + properties.put("spring.security.oauth2.client.provider.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}.token-uri", "{{{tokenUrl}}}" ); properties.put("spring.security.oauth2.client.provider.{{{name}}}{{#lambda.pascalcase}}{{{flow}}}{{/lambda.pascalcase}}.authorization-uri", "{{{authorizationUrl}}}" ); {{/isCode}} {{#isPassword}} @@ -38,4 +38,4 @@ public class ClientPropertiesConfiguration { } {{/isOAuth}} -{{/authMethods}} \ No newline at end of file +{{/authMethods}} From 55d0426777118584c1f8eb7b0daa2f0507d57ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flemming=20N=C3=B8rnberg=20Larsen?= Date: Wed, 13 Mar 2024 21:16:29 +0100 Subject: [PATCH 2/3] #18058 Added test unit --- .../java/spring/SpringCodegenTest.java | 40 +++++++++++++++++++ .../src/test/resources/3_0/issue_18090.yaml | 29 ++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/3_0/issue_18090.yaml diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index c88416c22599..0a55823fbe7d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -49,6 +49,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.List; @@ -1191,6 +1192,45 @@ public void testSettersForConfigValues() throws Exception { Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING), true); } + @Test + public void testGenerationOfClientPropertiesConfigurationForOAuth() throws Exception { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + + OpenAPI openAPI = new OpenAPIParser() + .readLocation("src/test/resources/3_0/issue_18090.yaml", null, new ParseOptions()).getOpenAPI(); + + final SpringCodegen codegen = new SpringCodegen(); + codegen.setOpenAPI(openAPI); + codegen.setOutputDir(output.getAbsolutePath()); + + codegen.setHideGenerationTimestamp(true); + codegen.setInterfaceOnly(false); + codegen.setLibrary(SPRING_CLOUD_LIBRARY); + + codegen.processOpts(); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + + generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "true"); + + generator.opts(input).generate(); + + Path filePath = Paths.get(output.getAbsolutePath(), "src/main/java/org/openapitools/configuration/ClientPropertiesConfiguration.java"); + + String content = new String(Files.readAllBytes(filePath)); + Assert.assertTrue(content.contains("properties.put(\"spring.security.oauth2.client.provider.oAuth2AccessCode.token-uri\", \"${tokenUrl}\" );")); + Assert.assertTrue(content.contains("properties.put(\"spring.security.oauth2.client.provider.oAuth2AccessCode.authorization-uri\", \"${authorizationUrl}\" );")); + } + @Test public void useBeanValidationTruePerformBeanValidationFalseJava8TrueForFormatEmail() throws IOException { beanValidationForFormatEmail(true, false, true, "@javax.validation.constraints.Email", "@org.hibernate.validator.constraints.Email"); diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_18090.yaml b/modules/openapi-generator/src/test/resources/3_0/issue_18090.yaml new file mode 100644 index 000000000000..6d6792141677 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_18090.yaml @@ -0,0 +1,29 @@ +openapi: "3.0.3" +info: + title: Test for OAuth2 provider + version: 1.0.0 + +security: + - OAuth2: + - openid + - profile + +paths: + /some/endpoint: + get: + responses: + "200": + description: OK + +components: + securitySchemes: + OAuth2: + type: oauth2 + x-tokenName: id_token + flows: + authorizationCode: + authorizationUrl: "${authorizationUrl}" + tokenUrl: "${tokenUrl}" + scopes: + openid: Access OpenId Connect info + profile: Profile info From e015fce1c343ada0dbefecaf870556b7859dfb4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flemming=20N=C3=B8rnberg=20Larsen?= Date: Wed, 13 Mar 2024 21:22:01 +0100 Subject: [PATCH 3/3] #18058 Stop unit test from generating unnecessary APIs --- .../org/openapitools/codegen/java/spring/SpringCodegenTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 0a55823fbe7d..b5d06bb6c485 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -1219,7 +1219,7 @@ public void testGenerationOfClientPropertiesConfigurationForOAuth() throws Excep generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "false"); generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false"); generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false"); - generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true"); + generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false"); generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "true"); generator.opts(input).generate();