25
25
import com .samskivert .mustache .Mustache ;
26
26
import com .samskivert .mustache .Mustache .Compiler ;
27
27
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 ;
29
45
import org .apache .commons .lang3 .ObjectUtils ;
30
46
import org .apache .commons .lang3 .StringEscapeUtils ;
31
47
import org .apache .commons .lang3 .StringUtils ;
56
72
import java .util .stream .Collectors ;
57
73
import java .util .stream .Stream ;
58
74
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
-
77
75
import static org .openapitools .codegen .utils .OnceLogger .once ;
78
76
import static org .openapitools .codegen .utils .StringUtils .*;
79
77
@@ -1486,20 +1484,20 @@ public DefaultCodegen() {
1486
1484
1487
1485
// option to change how we process + set the data in the 'additionalProperties' keyword.
1488
1486
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 ());
1491
1489
Map <String , String > disallowAdditionalPropertiesIfNotPresentOpts = new HashMap <>();
1492
1490
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." );
1494
1492
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." );
1499
1497
disallowAdditionalPropertiesIfNotPresentOpt .setEnum (disallowAdditionalPropertiesIfNotPresentOpts );
1500
1498
cliOptions .add (disallowAdditionalPropertiesIfNotPresentOpt );
1501
1499
this .setDisallowAdditionalPropertiesIfNotPresent (true );
1502
-
1500
+
1503
1501
// initialize special character mapping
1504
1502
initalizeSpecialCharacterMapping ();
1505
1503
@@ -2640,7 +2638,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
2640
2638
Integer hasDiscriminatorCnt = 0 ;
2641
2639
Integer hasNullTypeCnt = 0 ;
2642
2640
Set <String > discriminatorsPropNames = new HashSet <>();
2643
- for (Schema oneOf : composedSchema .getOneOf ()) {
2641
+ for (Schema oneOf : composedSchema .getOneOf ()) {
2644
2642
if (ModelUtils .isNullType (oneOf )) {
2645
2643
// The null type does not have a discriminator. Skip.
2646
2644
hasNullTypeCnt ++;
@@ -2654,7 +2652,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
2654
2652
}
2655
2653
if (discriminatorsPropNames .size () > 1 ) {
2656
2654
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 ));
2658
2656
}
2659
2657
if ((hasDiscriminatorCnt + hasNullTypeCnt ) == composedSchema .getOneOf ().size () && discriminatorsPropNames .size () == 1 ) {
2660
2658
disc .setPropertyName (foundDisc .getPropertyName ());
@@ -2669,7 +2667,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
2669
2667
Integer hasDiscriminatorCnt = 0 ;
2670
2668
Integer hasNullTypeCnt = 0 ;
2671
2669
Set <String > discriminatorsPropNames = new HashSet <>();
2672
- for (Schema anyOf : composedSchema .getAnyOf ()) {
2670
+ for (Schema anyOf : composedSchema .getAnyOf ()) {
2673
2671
if (ModelUtils .isNullType (anyOf )) {
2674
2672
// The null type does not have a discriminator. Skip.
2675
2673
hasNullTypeCnt ++;
@@ -2683,7 +2681,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
2683
2681
}
2684
2682
if (discriminatorsPropNames .size () > 1 ) {
2685
2683
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 ));
2687
2685
}
2688
2686
if ((hasDiscriminatorCnt + hasNullTypeCnt ) == composedSchema .getAnyOf ().size () && discriminatorsPropNames .size () == 1 ) {
2689
2687
disc .setPropertyName (foundDisc .getPropertyName ());
@@ -2720,7 +2718,7 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
2720
2718
if (schemaList == null ) {
2721
2719
continue ;
2722
2720
}
2723
- for (Schema sc : schemaList ) {
2721
+ for (Schema sc : schemaList ) {
2724
2722
if (ModelUtils .isNullType (sc )) {
2725
2723
continue ;
2726
2724
}
@@ -2875,7 +2873,7 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
2875
2873
* Handle the model for the 'additionalProperties' keyword in the OAS schema.
2876
2874
*
2877
2875
* @param codegenModel The codegen representation of the schema.
2878
- * @param schema the input OAS schema.
2876
+ * @param schema the input OAS schema.
2879
2877
*/
2880
2878
protected void addAdditionPropertiesToCodeGenModel (CodegenModel codegenModel , Schema schema ) {
2881
2879
addParentContainer (codegenModel , codegenModel .name , schema );
@@ -3503,7 +3501,7 @@ protected void handleMethodResponse(Operation operation,
3503
3501
op .returnType = cm .dataType ;
3504
3502
op .returnFormat = cm .dataFormat ;
3505
3503
op .hasReference = schemas != null && schemas .containsKey (op .returnBaseType );
3506
-
3504
+
3507
3505
// lookup discriminator
3508
3506
Schema schema = schemas .get (op .returnBaseType );
3509
3507
if (schema != null ) {
@@ -3965,8 +3963,8 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
3965
3963
r .containerType = cp .containerType ;
3966
3964
r .isMapContainer = "map" .equals (cp .containerType );
3967
3965
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 );
3970
3968
} else {
3971
3969
r .simpleType = true ;
3972
3970
}
@@ -4317,7 +4315,7 @@ public boolean isDataTypeBinary(String dataType) {
4317
4315
return false ;
4318
4316
}
4319
4317
}
4320
-
4318
+
4321
4319
// TODO revise below as it should be replaced by ModelUtils.isFileSchema(parameterSchema)
4322
4320
public boolean isDataTypeFile (String dataType ) {
4323
4321
if (dataType != null ) {
@@ -4589,15 +4587,15 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
4589
4587
* of the 'additionalProperties' keyword. Some language generator use class inheritance
4590
4588
* to implement additional properties. For example, in Java the generated model class
4591
4589
* has 'extends HashMap' to represent the additional properties.
4592
- *
4590
+ * <p>
4593
4591
* TODO: it's not a good idea to use single class inheritance to implement
4594
4592
* additionalProperties. That may work for non-composed schemas, but that does not
4595
4593
* work for composed 'allOf' schemas. For example, in Java, if additionalProperties
4596
4594
* is set to true (which it should be by default, per OAS spec), then the generated
4597
4595
* 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.
4601
4599
* @param schema the input OAS schema.
4602
4600
*/
4603
4601
protected void addParentContainer (CodegenModel model , String name , Schema schema ) {
@@ -6376,18 +6374,18 @@ public int hashCode() {
6376
6374
* Return true if the schema value can be any type, i.e. it can be
6377
6375
* the null value, integer, number, string, object or array.
6378
6376
* One use case is when the "type" attribute in the OAS schema is unspecified.
6379
- *
6377
+ * <p>
6380
6378
* 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
6391
6389
*
6392
6390
* @param schema the OAS schema.
6393
6391
* @return true if the schema value can be an arbitrary type.
@@ -6416,30 +6414,30 @@ public boolean isAnyTypeSchema(Schema schema) {
6416
6414
6417
6415
/**
6418
6416
* Check to see if the schema is a free form object.
6419
- *
6417
+ * <p>
6420
6418
* A free form object is an object (i.e. 'type: object' in a OAS document) that:
6421
6419
* 1) Does not define properties, and
6422
6420
* 2) Is not a composed schema (no anyOf, oneOf, allOf), and
6423
6421
* 3) additionalproperties is not defined, or additionalproperties: true, or additionalproperties: {}.
6424
- *
6422
+ * <p>
6425
6423
* Examples:
6426
- *
6424
+ * <p>
6427
6425
* 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.
6443
6441
*
6444
6442
* @param schema potentially containing a '$ref'
6445
6443
* @return true if it's a free-form object
@@ -6450,18 +6448,18 @@ protected boolean isFreeFormObject(Schema schema) {
6450
6448
6451
6449
/**
6452
6450
* Returns the additionalProperties Schema for the specified input schema.
6453
- *
6451
+ * <p>
6454
6452
* The additionalProperties keyword is used to control the handling of additional, undeclared
6455
6453
* properties, that is, properties whose names are not listed in the properties keyword.
6456
6454
* The additionalProperties keyword may be either a boolean or an object.
6457
6455
* If additionalProperties is a boolean and set to false, no additional properties are allowed.
6458
6456
* By default when the additionalProperties keyword is not specified in the input schema,
6459
6457
* any additional properties are allowed. This is equivalent to setting additionalProperties
6460
6458
* to the boolean value True or setting additionalProperties: {}
6461
- *
6459
+ *
6462
6460
* @param schema the input schema that may or may not have the additionalProperties keyword.
6463
6461
* @return the Schema of the additionalProperties. The null value is returned if no additional
6464
- * properties are allowed.
6462
+ * properties are allowed.
6465
6463
*/
6466
6464
protected Schema getAdditionalProperties (Schema schema ) {
6467
6465
return ModelUtils .getAdditionalProperties (openAPI , schema );
0 commit comments