forked from loafle/openapi-generator-original
[CSHARP] Fix how the array type is set when using NULLABLE_REFERENCE_TYPES (#22071)
* Fix how the type is calculated for deep inline arrays * Add list alias objects to petstore specification and regenerate samples
This commit is contained in:
committed by
GitHub
parent
2afe7d29cd
commit
23a2aafe91
@@ -1628,7 +1628,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
||||
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema;
|
||||
if (ModelUtils.isArraySchema(target)) {
|
||||
Schema<?> items = getSchemaItems(schema);
|
||||
return getSchemaType(target) + "<" + getTypeDeclarationForArray(items) + ">";
|
||||
return typeMapping.get("array") + "<" + getTypeDeclarationForArray(items) + ">";
|
||||
} else if (ModelUtils.isMapSchema(p)) {
|
||||
// Should we also support maps of maps?
|
||||
Schema<?> inner = ModelUtils.getAdditionalProperties(p);
|
||||
|
||||
@@ -368,11 +368,27 @@ public class CSharpModelTest {
|
||||
public void nullablePropertyWithNullableReferenceTypesTest() {
|
||||
final Schema model = new Schema()
|
||||
.description("a sample model")
|
||||
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT).nullable(true))
|
||||
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT)
|
||||
.nullable(true))
|
||||
.addProperties("urls", new ArraySchema()
|
||||
.items(new StringSchema()).nullable(true))
|
||||
.items(new StringSchema())
|
||||
.nullable(true))
|
||||
.addProperties("name", new StringSchema().nullable(true))
|
||||
.addProperties("subObject", new Schema().addProperties("name", new StringSchema()).nullable(true))
|
||||
.addProperties("subObject", new Schema().addProperties("name", new StringSchema())
|
||||
.nullable(true))
|
||||
.addProperties("deepNullableAliasArray", new ArraySchema()
|
||||
.items(new ArraySchema()
|
||||
.items(new StringSchema()
|
||||
.nullable(true))
|
||||
.nullable(true))
|
||||
.nullable(true))
|
||||
.addProperties("deepAliasArray", new ArraySchema()
|
||||
.items(new ArraySchema()
|
||||
.items(new StringSchema())))
|
||||
.addProperties("deepIntermediateNullableAliasArray", new ArraySchema()
|
||||
.items(new ArraySchema()
|
||||
.items(new StringSchema())
|
||||
.nullable(true)))
|
||||
.addRequiredItem("id");
|
||||
final DefaultCodegen codegen = new AspNetServerCodegen();
|
||||
codegen.processOpts();
|
||||
@@ -385,7 +401,7 @@ public class CSharpModelTest {
|
||||
Assert.assertEquals(cm.name, "sample");
|
||||
Assert.assertEquals(cm.classname, "Sample");
|
||||
Assert.assertEquals(cm.description, "a sample model");
|
||||
Assert.assertEquals(cm.vars.size(), 4);
|
||||
Assert.assertEquals(cm.vars.size(), 7);
|
||||
|
||||
final CodegenProperty property1 = cm.vars.get(0);
|
||||
Assert.assertEquals(property1.baseName, "id");
|
||||
@@ -398,7 +414,7 @@ public class CSharpModelTest {
|
||||
|
||||
final CodegenProperty property2 = cm.vars.get(1);
|
||||
Assert.assertEquals(property2.baseName, "urls");
|
||||
Assert.assertEquals(property2.dataType, "List?<string>");
|
||||
Assert.assertEquals(property2.dataType, "List<string>");
|
||||
Assert.assertEquals(property2.name, "Urls");
|
||||
Assert.assertNull(property2.defaultValue);
|
||||
Assert.assertEquals(property2.baseType, "List?");
|
||||
@@ -424,6 +440,33 @@ public class CSharpModelTest {
|
||||
Assert.assertEquals(property4.baseType, "Object?");
|
||||
Assert.assertFalse(property4.required);
|
||||
Assert.assertFalse(property4.isPrimitiveType);
|
||||
|
||||
final CodegenProperty property5 = cm.vars.get(4);
|
||||
Assert.assertEquals(property5.baseName, "deepNullableAliasArray");
|
||||
Assert.assertEquals(property5.dataType, "List<List<string?>>");
|
||||
Assert.assertEquals(property5.name, "DeepNullableAliasArray");
|
||||
Assert.assertNull(property5.defaultValue);
|
||||
Assert.assertEquals(property5.baseType, "List?");
|
||||
Assert.assertEquals(property5.containerType, "array");
|
||||
Assert.assertFalse(property5.required);
|
||||
Assert.assertFalse(property5.isPrimitiveType);
|
||||
Assert.assertTrue(property5.isContainer);
|
||||
|
||||
final CodegenProperty property6 = cm.vars.get(5);
|
||||
Assert.assertEquals(property6.baseName, "deepAliasArray");
|
||||
Assert.assertEquals(property6.dataType, "List<List<string>>");
|
||||
Assert.assertEquals(property6.name, "DeepAliasArray");
|
||||
Assert.assertEquals(property6.baseType, "List");
|
||||
Assert.assertEquals(property6.containerType, "array");
|
||||
Assert.assertTrue(property6.isContainer);
|
||||
|
||||
final CodegenProperty property7 = cm.vars.get(6);
|
||||
Assert.assertEquals(property7.baseName, "deepIntermediateNullableAliasArray");
|
||||
Assert.assertEquals(property7.dataType, "List<List<string>>");
|
||||
Assert.assertEquals(property7.name, "DeepIntermediateNullableAliasArray");
|
||||
Assert.assertEquals(property7.baseType, "List");
|
||||
Assert.assertEquals(property7.containerType, "array");
|
||||
Assert.assertTrue(property7.isContainer);
|
||||
}
|
||||
|
||||
@Test(description = "convert a model with list property")
|
||||
|
||||
@@ -2935,6 +2935,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
additionalProperties:
|
||||
type: string
|
||||
ListAlias:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
DeepListAlias:
|
||||
type: array
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
TestResult:
|
||||
type: object
|
||||
allOf:
|
||||
|
||||
@@ -2687,6 +2687,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2687,6 +2687,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2687,6 +2687,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2687,6 +2687,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
@@ -2868,6 +2868,16 @@ components:
|
||||
description: list of named parameters for current message
|
||||
type: object
|
||||
type: object
|
||||
ListAlias:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
DeepListAlias:
|
||||
items:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
type: array
|
||||
TestResult:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Result"
|
||||
|
||||
Reference in New Issue
Block a user