Skip to content

Commit

Permalink
Code cleanup. Remove extraspaces in generated files. (#1080)
Browse files Browse the repository at this point in the history
* Code cleanup. Remove extraspaces in generated files.

* Fixed documentation about views properties
  • Loading branch information
altro3 authored Jun 26, 2023
1 parent ab23915 commit 263640f
Show file tree
Hide file tree
Showing 177 changed files with 377 additions and 384 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static org.openapitools.codegen.CodegenConstants.INVOKER_PACKAGE;

abstract class AbstractMicronautJavaCodegen<T extends GeneratorOptionsBuilder> extends AbstractJavaCodegen implements BeanValidationFeatures, OptionalFeatures, MicronautCodeGenerator<T> {

public static final String OPT_TITLE = "title";
public static final String OPT_TEST = "test";
public static final String OPT_TEST_JUNIT = "junit";
Expand Down Expand Up @@ -142,8 +143,8 @@ protected AbstractMicronautJavaCodegen() {
additionalProperties.put("closebrace", "}");

// Set client options that will be presented to user
updateOption(INVOKER_PACKAGE, this.getInvokerPackage());
updateOption(CodegenConstants.ARTIFACT_ID, this.getArtifactId());
updateOption(INVOKER_PACKAGE, getInvokerPackage());
updateOption(CodegenConstants.ARTIFACT_ID, getArtifactId());
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);

Expand Down Expand Up @@ -233,7 +234,7 @@ public void setApiPackage(String apiPackage) {
@Override
public void setInvokerPackage(String invokerPackage) {
super.setInvokerPackage(invokerPackage);
updateOption(INVOKER_PACKAGE, this.getInvokerPackage());
updateOption(INVOKER_PACKAGE, getInvokerPackage());
}

@Override
Expand All @@ -242,7 +243,7 @@ public void processOpts() {

// Get properties
if (additionalProperties.containsKey(OPT_TITLE)) {
this.title = (String) additionalProperties.get(OPT_TITLE);
title = (String) additionalProperties.get(OPT_TITLE);
}

if (additionalProperties.containsKey(INVOKER_PACKAGE)) {
Expand All @@ -259,37 +260,37 @@ public void processOpts() {

// Get boolean properties
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
}
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);

if (additionalProperties.containsKey(USE_OPTIONAL)) {
this.setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
}
writePropertyBack(USE_OPTIONAL, useOptional);

if (additionalProperties.containsKey(OPT_VISITABLE)) {
this.setVisitable(convertPropertyToBoolean(OPT_VISITABLE));
setVisitable(convertPropertyToBoolean(OPT_VISITABLE));
}
writePropertyBack(OPT_VISITABLE, visitable);

if (additionalProperties.containsKey(OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR)) {
this.requiredPropertiesInConstructor = convertPropertyToBoolean(OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR);
requiredPropertiesInConstructor = convertPropertyToBoolean(OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR);
}
writePropertyBack(OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR, requiredPropertiesInConstructor);

if (additionalProperties.containsKey(OPT_REACTIVE)) {
this.reactive = convertPropertyToBoolean(OPT_REACTIVE);
reactive = convertPropertyToBoolean(OPT_REACTIVE);
}
writePropertyBack(OPT_REACTIVE, reactive);

if (additionalProperties.containsKey(OPT_WRAP_IN_HTTP_RESPONSE)) {
this.wrapInHttpResponse = convertPropertyToBoolean(OPT_WRAP_IN_HTTP_RESPONSE);
wrapInHttpResponse = convertPropertyToBoolean(OPT_WRAP_IN_HTTP_RESPONSE);
}
writePropertyBack(OPT_WRAP_IN_HTTP_RESPONSE, wrapInHttpResponse);

if (additionalProperties.containsKey(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG)) {
this.generateOperationOnlyForFirstTag = convertPropertyToBoolean(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG);
generateOperationOnlyForFirstTag = convertPropertyToBoolean(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG);
}
writePropertyBack(OPT_GENERATE_OPERATION_ONLY_FOR_FIRST_TAG, generateOperationOnlyForFirstTag);

Expand All @@ -302,16 +303,16 @@ public void processOpts() {
}

maybeSetSwagger();
if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1.equals(this.generateSwaggerAnnotations)) {
if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1.equals(generateSwaggerAnnotations)) {
additionalProperties.put("generateSwagger1Annotations", true);
} else if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2.equals(this.generateSwaggerAnnotations)) {
} else if (OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2.equals(generateSwaggerAnnotations)) {
additionalProperties.put("generateSwagger2Annotations", true);
}

if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) {
setSerializationLibrary((String) additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));
}
additionalProperties.put(this.serializationLibrary.toLowerCase(Locale.US), true);
additionalProperties.put(serializationLibrary.toLowerCase(Locale.US), true);
if (SerializationLibraryKind.MICRONAUT_SERDE_JACKSON.name().equals(serializationLibrary)) {
additionalProperties.put(SerializationLibraryKind.JACKSON.name().toLowerCase(Locale.US), true);
}
Expand Down Expand Up @@ -376,11 +377,11 @@ private void maybeSetSwagger() {
String value = String.valueOf(additionalProperties.get(OPT_GENERATE_SWAGGER_ANNOTATIONS));
switch (value) {
case OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1 ->
this.generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1;
generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_1;
case OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2, OPT_GENERATE_SWAGGER_ANNOTATIONS_TRUE ->
this.generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2;
generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_SWAGGER_2;
case OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE ->
this.generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE;
generateSwaggerAnnotations = OPT_GENERATE_SWAGGER_ANNOTATIONS_FALSE;
default ->
throw new RuntimeException("Value \"" + value + "\" for the " + OPT_GENERATE_SWAGGER_ANNOTATIONS + " parameter is unsupported or misspelled");
}
Expand All @@ -391,7 +392,7 @@ private void maybeSetTestTool() {
if (additionalProperties.containsKey(OPT_TEST)) {
switch ((String) additionalProperties.get(OPT_TEST)) {
case OPT_TEST_JUNIT, OPT_TEST_SPOCK ->
this.testTool = (String) additionalProperties.get(OPT_TEST);
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
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Arrays;
import java.util.List;


class JavaMicronautClientCodegen extends AbstractMicronautJavaCodegen<JavaMicronautClientOptionsBuilder> {

public static final String OPT_CONFIGURE_AUTH = "configureAuth";
Expand All @@ -43,8 +42,7 @@ class JavaMicronautClientCodegen extends AbstractMicronautJavaCodegen<JavaMicron
protected String basePathSeparator = "-";
protected String clientId;

public JavaMicronautClientCodegen() {
super();
JavaMicronautClientCodegen() {

title = "OpenAPI Micronaut Client";
configureAuthorization = false;
Expand Down Expand Up @@ -85,7 +83,7 @@ public void processOpts() {
super.processOpts();

if (additionalProperties.containsKey(OPT_CONFIGURE_AUTH)) {
this.configureAuthorization = convertPropertyToBoolean(OPT_CONFIGURE_AUTH);
configureAuthorization = convertPropertyToBoolean(OPT_CONFIGURE_AUTH);
}
writePropertyBack(OPT_CONFIGURE_AUTH, configureAuthorization);

Expand Down Expand Up @@ -116,26 +114,26 @@ public void processOpts() {

if (additionalProperties.containsKey(AUTHORIZATION_FILTER_PATTERN)) {
String pattern = additionalProperties.get(AUTHORIZATION_FILTER_PATTERN).toString();
this.setAuthorizationFilterPattern(pattern);
setAuthorizationFilterPattern(pattern);
additionalProperties.put(AUTHORIZATION_FILTER_PATTERN, authorizationFilterPattern);
}
}

if (additionalProperties.containsKey(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS)) {
String additionalClientAnnotationsList = additionalProperties.get(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS).toString();
this.setAdditionalClientTypeAnnotations(Arrays.asList(additionalClientAnnotationsList.trim().split("\\s*(;|\\r?\\n)\\s*")));
setAdditionalClientTypeAnnotations(Arrays.asList(additionalClientAnnotationsList.trim().split("\\s*(;|\\r?\\n)\\s*")));
additionalProperties.put(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS, additionalClientTypeAnnotations);
}

if (additionalProperties.containsKey(CLIENT_ID)) {
String id = additionalProperties.get(CLIENT_ID).toString();
this.setClientId(id);
setClientId(id);
additionalProperties.put(CLIENT_ID, clientId);
}

if (additionalProperties.containsKey(BASE_PATH_SEPARATOR)) {
String separator = additionalProperties.get(BASE_PATH_SEPARATOR).toString();
this.setBasePathSeparator(separator);
setBasePathSeparator(separator);
additionalProperties.put(BASE_PATH_SEPARATOR, basePathSeparator);
}

Expand Down Expand Up @@ -164,16 +162,16 @@ public void setAdditionalClientTypeAnnotations(final List<String> additionalClie

public void setAuthorizationFilterPattern(final String pattern) {
writePropertyBack(OPT_CONFIGURE_AUTH_FILTER_PATTERN, true);
this.authorizationFilterPattern = pattern;
authorizationFilterPattern = pattern;
}

public void setClientId(final String id) {
writePropertyBack(OPT_CONFIGURE_CLIENT_ID, true);
this.clientId = id;
clientId = id;
}

public void setBasePathSeparator(final String separator) {
this.basePathSeparator = separator;
basePathSeparator = separator;
}

public void setConfigureAuthorization(boolean configureAuthorization) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
*/
@SuppressWarnings("UnusedReturnValue")
public interface JavaMicronautClientOptionsBuilder extends GeneratorOptionsBuilder {

/**
* If set to true the client will be configured for authorization.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


class JavaMicronautServerCodegen extends AbstractMicronautJavaCodegen<JavaMicronautServerOptionsBuilder> {

public static final String OPT_CONTROLLER_PACKAGE = "controllerPackage";
public static final String OPT_GENERATE_CONTROLLER_FROM_EXAMPLES = "generateControllerFromExamples";
public static final String OPT_GENERATE_IMPLEMENTATION_FILES = "generateImplementationFiles";
Expand Down Expand Up @@ -59,8 +58,7 @@ class JavaMicronautServerCodegen extends AbstractMicronautJavaCodegen<JavaMicron
protected boolean useAuth = true;
protected boolean generateHardNullable = true;

public JavaMicronautServerCodegen() {
super();
JavaMicronautServerCodegen() {

title = "OpenAPI Micronaut Server";
apiPackage = "org.openapitools.api";
Expand Down Expand Up @@ -254,18 +252,12 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
operation.vendorExtensions.put(EXTENSION_ROLES, Collections.singletonList(role));
} else {
List<String> roles = (List<String>) operation.vendorExtensions.get(EXTENSION_ROLES);
roles = roles.stream().map(role -> {
switch (role) {
case ANONYMOUS_ROLE_KEY:
return ANONYMOUS_ROLE;
case AUTHORIZED_ROLE_KEY:
return AUTHORIZED_ROLE;
case DENY_ALL_ROLE_KEY:
return DENY_ALL_ROLE;
default:
return "\"" + escapeText(role) + "\"";
}
}).collect(Collectors.toList());
roles = roles.stream().map(role -> switch (role) {
case ANONYMOUS_ROLE_KEY -> ANONYMOUS_ROLE;
case AUTHORIZED_ROLE_KEY -> AUTHORIZED_ROLE;
case DENY_ALL_ROLE_KEY -> DENY_ALL_ROLE;
default -> "\"" + escapeText(role) + "\"";
}).toList();
operation.vendorExtensions.put(EXTENSION_ROLES, roles);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
*/
@SuppressWarnings("UnusedReturnValue")
public interface JavaMicronautServerOptionsBuilder extends GeneratorOptionsBuilder {

/**
* Sets the package name of generated controller classes.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,5 +22,6 @@
* @param <T> The type of generator options builder.
*/
public interface MicronautCodeGenerator<T extends GeneratorOptionsBuilder> {

T optionsBuilder();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 original authors
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
*/
@SuppressWarnings("UnusedReturnValue")
public interface MicronautCodeGeneratorBuilder {

/**
* Sets the code generator which should be used (e.g server or client).
*
Expand Down
Loading

0 comments on commit 263640f

Please sign in to comment.