Skip to content

Commit ea2c686

Browse files
authored
[csharp][generichost] Removed redundant properties (#15869)
* removed redundant properties * removed commneted code * restored discriminator as a model property * build samples
1 parent c23560a commit ea2c686

63 files changed

Lines changed: 161 additions & 1827 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
506506

507507
List<CodegenProperty> anyOf = composedSchemas.getAnyOf();
508508
if (anyOf != null) {
509+
removePropertiesDeclaredInComposedTypes(objs, model, anyOf);
509510
for(CodegenProperty property : anyOf) {
510511
property.name = patchPropertyName(model, property.baseType);
511512
property.isNullable = true;
@@ -514,6 +515,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
514515

515516
List<CodegenProperty> oneOf = composedSchemas.getOneOf();
516517
if (oneOf != null) {
518+
removePropertiesDeclaredInComposedTypes(objs, model, oneOf);
517519
for(CodegenProperty property : oneOf) {
518520
property.name = patchPropertyName(model, property.baseType);
519521
property.isNullable = true;
@@ -552,6 +554,9 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
552554
return processed;
553555
}
554556

557+
protected void removePropertiesDeclaredInComposedTypes(Map<String, ModelsMap> objs, CodegenModel model, List<CodegenProperty> composedProperties) {
558+
}
559+
555560
private String patchPropertyName(CodegenModel model, String value) {
556561
// the casing will be wrong if we just set the name to escapeReservedWord
557562
// if we try to fix it with camelize, underscores get stripped out

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,42 @@ public ModelsMap postProcessModels(ModelsMap objs) {
15921592
return objs;
15931593
}
15941594

1595+
// https://github.com/OpenAPITools/openapi-generator/issues/15867
1596+
@Override
1597+
protected void removePropertiesDeclaredInComposedTypes(Map<String, ModelsMap> objs, CodegenModel model, List<CodegenProperty> composedProperties) {
1598+
if (!GENERICHOST.equals(getLibrary())) {
1599+
return;
1600+
}
1601+
1602+
String discriminatorName = model.discriminator == null
1603+
? null
1604+
: model.discriminator.getPropertyName();
1605+
1606+
for(CodegenProperty oneOfProperty : composedProperties) {
1607+
String ref = oneOfProperty.getRef();
1608+
if (ref != null) {
1609+
for (Map.Entry<String, ModelsMap> composedEntry : objs.entrySet()) {
1610+
CodegenModel composedModel = ModelUtils.getModelByName(composedEntry.getKey(), objs);
1611+
if (ref.endsWith("/" + composedModel.name)) {
1612+
for (CodegenProperty composedProperty : composedModel.allVars) {
1613+
if (discriminatorName != null && composedProperty.name.equals(discriminatorName)) {
1614+
continue;
1615+
}
1616+
model.vars.removeIf(v -> v.name.equals(composedProperty.name));
1617+
model.allVars.removeIf(v -> v.name.equals(composedProperty.name));
1618+
model.readOnlyVars.removeIf(v -> v.name.equals(composedProperty.name));
1619+
model.nonNullableVars.removeIf(v -> v.name.equals(composedProperty.name));
1620+
model.optionalVars.removeIf(v -> v.name.equals(composedProperty.name));
1621+
model.parentRequiredVars.removeIf(v -> v.name.equals(composedProperty.name));
1622+
model.readWriteVars.removeIf(v -> v.name.equals(composedProperty.name));
1623+
model.requiredVars.removeIf(v -> v.name.equals(composedProperty.name));
1624+
}
1625+
}
1626+
}
1627+
}
1628+
}
1629+
}
1630+
15951631
/**
15961632
* Return true if the property being passed is a C# value type
15971633
*

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/Fruit.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**Color** | **string** | | [optional]
8-
**Cultivar** | **string** | | [optional]
9-
**LengthCm** | **decimal** | | [optional]
10-
**Origin** | **string** | | [optional]
118

129
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
1310

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/FruitReq.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**Cultivar** | **string** | |
8-
**LengthCm** | **decimal** | |
9-
**Mealy** | **bool** | | [optional]
10-
**Sweet** | **bool** | | [optional]
117

128
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
139

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/GmFruit.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**Color** | **string** | | [optional]
8-
**Cultivar** | **string** | | [optional]
9-
**LengthCm** | **decimal** | | [optional]
10-
**Origin** | **string** | | [optional]
118

129
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
1310

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/Mammal.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**ClassName** | **string** | |
8-
**HasBaleen** | **bool** | | [optional]
9-
**HasTeeth** | **bool** | | [optional]
10-
**Type** | **string** | | [optional]
118

129
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
1310

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/NullableShape.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ The value may be a shape or the 'null' value. The 'nullable' attribute was intro
55

66
Name | Type | Description | Notes
77
------------ | ------------- | ------------- | -------------
8-
**QuadrilateralType** | **string** | |
98
**ShapeType** | **string** | |
109

1110
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/Quadrilateral.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**QuadrilateralType** | **string** | |
8-
**ShapeType** | **string** | |
98

109
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
1110

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/Shape.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**QuadrilateralType** | **string** | |
87
**ShapeType** | **string** | |
98

109
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/docs/models/ShapeOrNull.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ The value may be a shape or the 'null' value. This is introduced in OAS schema >
55

66
Name | Type | Description | Notes
77
------------ | ------------- | ------------- | -------------
8-
**QuadrilateralType** | **string** | |
98
**ShapeType** | **string** | |
109

1110
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)

0 commit comments

Comments
 (0)