Skip to content

Commit 3af1838

Browse files
committed
minor code format change
1 parent 9efcee6 commit 3af1838

File tree

1 file changed

+71
-73
lines changed

1 file changed

+71
-73
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,23 @@
2525
import com.samskivert.mustache.Mustache;
2626
import com.samskivert.mustache.Mustache.Compiler;
2727
import com.samskivert.mustache.Mustache.Lambda;
28-
28+
import io.swagger.v3.core.util.Json;
29+
import io.swagger.v3.oas.models.OpenAPI;
30+
import io.swagger.v3.oas.models.Operation;
31+
import io.swagger.v3.oas.models.PathItem;
32+
import io.swagger.v3.oas.models.callbacks.Callback;
33+
import io.swagger.v3.oas.models.examples.Example;
34+
import io.swagger.v3.oas.models.headers.Header;
35+
import io.swagger.v3.oas.models.media.*;
36+
import io.swagger.v3.oas.models.parameters.*;
37+
import io.swagger.v3.oas.models.responses.ApiResponse;
38+
import io.swagger.v3.oas.models.responses.ApiResponses;
39+
import io.swagger.v3.oas.models.security.OAuthFlow;
40+
import io.swagger.v3.oas.models.security.OAuthFlows;
41+
import io.swagger.v3.oas.models.security.SecurityScheme;
42+
import io.swagger.v3.oas.models.servers.Server;
43+
import io.swagger.v3.oas.models.servers.ServerVariable;
44+
import io.swagger.v3.parser.util.SchemaTypeUtil;
2945
import org.apache.commons.lang3.ObjectUtils;
3046
import org.apache.commons.lang3.StringEscapeUtils;
3147
import org.apache.commons.lang3.StringUtils;
@@ -56,24 +72,6 @@
5672
import java.util.stream.Collectors;
5773
import java.util.stream.Stream;
5874

59-
import io.swagger.v3.core.util.Json;
60-
import io.swagger.v3.oas.models.OpenAPI;
61-
import io.swagger.v3.oas.models.Operation;
62-
import io.swagger.v3.oas.models.PathItem;
63-
import io.swagger.v3.oas.models.callbacks.Callback;
64-
import io.swagger.v3.oas.models.examples.Example;
65-
import io.swagger.v3.oas.models.headers.Header;
66-
import io.swagger.v3.oas.models.media.*;
67-
import io.swagger.v3.oas.models.parameters.*;
68-
import io.swagger.v3.oas.models.responses.ApiResponse;
69-
import io.swagger.v3.oas.models.responses.ApiResponses;
70-
import io.swagger.v3.oas.models.security.OAuthFlow;
71-
import io.swagger.v3.oas.models.security.OAuthFlows;
72-
import io.swagger.v3.oas.models.security.SecurityScheme;
73-
import io.swagger.v3.oas.models.servers.Server;
74-
import io.swagger.v3.oas.models.servers.ServerVariable;
75-
import io.swagger.v3.parser.util.SchemaTypeUtil;
76-
7775
import static org.openapitools.codegen.utils.OnceLogger.once;
7876
import static org.openapitools.codegen.utils.StringUtils.*;
7977

@@ -1486,20 +1484,20 @@ public DefaultCodegen() {
14861484

14871485
// option to change how we process + set the data in the 'additionalProperties' keyword.
14881486
CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean(
1489-
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT,
1490-
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT_DESC).defaultValue(Boolean.TRUE.toString());
1487+
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT,
1488+
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT_DESC).defaultValue(Boolean.TRUE.toString());
14911489
Map<String, String> disallowAdditionalPropertiesIfNotPresentOpts = new HashMap<>();
14921490
disallowAdditionalPropertiesIfNotPresentOpts.put("false",
1493-
"The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.");
1491+
"The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.");
14941492
disallowAdditionalPropertiesIfNotPresentOpts.put("true",
1495-
"when the 'additionalProperties' keyword is not present in a schema, " +
1496-
"the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. " +
1497-
"Note: this mode is not compliant with the JSON schema specification. " +
1498-
"This is the original openapi-generator behavior.");
1493+
"when the 'additionalProperties' keyword is not present in a schema, " +
1494+
"the value of 'additionalProperties' is automatically set to false, i.e. no additional properties are allowed. " +
1495+
"Note: this mode is not compliant with the JSON schema specification. " +
1496+
"This is the original openapi-generator behavior.");
14991497
disallowAdditionalPropertiesIfNotPresentOpt.setEnum(disallowAdditionalPropertiesIfNotPresentOpts);
15001498
cliOptions.add(disallowAdditionalPropertiesIfNotPresentOpt);
15011499
this.setDisallowAdditionalPropertiesIfNotPresent(true);
1502-
1500+
15031501
// initialize special character mapping
15041502
initalizeSpecialCharacterMapping();
15051503

@@ -2640,7 +2638,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
26402638
Integer hasDiscriminatorCnt = 0;
26412639
Integer hasNullTypeCnt = 0;
26422640
Set<String> discriminatorsPropNames = new HashSet<>();
2643-
for (Schema oneOf: composedSchema.getOneOf()) {
2641+
for (Schema oneOf : composedSchema.getOneOf()) {
26442642
if (ModelUtils.isNullType(oneOf)) {
26452643
// The null type does not have a discriminator. Skip.
26462644
hasNullTypeCnt++;
@@ -2654,7 +2652,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
26542652
}
26552653
if (discriminatorsPropNames.size() > 1) {
26562654
throw new RuntimeException("The oneOf schemas have conflicting discriminator property names. " +
2657-
"oneOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
2655+
"oneOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
26582656
}
26592657
if ((hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getOneOf().size() && discriminatorsPropNames.size() == 1) {
26602658
disc.setPropertyName(foundDisc.getPropertyName());
@@ -2669,7 +2667,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
26692667
Integer hasDiscriminatorCnt = 0;
26702668
Integer hasNullTypeCnt = 0;
26712669
Set<String> discriminatorsPropNames = new HashSet<>();
2672-
for (Schema anyOf: composedSchema.getAnyOf()) {
2670+
for (Schema anyOf : composedSchema.getAnyOf()) {
26732671
if (ModelUtils.isNullType(anyOf)) {
26742672
// The null type does not have a discriminator. Skip.
26752673
hasNullTypeCnt++;
@@ -2683,7 +2681,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
26832681
}
26842682
if (discriminatorsPropNames.size() > 1) {
26852683
throw new RuntimeException("The anyOf schemas have conflicting discriminator property names. " +
2686-
"anyOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
2684+
"anyOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
26872685
}
26882686
if ((hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getAnyOf().size() && discriminatorsPropNames.size() == 1) {
26892687
disc.setPropertyName(foundDisc.getPropertyName());
@@ -2720,7 +2718,7 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
27202718
if (schemaList == null) {
27212719
continue;
27222720
}
2723-
for (Schema sc: schemaList) {
2721+
for (Schema sc : schemaList) {
27242722
if (ModelUtils.isNullType(sc)) {
27252723
continue;
27262724
}
@@ -2875,7 +2873,7 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
28752873
* Handle the model for the 'additionalProperties' keyword in the OAS schema.
28762874
*
28772875
* @param codegenModel The codegen representation of the schema.
2878-
* @param schema the input OAS schema.
2876+
* @param schema the input OAS schema.
28792877
*/
28802878
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
28812879
addParentContainer(codegenModel, codegenModel.name, schema);
@@ -3503,7 +3501,7 @@ protected void handleMethodResponse(Operation operation,
35033501
op.returnType = cm.dataType;
35043502
op.returnFormat = cm.dataFormat;
35053503
op.hasReference = schemas != null && schemas.containsKey(op.returnBaseType);
3506-
3504+
35073505
// lookup discriminator
35083506
Schema schema = schemas.get(op.returnBaseType);
35093507
if (schema != null) {
@@ -3965,8 +3963,8 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
39653963
r.containerType = cp.containerType;
39663964
r.isMapContainer = "map".equals(cp.containerType);
39673965
r.isListContainer = "list".equalsIgnoreCase(cp.containerType) ||
3968-
"array".equalsIgnoreCase(cp.containerType) ||
3969-
"set".equalsIgnoreCase(cp.containerType);
3966+
"array".equalsIgnoreCase(cp.containerType) ||
3967+
"set".equalsIgnoreCase(cp.containerType);
39703968
} else {
39713969
r.simpleType = true;
39723970
}
@@ -4317,7 +4315,7 @@ public boolean isDataTypeBinary(String dataType) {
43174315
return false;
43184316
}
43194317
}
4320-
4318+
43214319
// TODO revise below as it should be replaced by ModelUtils.isFileSchema(parameterSchema)
43224320
public boolean isDataTypeFile(String dataType) {
43234321
if (dataType != null) {
@@ -4589,15 +4587,15 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
45894587
* of the 'additionalProperties' keyword. Some language generator use class inheritance
45904588
* to implement additional properties. For example, in Java the generated model class
45914589
* has 'extends HashMap' to represent the additional properties.
4592-
*
4590+
* <p>
45934591
* TODO: it's not a good idea to use single class inheritance to implement
45944592
* additionalProperties. That may work for non-composed schemas, but that does not
45954593
* work for composed 'allOf' schemas. For example, in Java, if additionalProperties
45964594
* is set to true (which it should be by default, per OAS spec), then the generated
45974595
* code has extends HashMap. That wouldn't work for composed 'allOf' schemas.
4598-
*
4599-
* @param model the codegen representation of the OAS schema.
4600-
* @param name the name of the model.
4596+
*
4597+
* @param model the codegen representation of the OAS schema.
4598+
* @param name the name of the model.
46014599
* @param schema the input OAS schema.
46024600
*/
46034601
protected void addParentContainer(CodegenModel model, String name, Schema schema) {
@@ -6376,18 +6374,18 @@ public int hashCode() {
63766374
* Return true if the schema value can be any type, i.e. it can be
63776375
* the null value, integer, number, string, object or array.
63786376
* One use case is when the "type" attribute in the OAS schema is unspecified.
6379-
*
6377+
* <p>
63806378
* Examples:
6381-
*
6382-
* arbitraryTypeValue:
6383-
* description: This is an arbitrary type schema.
6384-
* It is not a free-form object.
6385-
* The value can be any type except the 'null' value.
6386-
* arbitraryTypeNullableValue:
6387-
* description: This is an arbitrary type schema.
6388-
* It is not a free-form object.
6389-
* The value can be any type, including the 'null' value.
6390-
* nullable: true
6379+
* <p>
6380+
* arbitraryTypeValue:
6381+
* description: This is an arbitrary type schema.
6382+
* It is not a free-form object.
6383+
* The value can be any type except the 'null' value.
6384+
* arbitraryTypeNullableValue:
6385+
* description: This is an arbitrary type schema.
6386+
* It is not a free-form object.
6387+
* The value can be any type, including the 'null' value.
6388+
* nullable: true
63916389
*
63926390
* @param schema the OAS schema.
63936391
* @return true if the schema value can be an arbitrary type.
@@ -6416,30 +6414,30 @@ public boolean isAnyTypeSchema(Schema schema) {
64166414

64176415
/**
64186416
* Check to see if the schema is a free form object.
6419-
*
6417+
* <p>
64206418
* A free form object is an object (i.e. 'type: object' in a OAS document) that:
64216419
* 1) Does not define properties, and
64226420
* 2) Is not a composed schema (no anyOf, oneOf, allOf), and
64236421
* 3) additionalproperties is not defined, or additionalproperties: true, or additionalproperties: {}.
6424-
*
6422+
* <p>
64256423
* Examples:
6426-
*
6424+
* <p>
64276425
* components:
6428-
* schemas:
6429-
* arbitraryObject:
6430-
* type: object
6431-
* description: This is a free-form object.
6432-
* The value must be a map of strings to values. The value cannot be 'null'.
6433-
* It cannot be array, string, integer, number.
6434-
* arbitraryNullableObject:
6435-
* type: object
6436-
* description: This is a free-form object.
6437-
* The value must be a map of strings to values. The value can be 'null',
6438-
* It cannot be array, string, integer, number.
6439-
* nullable: true
6440-
* arbitraryTypeValue:
6441-
* description: This is NOT a free-form object.
6442-
* The value can be any type except the 'null' value.
6426+
* schemas:
6427+
* arbitraryObject:
6428+
* type: object
6429+
* description: This is a free-form object.
6430+
* The value must be a map of strings to values. The value cannot be 'null'.
6431+
* It cannot be array, string, integer, number.
6432+
* arbitraryNullableObject:
6433+
* type: object
6434+
* description: This is a free-form object.
6435+
* The value must be a map of strings to values. The value can be 'null',
6436+
* It cannot be array, string, integer, number.
6437+
* nullable: true
6438+
* arbitraryTypeValue:
6439+
* description: This is NOT a free-form object.
6440+
* The value can be any type except the 'null' value.
64436441
*
64446442
* @param schema potentially containing a '$ref'
64456443
* @return true if it's a free-form object
@@ -6450,18 +6448,18 @@ protected boolean isFreeFormObject(Schema schema) {
64506448

64516449
/**
64526450
* Returns the additionalProperties Schema for the specified input schema.
6453-
*
6451+
* <p>
64546452
* The additionalProperties keyword is used to control the handling of additional, undeclared
64556453
* properties, that is, properties whose names are not listed in the properties keyword.
64566454
* The additionalProperties keyword may be either a boolean or an object.
64576455
* If additionalProperties is a boolean and set to false, no additional properties are allowed.
64586456
* By default when the additionalProperties keyword is not specified in the input schema,
64596457
* any additional properties are allowed. This is equivalent to setting additionalProperties
64606458
* to the boolean value True or setting additionalProperties: {}
6461-
*
6459+
*
64626460
* @param schema the input schema that may or may not have the additionalProperties keyword.
64636461
* @return the Schema of the additionalProperties. The null value is returned if no additional
6464-
* properties are allowed.
6462+
* properties are allowed.
64656463
*/
64666464
protected Schema getAdditionalProperties(Schema schema) {
64676465
return ModelUtils.getAdditionalProperties(openAPI, schema);

0 commit comments

Comments
 (0)