Skip to content

Commit ee3ff39

Browse files
authored
fixed sorting (#18706)
1 parent af090fd commit ee3ff39

File tree

75 files changed

+15267
-2687
lines changed

Some content is hidden

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

75 files changed

+15267
-2687
lines changed

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
import java.util.concurrent.atomic.AtomicReference;
3939
import java.util.function.Consumer;
4040
import java.util.stream.Collectors;
41-
import java.util.ArrayList;
42-
import java.util.Comparator;
43-
import java.util.List;
4441

4542
import static org.apache.commons.lang3.StringUtils.isEmpty;
4643
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
@@ -456,7 +453,7 @@ public CodegenModel fromModel(String name, Schema model) {
456453
}
457454

458455
// avoid breaking changes
459-
if (GENERICHOST.equals(getLibrary())) {
456+
if (GENERICHOST.equals(getLibrary()) && codegenModel != null) {
460457

461458
Collections.sort(codegenModel.vars, propertyComparatorByName);
462459
Collections.sort(codegenModel.allVars, propertyComparatorByName);
@@ -485,17 +482,8 @@ public int compare(CodegenProperty one, CodegenProperty another) {
485482
}
486483
};
487484

488-
public static Comparator<CodegenProperty> propertyComparatorByNotNullableRequiredNoDefault = new Comparator<CodegenProperty>() {
489-
@Override
490-
public int compare(CodegenProperty one, CodegenProperty another) {
491-
if (one.isNullable == another.isNullable && one.required == another.required && (one.defaultValue == null) == (another.defaultValue == null))
492-
return 0;
493-
else if (!one.isNullable && one.required && one.defaultValue == null)
494-
return -1;
495-
else
496-
return 1;
497-
}
498-
};
485+
public static Comparator<CodegenProperty> propertyComparatorByNotNullableRequiredNoDefault =
486+
Comparator.comparing(p -> p.isNullable || !p.required || p.defaultValue != null);
499487

500488
public static Comparator<CodegenParameter> parameterComparatorByDataType = new Comparator<CodegenParameter>() {
501489
@Override

modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2752,4 +2752,106 @@ components:
27522752
a_objVariableobject:
27532753
type: array
27542754
items:
2755-
$ref: '#/components/schemas/Custom-Variableobject-Response'
2755+
$ref: '#/components/schemas/Custom-Variableobject-Response'
2756+
# this class ensures that the CodegenProperties are sorted correctly
2757+
# https://github.com/OpenAPITools/openapi-generator/issues/18607
2758+
MixLog:
2759+
type: object
2760+
properties:
2761+
id:
2762+
$ref: '#/components/schemas/uuid'
2763+
description:
2764+
type: string
2765+
mixDate:
2766+
type: string
2767+
format: date-time
2768+
shopId:
2769+
$ref: '#/components/schemas/uuid'
2770+
totalPrice:
2771+
type: number
2772+
format: float
2773+
nullable: true
2774+
totalRecalculations:
2775+
type: integer
2776+
format: int32
2777+
totalOverPoors:
2778+
type: integer
2779+
format: int32
2780+
totalSkips:
2781+
type: integer
2782+
format: int32
2783+
totalUnderPours:
2784+
type: integer
2785+
format: int32
2786+
formulaVersionDate:
2787+
type: string
2788+
format: date-time
2789+
someCode:
2790+
type: string
2791+
nullable: true
2792+
description: SomeCode is only required for color mixes
2793+
batchNumber:
2794+
type: string
2795+
brandCode:
2796+
type: string
2797+
description: BrandCode is only required for non-color mixes
2798+
brandId:
2799+
type: string
2800+
description: BrandId is only required for color mixes
2801+
brandName:
2802+
type: string
2803+
description: BrandName is only required for color mixes
2804+
categoryCode:
2805+
type: string
2806+
description: CategoryCode is not used anymore
2807+
color:
2808+
type: string
2809+
description: Color is only required for color mixes
2810+
colorDescription:
2811+
type: string
2812+
comment:
2813+
type: string
2814+
commercialProductCode:
2815+
type: string
2816+
productLineCode:
2817+
type: string
2818+
description: ProductLineCode is only required for color mixes
2819+
country:
2820+
type: string
2821+
createdBy:
2822+
type: string
2823+
createdByFirstName:
2824+
type: string
2825+
createdByLastName:
2826+
type: string
2827+
deltaECalculationRepaired:
2828+
type: string
2829+
deltaECalculationSprayout:
2830+
type: string
2831+
ownColorVariantNumber:
2832+
nullable: true
2833+
type: integer
2834+
format: int32
2835+
primerProductId:
2836+
type: string
2837+
productId:
2838+
type: string
2839+
description: ProductId is only required for color mixes
2840+
productName:
2841+
type: string
2842+
description: ProductName is only required for color mixes
2843+
selectedVersionIndex:
2844+
type: integer
2845+
format: int32
2846+
required:
2847+
- id
2848+
- description
2849+
- mixDate
2850+
- totalRecalculations
2851+
- totalOverPoors
2852+
- totalSkips
2853+
- totalUnderPours
2854+
- formulaVersionDate
2855+
uuid:
2856+
type: string
2857+
format: uuid

samples/client/petstore/csharp/generichost/net8/FormModels/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ docs/models/LiteralStringClass.md
6262
docs/models/Mammal.md
6363
docs/models/MapTest.md
6464
docs/models/MapTestMapOfEnumStringValue.md
65+
docs/models/MixLog.md
6566
docs/models/MixedPropertiesAndAdditionalPropertiesClass.md
6667
docs/models/Model200Response.md
6768
docs/models/ModelClient.md
@@ -215,6 +216,7 @@ src/Org.OpenAPITools/Model/LiteralStringClass.cs
215216
src/Org.OpenAPITools/Model/Mammal.cs
216217
src/Org.OpenAPITools/Model/MapTest.cs
217218
src/Org.OpenAPITools/Model/MapTestMapOfEnumStringValue.cs
219+
src/Org.OpenAPITools/Model/MixLog.cs
218220
src/Org.OpenAPITools/Model/MixedPropertiesAndAdditionalPropertiesClass.cs
219221
src/Org.OpenAPITools/Model/Model200Response.cs
220222
src/Org.OpenAPITools/Model/ModelClient.cs

samples/client/petstore/csharp/generichost/net8/FormModels/api/openapi.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,108 @@ components:
25282528
- a_objVariableobject
25292529
- pkiNotificationtestID
25302530
type: object
2531+
MixLog:
2532+
properties:
2533+
id:
2534+
format: uuid
2535+
type: string
2536+
description:
2537+
type: string
2538+
mixDate:
2539+
format: date-time
2540+
type: string
2541+
shopId:
2542+
format: uuid
2543+
type: string
2544+
totalPrice:
2545+
format: float
2546+
nullable: true
2547+
type: number
2548+
totalRecalculations:
2549+
format: int32
2550+
type: integer
2551+
totalOverPoors:
2552+
format: int32
2553+
type: integer
2554+
totalSkips:
2555+
format: int32
2556+
type: integer
2557+
totalUnderPours:
2558+
format: int32
2559+
type: integer
2560+
formulaVersionDate:
2561+
format: date-time
2562+
type: string
2563+
someCode:
2564+
description: SomeCode is only required for color mixes
2565+
nullable: true
2566+
type: string
2567+
batchNumber:
2568+
type: string
2569+
brandCode:
2570+
description: BrandCode is only required for non-color mixes
2571+
type: string
2572+
brandId:
2573+
description: BrandId is only required for color mixes
2574+
type: string
2575+
brandName:
2576+
description: BrandName is only required for color mixes
2577+
type: string
2578+
categoryCode:
2579+
description: CategoryCode is not used anymore
2580+
type: string
2581+
color:
2582+
description: Color is only required for color mixes
2583+
type: string
2584+
colorDescription:
2585+
type: string
2586+
comment:
2587+
type: string
2588+
commercialProductCode:
2589+
type: string
2590+
productLineCode:
2591+
description: ProductLineCode is only required for color mixes
2592+
type: string
2593+
country:
2594+
type: string
2595+
createdBy:
2596+
type: string
2597+
createdByFirstName:
2598+
type: string
2599+
createdByLastName:
2600+
type: string
2601+
deltaECalculationRepaired:
2602+
type: string
2603+
deltaECalculationSprayout:
2604+
type: string
2605+
ownColorVariantNumber:
2606+
format: int32
2607+
nullable: true
2608+
type: integer
2609+
primerProductId:
2610+
type: string
2611+
productId:
2612+
description: ProductId is only required for color mixes
2613+
type: string
2614+
productName:
2615+
description: ProductName is only required for color mixes
2616+
type: string
2617+
selectedVersionIndex:
2618+
format: int32
2619+
type: integer
2620+
required:
2621+
- description
2622+
- formulaVersionDate
2623+
- id
2624+
- mixDate
2625+
- totalOverPoors
2626+
- totalRecalculations
2627+
- totalSkips
2628+
- totalUnderPours
2629+
type: object
2630+
uuid:
2631+
format: uuid
2632+
type: string
25312633
_foo_get_default_response:
25322634
example:
25332635
string:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Org.OpenAPITools.Model.MixLog
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**Description** | **string** | |
8+
**FormulaVersionDate** | **DateTime** | |
9+
**Id** | **Guid** | |
10+
**MixDate** | **DateTime** | |
11+
**TotalOverPoors** | **int** | |
12+
**TotalRecalculations** | **int** | |
13+
**TotalSkips** | **int** | |
14+
**TotalUnderPours** | **int** | |
15+
**BatchNumber** | **string** | | [optional]
16+
**BrandCode** | **string** | BrandCode is only required for non-color mixes | [optional]
17+
**BrandId** | **string** | BrandId is only required for color mixes | [optional]
18+
**BrandName** | **string** | BrandName is only required for color mixes | [optional]
19+
**CategoryCode** | **string** | CategoryCode is not used anymore | [optional]
20+
**Color** | **string** | Color is only required for color mixes | [optional]
21+
**ColorDescription** | **string** | | [optional]
22+
**Comment** | **string** | | [optional]
23+
**CommercialProductCode** | **string** | | [optional]
24+
**Country** | **string** | | [optional]
25+
**CreatedBy** | **string** | | [optional]
26+
**CreatedByFirstName** | **string** | | [optional]
27+
**CreatedByLastName** | **string** | | [optional]
28+
**DeltaECalculationRepaired** | **string** | | [optional]
29+
**DeltaECalculationSprayout** | **string** | | [optional]
30+
**OwnColorVariantNumber** | **int** | | [optional]
31+
**PrimerProductId** | **string** | | [optional]
32+
**ProductId** | **string** | ProductId is only required for color mixes | [optional]
33+
**ProductLineCode** | **string** | ProductLineCode is only required for color mixes | [optional]
34+
**ProductName** | **string** | ProductName is only required for color mixes | [optional]
35+
**SelectedVersionIndex** | **int** | | [optional]
36+
**ShopId** | **Guid** | | [optional]
37+
**SomeCode** | **string** | SomeCode is only required for color mixes | [optional]
38+
**TotalPrice** | **float** | | [optional]
39+
40+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
41+

samples/client/petstore/csharp/generichost/net8/FormModels/docs/models/RequiredClass.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ Name | Type | Description | Notes
1515
**RequiredNotnullableStringProp** | **string** | |
1616
**RequiredNotnullableUuid** | **Guid** | |
1717
**RequiredNotnullableintegerProp** | **int** | |
18-
**RequiredNullableArrayOfString** | **List&lt;string&gt;** | |
19-
**RequiredNullableBooleanProp** | **bool** | |
20-
**RequiredNullableDateProp** | **DateOnly** | |
21-
**RequiredNullableDatetimeProp** | **DateTime** | |
22-
**RequiredNullableEnumInteger** | **RequiredClassRequiredNullableEnumInteger** | |
23-
**RequiredNullableEnumIntegerOnly** | **RequiredClassRequiredNullableEnumIntegerOnly** | |
24-
**RequiredNullableEnumString** | **RequiredClassRequiredNullableEnumString** | |
25-
**RequiredNullableIntegerProp** | **int** | |
26-
**RequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
27-
**RequiredNullableStringProp** | **string** | |
28-
**RequiredNullableUuid** | **Guid** | |
2918
**NotRequiredNotnullableDateProp** | **DateOnly** | | [optional]
3019
**NotRequiredNotnullableintegerProp** | **int** | | [optional]
3120
**NotRequiredNullableDateProp** | **DateOnly** | | [optional]
@@ -48,6 +37,17 @@ Name | Type | Description | Notes
4837
**NotrequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
4938
**NotrequiredNullableStringProp** | **string** | | [optional]
5039
**NotrequiredNullableUuid** | **Guid** | | [optional]
40+
**RequiredNullableArrayOfString** | **List&lt;string&gt;** | |
41+
**RequiredNullableBooleanProp** | **bool** | |
42+
**RequiredNullableDateProp** | **DateOnly** | |
43+
**RequiredNullableDatetimeProp** | **DateTime** | |
44+
**RequiredNullableEnumInteger** | **RequiredClassRequiredNullableEnumInteger** | |
45+
**RequiredNullableEnumIntegerOnly** | **RequiredClassRequiredNullableEnumIntegerOnly** | |
46+
**RequiredNullableEnumString** | **RequiredClassRequiredNullableEnumString** | |
47+
**RequiredNullableIntegerProp** | **int** | |
48+
**RequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
49+
**RequiredNullableStringProp** | **string** | |
50+
**RequiredNullableUuid** | **Guid** | |
5151

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

0 commit comments

Comments
 (0)