Skip to content

Commit

Permalink
Insert missing quote in clientPropertiesConfiguration.mustache for th…
Browse files Browse the repository at this point in the history
…e Spring generator (OpenAPITools#18172)

* OpenAPITools#18090 Insert missing quote: `{{{tokenUrl}}}"` -> `"{{{tokenUrl}}}"`

* OpenAPITools#18058 Added test unit

* OpenAPITools#18058 Stop unit test from generating unnecessary APIs

* fix test

---------

Co-authored-by: Flemming Nørnberg Larsen <[email protected]>
  • Loading branch information
2 people authored and zapodot committed Mar 21, 2024
1 parent 5e2e807 commit b5714fe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -38,4 +38,4 @@ public class ClientPropertiesConfiguration {

}
{{/isOAuth}}
{{/authMethods}}
{{/authMethods}}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, "false");
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), "UTF-8");
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");
Expand Down
29 changes: 29 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/issue_18090.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b5714fe

Please sign in to comment.