Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.

Commit 2ea7720

Browse files
committed
test with CI
1 parent df2974a commit 2ea7720

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
28152815
LOGGER.error("Undefined property/schema for `{}`. Default to type:string.", name);
28162816
return null;
28172817
}
2818-
LOGGER.debug("debugging fromProperty for " + name + " : " + p);
2818+
LOGGER.info("debugging fromProperty for " + name + " : " + p);
28192819

28202820
// unalias schema
28212821
p = ModelUtils.unaliasSchema(this.openAPI, p, importMapping);
@@ -2968,8 +2968,10 @@ public CodegenProperty fromProperty(String name, Schema p) {
29682968
property.hasValidation = true;
29692969

29702970
} else if (ModelUtils.isFreeFormObject(p)) {
2971+
LOGGER.info("debugging free form schema: " + p);
29712972
property.isFreeFormObject = true;
29722973
} else if (ModelUtils.isAnyTypeSchema(p)) {
2974+
LOGGER.info("debugging any of schema: " + p);
29732975
property.isAnyType = true;
29742976
} else if (ModelUtils.isArraySchema(p)) {
29752977
// default to string if inner item is undefined
@@ -5619,7 +5621,7 @@ private void addBodyModelSchema(CodegenParameter codegenParameter, String name,
56195621
codegenParameter.dataType = getTypeDeclaration(codegenModelName);
56205622
codegenParameter.description = codegenProperty.getDescription();
56215623
} else {
5622-
if (ModelUtils.getAdditionalProperties(schema) != null) {// http body is map
5624+
if (ModelUtils.isMapSchema(schema)) {// http body is map
56235625
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
56245626
} else if (codegenProperty != null) {
56255627
String codegenModelName, codegenModelDescription;

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ public static boolean isComposedSchema(Schema schema) {
439439
* @return true if the specified schema is a Map schema.
440440
*/
441441
public static boolean isMapSchema(Schema schema) {
442+
// make sure it's not free form object first
443+
if (isFreeFormObject(schema)) {
444+
// to cover `additionalProperties: {}`
445+
return false;
446+
}
447+
442448
if (schema instanceof MapSchema) {
443449
return true;
444450
}
@@ -684,7 +690,7 @@ public static boolean isAnyTypeSchema(Schema schema) {
684690
}
685691

686692
if (isFreeFormObject(schema)) {
687-
// to cover `additionalProperties: {}`
693+
// make sure it's not free form object
688694
return false;
689695
}
690696

@@ -760,6 +766,11 @@ public static boolean isFreeFormObject(Schema schema) {
760766
if (objSchema.getProperties() == null || objSchema.getProperties().isEmpty()) {
761767
return true;
762768
}
769+
} else if (addlProps instanceof Schema) {
770+
// additionalProperties defined as {}
771+
if (addlProps.getType() == null && (addlProps.getProperties() == null || addlProps.getProperties().isEmpty())) {
772+
return true;
773+
}
763774
}
764775
}
765776
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ public void testAnyType() {
648648
Assert.assertTrue(property1.hasMore);
649649
Assert.assertFalse(property1.isPrimitiveType);
650650
Assert.assertFalse(property1.isContainer);
651+
Assert.assertFalse(property1.isFreeFormObject);
652+
Assert.assertTrue(property1.isAnyType);
651653

652654
final CodegenProperty property2 = cm1.vars.get(1);
653655
Assert.assertEquals(property2.baseName, "any_value_with_desc");
@@ -656,14 +658,18 @@ public void testAnyType() {
656658
Assert.assertFalse(property2.required);
657659
Assert.assertFalse(property2.isPrimitiveType);
658660
Assert.assertFalse(property2.isContainer);
661+
Assert.assertFalse(property2.isFreeFormObject);
662+
Assert.assertTrue(property2.isAnyType);
659663

660664
final CodegenProperty property3 = cm1.vars.get(2);
661665
Assert.assertEquals(property3.baseName, "any_value_nullable");
662666
Assert.assertEquals(property3.dataType, "oas_any_type_not_mapped");
663-
Assert.assertTrue(property3.hasMore);
667+
Assert.assertFalse(property3.hasMore);
664668
Assert.assertFalse(property3.required);
665669
Assert.assertFalse(property3.isPrimitiveType);
666670
Assert.assertFalse(property3.isContainer);
671+
Assert.assertFalse(property3.isFreeFormObject);
672+
Assert.assertTrue(property3.isAnyType);
667673

668674
Schema test2 = openAPI.getComponents().getSchemas().get("AnyValueModelInline");
669675
codegen.setOpenAPI(openAPI);
@@ -677,6 +683,8 @@ public void testAnyType() {
677683
Assert.assertFalse(cp1.required);
678684
Assert.assertFalse(cp1.isPrimitiveType);
679685
Assert.assertFalse(cp1.isContainer);
686+
Assert.assertFalse(cp1.isFreeFormObject);
687+
Assert.assertTrue(cp1.isAnyType);
680688

681689
final CodegenProperty cp2 = cm1.vars.get(1);
682690
Assert.assertEquals(cp2.baseName, "any_value_with_desc");
@@ -685,6 +693,8 @@ public void testAnyType() {
685693
Assert.assertFalse(cp2.required);
686694
Assert.assertFalse(cp2.isPrimitiveType);
687695
Assert.assertFalse(cp2.isContainer);
696+
Assert.assertFalse(cp2.isFreeFormObject);
697+
Assert.assertTrue(cp2.isAnyType);
688698

689699
final CodegenProperty cp3 = cm1.vars.get(2);
690700
Assert.assertEquals(cp3.baseName, "any_value_nullable");
@@ -693,6 +703,8 @@ public void testAnyType() {
693703
Assert.assertFalse(cp3.required);
694704
Assert.assertFalse(cp3.isPrimitiveType);
695705
Assert.assertFalse(cp3.isContainer);
706+
Assert.assertFalse(cp3.isFreeFormObject);
707+
Assert.assertTrue(cp3.isAnyType);
696708

697709
// map
698710
final CodegenProperty cp4 = cm1.vars.get(3);
@@ -703,7 +715,8 @@ public void testAnyType() {
703715
Assert.assertFalse(cp4.isPrimitiveType);
704716
Assert.assertTrue(cp4.isContainer);
705717
Assert.assertTrue(cp4.isMapContainer);
706-
718+
Assert.assertFalse(cp4.isFreeFormObject);
719+
Assert.assertTrue(cp4.isAnyType);
707720

708721
final CodegenProperty cp5 = cm1.vars.get(4);
709722
Assert.assertEquals(cp5.baseName, "map_any_value_with_desc");
@@ -713,6 +726,8 @@ public void testAnyType() {
713726
Assert.assertFalse(cp5.isPrimitiveType);
714727
Assert.assertTrue(cp5.isContainer);
715728
Assert.assertTrue(cp5.isMapContainer);
729+
Assert.assertFalse(cp5.isFreeFormObject);
730+
Assert.assertTrue(cp5.isAnyType);
716731

717732
final CodegenProperty cp6 = cm1.vars.get(5);
718733
Assert.assertEquals(cp6.baseName, "map_any_value_nullable");
@@ -722,6 +737,8 @@ public void testAnyType() {
722737
Assert.assertFalse(cp6.isPrimitiveType);
723738
Assert.assertTrue(cp6.isContainer);
724739
Assert.assertTrue(cp6.isMapContainer);
740+
Assert.assertFalse(cp6.isFreeFormObject);
741+
Assert.assertTrue(cp6.isAnyType);
725742

726743
// array
727744
final CodegenProperty cp7 = cm1.vars.get(6);
@@ -732,6 +749,8 @@ public void testAnyType() {
732749
Assert.assertFalse(cp7.isPrimitiveType);
733750
Assert.assertTrue(cp7.isContainer);
734751
Assert.assertTrue(cp7.isListContainer);
752+
Assert.assertFalse(cp7.isFreeFormObject);
753+
Assert.assertTrue(cp7.isAnyType);
735754

736755
final CodegenProperty cp8 = cm1.vars.get(7);
737756
Assert.assertEquals(cp8.baseName, "array_any_value_with_desc");
@@ -741,6 +760,8 @@ public void testAnyType() {
741760
Assert.assertFalse(cp8.isPrimitiveType);
742761
Assert.assertTrue(cp8.isContainer);
743762
Assert.assertTrue(cp8.isListContainer);
763+
Assert.assertFalse(cp8.isFreeFormObject);
764+
Assert.assertTrue(cp8.isAnyType);
744765

745766
final CodegenProperty cp9 = cm1.vars.get(8);
746767
Assert.assertEquals(cp9.baseName, "array_any_value_nullable");
@@ -750,5 +771,7 @@ public void testAnyType() {
750771
Assert.assertFalse(cp9.isPrimitiveType);
751772
Assert.assertTrue(cp9.isContainer);
752773
Assert.assertTrue(cp9.isListContainer);
774+
Assert.assertFalse(cp9.isFreeFormObject);
775+
Assert.assertTrue(cp9.isAnyType);
753776
}
754777
}

modules/openapi-generator/src/test/resources/3_0/issue796.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ components:
3434
type: object
3535
description: This type example 4
3636
additionalProperties: false
37-
37+
MapObject:
38+
properties:
39+
map_test1:
40+
$ref: '#/components/schemas/MapTest1'
41+
map_test2:
42+
$ref: '#/components/schemas/MapTest2'
43+
map_test3:
44+
$ref: '#/components/schemas/MapTest3'
45+
other_obj:
46+
$ref: '#/components/schemas/OtherObj'

0 commit comments

Comments
 (0)