Skip to content

Commit

Permalink
Fix kotlin generator with security scopes (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 committed Nov 24, 2023
1 parent eb19b8a commit db99c61
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ managed-parboiled = "1.4.1"
managed-freemarker = "2.3.32"
managed-pegdown = "1.6.0"

kotlin = "1.9.20"
kotlin = "1.9.21"
ksp = "1.9.20-1.0.14"
jspecify = "0.3.0"
jdt-annotation = "2.2.700"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public abstract class AbstractMicronautKotlinCodegen<T extends GeneratorOptionsB
public static final String OPT_TITLE = "title";
public static final String OPT_TEST = "test";
public static final String OPT_TEST_JUNIT = "junit";
public static final String OPT_TEST_SPOCK = "spock";
public static final String OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR = "requiredPropertiesInConstructor";
public static final String OPT_USE_AUTH = "useAuth";
public static final String OPT_FLUX_FOR_ARRAYS = "fluxForArrays";
Expand Down Expand Up @@ -544,7 +543,7 @@ private void maybeSetSwagger() {
private void maybeSetTestTool() {
if (additionalProperties.containsKey(OPT_TEST)) {
switch ((String) additionalProperties.get(OPT_TEST)) {
case OPT_TEST_JUNIT, OPT_TEST_SPOCK ->
case OPT_TEST_JUNIT ->
testTool = (String) additionalProperties.get(OPT_TEST);
default ->
throw new RuntimeException("Test tool \"" + additionalProperties.get(OPT_TEST) + "\" is not supported or misspelled.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
]{{/hasParams}}{{#hasAuthMethods}},
security = [
{{#authMethods}}
SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = {{openbrace}}{{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}}{{closebrace}}{{/isOAuth}}){{^-last}},{{/-last}}
SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = [{{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}}]{{/isOAuth}}){{^-last}},{{/-last}}
{{/authMethods}}
]{{/hasAuthMethods}}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ void generateAuthRolesWithExtension() {
assertFileContainsRegex(apiPath + "UsersApi.kt", "IS_AUTHENTICATED[^;]{0,100}updateProfile");
}

@Test
void generateAuth() {
var codegen = new KotlinMicronautServerCodegen();
codegen.additionalProperties().put(KotlinMicronautServerCodegen.OPT_USE_AUTH, true);
String outputPath = generateFiles(codegen, PETSTORE_PATH, CodegenConstants.MODELS, CodegenConstants.APIS);

String apiPath = outputPath + "src/main/kotlin/org/openapitools/api/";
assertFileContains(apiPath + "PetApi.kt", "SecurityRequirement(name = \"petstore_auth\", scopes = [\"write:pets\", \"read:pets\"])");
}

@Test
void doGenerateMonoWrapHttpResponse() {
var codegen = new KotlinMicronautServerCodegen();
Expand Down

0 comments on commit db99c61

Please sign in to comment.