Skip to content

Commit

Permalink
improved parameter ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
devhl-labs committed Nov 5, 2023
1 parent baed4ef commit 0116d4a
Show file tree
Hide file tree
Showing 75 changed files with 2,881 additions and 2,910 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,13 @@ public CodegenModel fromModel(String name, Schema model) {
Collections.sort(codegenModel.readWriteVars, propertyComparatorByName);
Collections.sort(codegenModel.parentVars, propertyComparatorByName);

Comparator<CodegenProperty> comparator = propertyComparatorByNullable.thenComparing(propertyComparatorByRequired).thenComparing(propertyComparatorByDefaultValue);
Collections.sort(codegenModel.vars, comparator);
Collections.sort(codegenModel.allVars, comparator);
Collections.sort(codegenModel.requiredVars, comparator);
Collections.sort(codegenModel.optionalVars, comparator);
Collections.sort(codegenModel.readOnlyVars, comparator);
Collections.sort(codegenModel.readWriteVars, comparator);
Collections.sort(codegenModel.parentVars, comparator);
Collections.sort(codegenModel.vars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.allVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.requiredVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.optionalVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.readOnlyVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.readWriteVars, propertyComparatorByNotNullableRequiredNoDefault);
Collections.sort(codegenModel.parentVars, propertyComparatorByNotNullableRequiredNoDefault);
}

return codegenModel;
Expand All @@ -474,36 +473,12 @@ public int compare(CodegenProperty one, CodegenProperty another) {
}
};

public static Comparator<CodegenProperty> propertyComparatorByDefaultValue = new Comparator<CodegenProperty>() {
public static Comparator<CodegenProperty> propertyComparatorByNotNullableRequiredNoDefault = new Comparator<CodegenProperty>() {
@Override
public int compare(CodegenProperty one, CodegenProperty another) {
if ((one.defaultValue == null) == (another.defaultValue == null))
return 0;
else if (one.defaultValue == null)
return -1;
else
return 1;
}
};

public static Comparator<CodegenProperty> propertyComparatorByRequired = new Comparator<CodegenProperty>() {
@Override
public int compare(CodegenProperty one, CodegenProperty another) {
if (one.required == another.required)
return 0;
else if (Boolean.TRUE.equals(one.required))
return -1;
else
return 1;
}
};

public static Comparator<CodegenProperty> propertyComparatorByNullable = new Comparator<CodegenProperty>() {
@Override
public int compare(CodegenProperty one, CodegenProperty another) {
if (one.isNullable == another.isNullable)
if (one.isNullable == another.isNullable && one.required == another.required && (one.defaultValue == null) == (another.defaultValue == null))
return 0;
else if (Boolean.FALSE.equals(one.isNullable))
else if (!one.isNullable && one.required && one.defaultValue == null)
return -1;
else
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SerializationTests()
[TestMethod]
public void Category()
{
Category category = new("test", 1);
Category category = new(1, "test");
string categoryJson = JsonSerializer.Serialize(category, _jsonSerializerOptions);
Category? category2 = JsonSerializer.Deserialize<Category>(categoryJson, _jsonSerializerOptions);
Assert.AreEqual(category.Id, category2?.Id);
Expand Down Expand Up @@ -152,7 +152,7 @@ public void ChildCatTest()
[TestMethod]
public void Cat()
{
Cat cat = new("cat", false, "black"); // TODO: where is the address property?
Cat cat = new("cat", "black", false); // TODO: where is the address property?
string catJson = JsonSerializer.Serialize(cat, _jsonSerializerOptions);
Cat? cat2 = JsonSerializer.Deserialize<Cat>(catJson, _jsonSerializerOptions);
Assert.IsTrue(cat2 != null && cat.Declawed.Equals(cat2.Declawed) && cat.ClassName.Equals(cat2.ClassName) && cat.Color != null && cat.Color.Equals(cat2.Color)); // TODO: add the address property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void ChildCat()
[TestMethod]
public void Cat()
{
Cat cat = new("cat", false, "black"); // TODO: where is the address property?
Cat cat = new("cat", "black", false); // TODO: where is the address property?
string catJson = JsonSerializer.Serialize(cat, _jsonSerializerOptions);
Cat? cat2 = JsonSerializer.Deserialize<Cat>(catJson, _jsonSerializerOptions);
Assert.IsTrue(cat2 != null && cat.Declawed.Equals(cat2.Declawed) && cat.ClassName.Equals(cat2.ClassName) && cat.Color != null && cat.Color.Equals(cat2.Color)); // TODO: add the address property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Anytype1** | **Object** | | [optional]
**EmptyMap** | **Object** | an object with no declared properties and no undeclared properties, hence it&#39;s an empty map. | [optional]
**MapOfMapProperty** | **Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;** | | [optional]
**MapProperty** | **Dictionary&lt;string, string&gt;** | | [optional]
**MapWithUndeclaredPropertiesAnytype1** | **Object** | | [optional]
**MapWithUndeclaredPropertiesAnytype2** | **Object** | | [optional]
**MapWithUndeclaredPropertiesAnytype3** | **Dictionary&lt;string, Object&gt;** | | [optional]
**MapWithUndeclaredPropertiesString** | **Dictionary&lt;string, string&gt;** | | [optional]
**Anytype1** | **Object** | | [optional]

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Name** | **string** | | [default to "default-name"]
**Id** | **long** | | [optional]
**Name** | **string** | | [default to "default-name"]

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**MainShape** | [**Shape**](Shape.md) | | [optional]
**Shapes** | [**List&lt;Shape&gt;**](Shape.md) | | [optional]
**NullableShape** | [**NullableShape**](NullableShape.md) | | [optional]
**ShapeOrNull** | [**ShapeOrNull**](ShapeOrNull.md) | | [optional]
**Shapes** | [**List&lt;Shape&gt;**](Shape.md) | | [optional]

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Name | Type | Description | Notes
**EnumIntegerOnly** | **int** | | [optional]
**EnumNumber** | **double** | | [optional]
**EnumString** | **string** | | [optional]
**OuterEnum** | **OuterEnum** | | [optional]
**OuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**OuterEnumInteger** | **OuterEnumInteger** | | [optional]
**OuterEnumIntegerDefaultValue** | **OuterEnumIntegerDefaultValue** | | [optional]
**OuterEnum** | **OuterEnum** | | [optional]

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**ArrayItemsNullable** | **List&lt;Object&gt;** | | [optional]
**ObjectItemsNullable** | **Dictionary&lt;string, Object&gt;** | | [optional]
**ArrayAndItemsNullableProp** | **List&lt;Object&gt;** | | [optional]
**ArrayItemsNullable** | **List&lt;Object&gt;** | | [optional]
**ArrayNullableProp** | **List&lt;Object&gt;** | | [optional]
**BooleanProp** | **bool** | | [optional]
**DateProp** | **DateTime** | | [optional]
**DatetimeProp** | **DateTime** | | [optional]
**IntegerProp** | **int** | | [optional]
**NumberProp** | **decimal** | | [optional]
**ObjectAndItemsNullableProp** | **Dictionary&lt;string, Object&gt;** | | [optional]
**ObjectItemsNullable** | **Dictionary&lt;string, Object&gt;** | | [optional]
**ObjectNullableProp** | **Dictionary&lt;string, Object&gt;** | | [optional]
**StringProp** | **string** | | [optional]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Complete** | **bool** | | [optional] [default to false]
**Id** | **long** | | [optional]
**PetId** | **long** | | [optional]
**Quantity** | **int** | | [optional]
**ShipDate** | **DateTime** | | [optional]
**Status** | **string** | Order Status | [optional]
**Complete** | **bool** | | [optional] [default to false]

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

Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ Name | Type | Description | Notes
**RequiredNotnullableStringProp** | **string** | |
**RequiredNotnullableUuid** | **Guid** | |
**RequiredNotnullableintegerProp** | **int** | |
**NotRequiredNotnullableDateProp** | **DateTime** | | [optional]
**NotRequiredNotnullableintegerProp** | **int** | | [optional]
**NotrequiredNotnullableArrayOfString** | **List&lt;string&gt;** | | [optional]
**NotrequiredNotnullableBooleanProp** | **bool** | | [optional]
**NotrequiredNotnullableDatetimeProp** | **DateTime** | | [optional]
**NotrequiredNotnullableEnumInteger** | **int** | | [optional]
**NotrequiredNotnullableEnumIntegerOnly** | **int** | | [optional]
**NotrequiredNotnullableEnumString** | **string** | | [optional]
**NotrequiredNotnullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**NotrequiredNotnullableStringProp** | **string** | | [optional]
**NotrequiredNotnullableUuid** | **Guid** | | [optional]
**RequiredNullableArrayOfString** | **List&lt;string&gt;** | |
**RequiredNullableBooleanProp** | **bool** | |
**RequiredNullableDateProp** | **DateTime** | |
Expand All @@ -37,8 +26,19 @@ Name | Type | Description | Notes
**RequiredNullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | |
**RequiredNullableStringProp** | **string** | |
**RequiredNullableUuid** | **Guid** | |
**NotRequiredNotnullableDateProp** | **DateTime** | | [optional]
**NotRequiredNotnullableintegerProp** | **int** | | [optional]
**NotRequiredNullableDateProp** | **DateTime** | | [optional]
**NotRequiredNullableIntegerProp** | **int** | | [optional]
**NotrequiredNotnullableArrayOfString** | **List&lt;string&gt;** | | [optional]
**NotrequiredNotnullableBooleanProp** | **bool** | | [optional]
**NotrequiredNotnullableDatetimeProp** | **DateTime** | | [optional]
**NotrequiredNotnullableEnumInteger** | **int** | | [optional]
**NotrequiredNotnullableEnumIntegerOnly** | **int** | | [optional]
**NotrequiredNotnullableEnumString** | **string** | | [optional]
**NotrequiredNotnullableOuterEnumDefaultValue** | **OuterEnumDefaultValue** | | [optional]
**NotrequiredNotnullableStringProp** | **string** | | [optional]
**NotrequiredNotnullableUuid** | **Guid** | | [optional]
**NotrequiredNullableArrayOfString** | **List&lt;string&gt;** | | [optional]
**NotrequiredNullableBooleanProp** | **bool** | | [optional]
**NotrequiredNullableDatetimeProp** | **DateTime** | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AnyTypeProp** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional]
**AnyTypePropNullable** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The &#39;nullable&#39; attribute does not change the allowed values. | [optional]
**Email** | **string** | | [optional]
**FirstName** | **string** | | [optional]
**Id** | **long** | | [optional]
**LastName** | **string** | | [optional]
**ObjectWithNoDeclaredProps** | **Object** | test code generation for objects Value must be a map of strings to values. It cannot be the &#39;null&#39; value. | [optional]
**ObjectWithNoDeclaredPropsNullable** | **Object** | test code generation for nullable objects. Value must be a map of strings to values or the &#39;null&#39; value. | [optional]
**Password** | **string** | | [optional]
**Phone** | **string** | | [optional]
**UserStatus** | **int** | User Status | [optional]
**Username** | **string** | | [optional]
**AnyTypeProp** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional]
**AnyTypePropNullable** | **Object** | test code generation for any type Here the &#39;type&#39; attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The &#39;nullable&#39; attribute does not change the allowed values. | [optional]
**ObjectWithNoDeclaredPropsNullable** | **Object** | test code generation for nullable objects. Value must be a map of strings to values or the &#39;null&#39; value. | [optional]

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

Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ public static string SanitizeFilename(string filename)
return RequiredClass.RequiredNotnullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNotnullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.RequiredNotnullableEnumStringEnum requiredClassRequiredNotnullableEnumStringEnum)
return RequiredClass.RequiredNotnullableEnumStringEnumToJsonValue(requiredClassRequiredNotnullableEnumStringEnum);
if (obj is RequiredClass.NotrequiredNotnullableEnumIntegerEnum requiredClassNotrequiredNotnullableEnumIntegerEnum)
return RequiredClass.NotrequiredNotnullableEnumIntegerEnumToJsonValue(requiredClassNotrequiredNotnullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.NotrequiredNotnullableEnumIntegerOnlyEnum requiredClassNotrequiredNotnullableEnumIntegerOnlyEnum)
return RequiredClass.NotrequiredNotnullableEnumIntegerOnlyEnumToJsonValue(requiredClassNotrequiredNotnullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.NotrequiredNotnullableEnumStringEnum requiredClassNotrequiredNotnullableEnumStringEnum)
return RequiredClass.NotrequiredNotnullableEnumStringEnumToJsonValue(requiredClassNotrequiredNotnullableEnumStringEnum);
if (obj is RequiredClass.RequiredNullableEnumIntegerEnum requiredClassRequiredNullableEnumIntegerEnum)
return RequiredClass.RequiredNullableEnumIntegerEnumToJsonValue(requiredClassRequiredNullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.RequiredNullableEnumIntegerOnlyEnum requiredClassRequiredNullableEnumIntegerOnlyEnum)
return RequiredClass.RequiredNullableEnumIntegerOnlyEnumToJsonValue(requiredClassRequiredNullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.RequiredNullableEnumStringEnum requiredClassRequiredNullableEnumStringEnum)
return RequiredClass.RequiredNullableEnumStringEnumToJsonValue(requiredClassRequiredNullableEnumStringEnum);
if (obj is RequiredClass.NotrequiredNotnullableEnumIntegerEnum requiredClassNotrequiredNotnullableEnumIntegerEnum)
return RequiredClass.NotrequiredNotnullableEnumIntegerEnumToJsonValue(requiredClassNotrequiredNotnullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.NotrequiredNotnullableEnumIntegerOnlyEnum requiredClassNotrequiredNotnullableEnumIntegerOnlyEnum)
return RequiredClass.NotrequiredNotnullableEnumIntegerOnlyEnumToJsonValue(requiredClassNotrequiredNotnullableEnumIntegerOnlyEnum).ToString();
if (obj is RequiredClass.NotrequiredNotnullableEnumStringEnum requiredClassNotrequiredNotnullableEnumStringEnum)
return RequiredClass.NotrequiredNotnullableEnumStringEnumToJsonValue(requiredClassNotrequiredNotnullableEnumStringEnum);
if (obj is RequiredClass.NotrequiredNullableEnumIntegerEnum requiredClassNotrequiredNullableEnumIntegerEnum)
return RequiredClass.NotrequiredNullableEnumIntegerEnumToJsonValue(requiredClassNotrequiredNullableEnumIntegerEnum).ToString();
if (obj is RequiredClass.NotrequiredNullableEnumIntegerOnlyEnum requiredClassNotrequiredNullableEnumIntegerOnlyEnum)
Expand Down
Loading

0 comments on commit 0116d4a

Please sign in to comment.