Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kotlin generator with security scopes #1318

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading