Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
List<CodegenProperty> allOf = composedSchemas.getAllOf();
if (allOf != null) {
for (CodegenProperty property : allOf) {
property.name = patchPropertyName(model, camelize(property.baseType), composedPropertyNames);
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
patchPropertyVendorExtensions(property);
}
}
Expand All @@ -638,7 +638,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
if (anyOf != null) {
removePropertiesDeclaredInComposedTypes(objs, model, anyOf);
for (CodegenProperty property : anyOf) {
property.name = patchPropertyName(model, camelize(property.baseType), composedPropertyNames);
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
property.isNullable = true;
patchPropertyVendorExtensions(property);
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
Expand All @@ -649,7 +649,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
if (oneOf != null) {
removePropertiesDeclaredInComposedTypes(objs, model, oneOf);
for (CodegenProperty property : oneOf) {
property.name = patchPropertyName(model, camelize(property.baseType), composedPropertyNames);
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
property.isNullable = true;
patchPropertyVendorExtensions(property);
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
Expand Down Expand Up @@ -716,7 +716,51 @@ private boolean modelIsMutable(CodegenModel model, Set<String> processed) {
protected void removePropertiesDeclaredInComposedTypes(Map<String, ModelsMap> objs, CodegenModel model, List<CodegenProperty> composedProperties) {
}

private String patchPropertyName(CodegenModel model, String value, Set<String> composedPropertyNames) {
/**
* If the model has duplicate proprety names, just make it unique
* This can happen for base names like "id" and "@id"
* @param model
* @param property
* @param value
* @return
*/
private String setUniquePropertyName(CodegenModel model, CodegenProperty property, String value) {
if (property.name.equalsIgnoreCase(property.baseName)) {
return value;
}

Optional<CodegenProperty> alreadyUpdatedProperty = model.allVars.stream()
.filter(p -> !p.name.equals(property.name) && p.baseName.equals(property.baseName))
.collect(Collectors.toList())
.stream()
.findFirst();

if (alreadyUpdatedProperty.isPresent()) {
// above iterates allVars, which may have already been corrected
return alreadyUpdatedProperty.get().name;
}

final String tmp = value;

long count = model.allVars.stream()
.filter(v -> v.name.equalsIgnoreCase(tmp))
.count();

if (count > 1) {
value = value + count;
value = setUniquePropertyName(model, property, value);
}

return value;
}

/**
* Fixes nested maps so the generic type is defined
* Convertes List<List>> to List<List<T>>
*/
private String patchPropertyName(CodegenModel model, CodegenProperty property, String value, Set<String> composedPropertyNames) {
value = setUniquePropertyName(model, property, value);

String name = escapeReservedWord(model, value);

if (name.startsWith(AbstractCSharpCodegen.invalidParameterNamePrefix)) {
Expand Down Expand Up @@ -799,7 +843,7 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo

patchPropertyVendorExtensions(property);

property.name = patchPropertyName(model, property.name, null);
property.name = patchPropertyName(model, property, property.name, null);

patchNestedMaps(property);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,10 @@ components:
string_formatted_as_decimal_required:
format: decimal
type: string
duplicate_property_name:
type: string
'@duplicate_property_name':
type: string
EnumClass:
type: string
default: '-efg'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,10 @@ components:
string_formatted_as_decimal_required:
format: decimal
type: string
duplicate_property_name:
type: string
'@duplicate_property_name':
type: string
required:
- byte
- date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Name | Type | Description | Notes
**DateTime** | **DateTime** | | [optional]
**Decimal** | **decimal** | | [optional]
**Double** | **double** | | [optional]
**DuplicatePropertyName2** | **string** | | [optional]
**DuplicatePropertyName** | **string** | | [optional]
**Float** | **float** | | [optional]
**Int32** | **int** | | [optional]
**Int32Range** | **int** | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ public void DoubleTest()
// TODO unit test for the property 'Double'
}

/// <summary>
/// Test the property 'DuplicatePropertyName2'
/// </summary>
[Fact]
public void DuplicatePropertyName2Test()
{
// TODO unit test for the property 'DuplicatePropertyName2'
}

/// <summary>
/// Test the property 'DuplicatePropertyName'
/// </summary>
[Fact]
public void DuplicatePropertyNameTest()
{
// TODO unit test for the property 'DuplicatePropertyName'
}

/// <summary>
/// Test the property 'Float'
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public partial class FormatTest : IValidatableObject
/// <param name="dateTime">dateTime</param>
/// <param name="decimal">decimal</param>
/// <param name="double">double</param>
/// <param name="duplicatePropertyName2">duplicatePropertyName2</param>
/// <param name="duplicatePropertyName">duplicatePropertyName</param>
/// <param name="float">float</param>
/// <param name="int32">int32</param>
/// <param name="int32Range">int32Range</param>
Expand All @@ -59,7 +61,7 @@ public partial class FormatTest : IValidatableObject
/// <param name="unsignedLong">unsignedLong</param>
/// <param name="uuid">uuid</param>
[JsonConstructor]
public FormatTest(byte[] @byte, DateTime date, decimal number, string password, decimal stringFormattedAsDecimalRequired, Option<System.IO.Stream> binary = default, Option<DateTime?> dateTime = default, Option<decimal?> @decimal = default, Option<double?> @double = default, Option<float?> @float = default, Option<int?> int32 = default, Option<int?> int32Range = default, Option<long?> int64 = default, Option<long?> int64Negative = default, Option<long?> int64NegativeExclusive = default, Option<long?> int64Positive = default, Option<long?> int64PositiveExclusive = default, Option<int?> integer = default, Option<string> patternWithBackslash = default, Option<string> patternWithDigits = default, Option<string> patternWithDigitsAndDelimiter = default, Option<string> @string = default, Option<decimal?> stringFormattedAsDecimal = default, Option<uint?> unsignedInteger = default, Option<ulong?> unsignedLong = default, Option<Guid?> uuid = default)
public FormatTest(byte[] @byte, DateTime date, decimal number, string password, decimal stringFormattedAsDecimalRequired, Option<System.IO.Stream> binary = default, Option<DateTime?> dateTime = default, Option<decimal?> @decimal = default, Option<double?> @double = default, Option<string> duplicatePropertyName2 = default, Option<string> duplicatePropertyName = default, Option<float?> @float = default, Option<int?> int32 = default, Option<int?> int32Range = default, Option<long?> int64 = default, Option<long?> int64Negative = default, Option<long?> int64NegativeExclusive = default, Option<long?> int64Positive = default, Option<long?> int64PositiveExclusive = default, Option<int?> integer = default, Option<string> patternWithBackslash = default, Option<string> patternWithDigits = default, Option<string> patternWithDigitsAndDelimiter = default, Option<string> @string = default, Option<decimal?> stringFormattedAsDecimal = default, Option<uint?> unsignedInteger = default, Option<ulong?> unsignedLong = default, Option<Guid?> uuid = default)
{
Byte = @byte;
Date = date;
Expand All @@ -70,6 +72,8 @@ public FormatTest(byte[] @byte, DateTime date, decimal number, string password,
DateTimeOption = dateTime;
DecimalOption = @decimal;
DoubleOption = @double;
DuplicatePropertyName2Option = duplicatePropertyName2;
DuplicatePropertyNameOption = duplicatePropertyName;
FloatOption = @float;
Int32Option = int32;
Int32RangeOption = int32Range;
Expand Down Expand Up @@ -176,6 +180,32 @@ public FormatTest(byte[] @byte, DateTime date, decimal number, string password,
[JsonPropertyName("double")]
public double? Double { get { return this.DoubleOption; } set { this.DoubleOption = new Option<double?>(value); } }

/// <summary>
/// Used to track the state of DuplicatePropertyName2
/// </summary>
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public Option<string> DuplicatePropertyName2Option { get; private set; }

/// <summary>
/// Gets or Sets DuplicatePropertyName2
/// </summary>
[JsonPropertyName("duplicate_property_name")]
public string DuplicatePropertyName2 { get { return this.DuplicatePropertyName2Option; } set { this.DuplicatePropertyName2Option = new Option<string>(value); } }

/// <summary>
/// Used to track the state of DuplicatePropertyName
/// </summary>
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public Option<string> DuplicatePropertyNameOption { get; private set; }

/// <summary>
/// Gets or Sets DuplicatePropertyName
/// </summary>
[JsonPropertyName("@duplicate_property_name")]
public string DuplicatePropertyName { get { return this.DuplicatePropertyNameOption; } set { this.DuplicatePropertyNameOption = new Option<string>(value); } }

/// <summary>
/// Used to track the state of Float
/// </summary>
Expand Down Expand Up @@ -424,6 +454,8 @@ public override string ToString()
sb.Append(" DateTime: ").Append(DateTime).Append("\n");
sb.Append(" Decimal: ").Append(Decimal).Append("\n");
sb.Append(" Double: ").Append(Double).Append("\n");
sb.Append(" DuplicatePropertyName2: ").Append(DuplicatePropertyName2).Append("\n");
sb.Append(" DuplicatePropertyName: ").Append(DuplicatePropertyName).Append("\n");
sb.Append(" Float: ").Append(Float).Append("\n");
sb.Append(" Int32: ").Append(Int32).Append("\n");
sb.Append(" Int32Range: ").Append(Int32Range).Append("\n");
Expand Down Expand Up @@ -658,6 +690,8 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
Option<DateTime?> dateTime = default;
Option<decimal?> varDecimal = default;
Option<double?> varDouble = default;
Option<string> duplicatePropertyName2 = default;
Option<string> duplicatePropertyName = default;
Option<float?> varFloat = default;
Option<int?> int32 = default;
Option<int?> int32Range = default;
Expand Down Expand Up @@ -718,6 +752,12 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
case "double":
varDouble = new Option<double?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (double?)null : utf8JsonReader.GetDouble());
break;
case "duplicate_property_name":
duplicatePropertyName2 = new Option<string>(utf8JsonReader.GetString());
break;
case "@duplicate_property_name":
duplicatePropertyName = new Option<string>(utf8JsonReader.GetString());
break;
case "float":
varFloat = new Option<float?>(utf8JsonReader.TokenType == JsonTokenType.Null ? (float?)null : (float)utf8JsonReader.GetDouble());
break;
Expand Down Expand Up @@ -817,6 +857,12 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
if (varDouble.IsSet && varDouble.Value == null)
throw new ArgumentNullException(nameof(varDouble), "Property is not nullable for class FormatTest.");

if (duplicatePropertyName2.IsSet && duplicatePropertyName2.Value == null)
throw new ArgumentNullException(nameof(duplicatePropertyName2), "Property is not nullable for class FormatTest.");

if (duplicatePropertyName.IsSet && duplicatePropertyName.Value == null)
throw new ArgumentNullException(nameof(duplicatePropertyName), "Property is not nullable for class FormatTest.");

if (varFloat.IsSet && varFloat.Value == null)
throw new ArgumentNullException(nameof(varFloat), "Property is not nullable for class FormatTest.");

Expand Down Expand Up @@ -868,7 +914,7 @@ public override FormatTest Read(ref Utf8JsonReader utf8JsonReader, Type typeToCo
if (uuid.IsSet && uuid.Value == null)
throw new ArgumentNullException(nameof(uuid), "Property is not nullable for class FormatTest.");

return new FormatTest(varByte.Value, date.Value.Value, number.Value.Value, password.Value, stringFormattedAsDecimalRequired.Value.Value, binary, dateTime, varDecimal, varDouble, varFloat, int32, int32Range, int64, int64Negative, int64NegativeExclusive, int64Positive, int64PositiveExclusive, integer, patternWithBackslash, patternWithDigits, patternWithDigitsAndDelimiter, varString, stringFormattedAsDecimal, unsignedInteger, unsignedLong, uuid);
return new FormatTest(varByte.Value, date.Value.Value, number.Value.Value, password.Value, stringFormattedAsDecimalRequired.Value.Value, binary, dateTime, varDecimal, varDouble, duplicatePropertyName2, duplicatePropertyName, varFloat, int32, int32Range, int64, int64Negative, int64NegativeExclusive, int64Positive, int64PositiveExclusive, integer, patternWithBackslash, patternWithDigits, patternWithDigitsAndDelimiter, varString, stringFormattedAsDecimal, unsignedInteger, unsignedLong, uuid);
}

/// <summary>
Expand Down Expand Up @@ -904,6 +950,12 @@ public void WriteProperties(Utf8JsonWriter writer, FormatTest formatTest, JsonSe
if (formatTest.BinaryOption.IsSet && formatTest.Binary == null)
throw new ArgumentNullException(nameof(formatTest.Binary), "Property is required for class FormatTest.");

if (formatTest.DuplicatePropertyName2Option.IsSet && formatTest.DuplicatePropertyName2 == null)
throw new ArgumentNullException(nameof(formatTest.DuplicatePropertyName2), "Property is required for class FormatTest.");

if (formatTest.DuplicatePropertyNameOption.IsSet && formatTest.DuplicatePropertyName == null)
throw new ArgumentNullException(nameof(formatTest.DuplicatePropertyName), "Property is required for class FormatTest.");

if (formatTest.PatternWithBackslashOption.IsSet && formatTest.PatternWithBackslash == null)
throw new ArgumentNullException(nameof(formatTest.PatternWithBackslash), "Property is required for class FormatTest.");

Expand Down Expand Up @@ -942,6 +994,12 @@ public void WriteProperties(Utf8JsonWriter writer, FormatTest formatTest, JsonSe
if (formatTest.DoubleOption.IsSet)
writer.WriteNumber("double", formatTest.DoubleOption.Value.Value);

if (formatTest.DuplicatePropertyName2Option.IsSet)
writer.WriteString("duplicate_property_name", formatTest.DuplicatePropertyName2);

if (formatTest.DuplicatePropertyNameOption.IsSet)
writer.WriteString("@duplicate_property_name", formatTest.DuplicatePropertyName);

if (formatTest.FloatOption.IsSet)
writer.WriteNumber("float", formatTest.FloatOption.Value.Value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,10 @@ components:
string_formatted_as_decimal_required:
format: decimal
type: string
duplicate_property_name:
type: string
'@duplicate_property_name':
type: string
required:
- byte
- date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Name | Type | Description | Notes
**DateTime** | **DateTime** | | [optional]
**Decimal** | **decimal** | | [optional]
**Double** | **double** | | [optional]
**DuplicatePropertyName2** | **string** | | [optional]
**DuplicatePropertyName** | **string** | | [optional]
**Float** | **float** | | [optional]
**Int32** | **int** | | [optional]
**Int32Range** | **int** | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ public void DoubleTest()
// TODO unit test for the property 'Double'
}

/// <summary>
/// Test the property 'DuplicatePropertyName2'
/// </summary>
[Fact]
public void DuplicatePropertyName2Test()
{
// TODO unit test for the property 'DuplicatePropertyName2'
}

/// <summary>
/// Test the property 'DuplicatePropertyName'
/// </summary>
[Fact]
public void DuplicatePropertyNameTest()
{
// TODO unit test for the property 'DuplicatePropertyName'
}

/// <summary>
/// Test the property 'Float'
/// </summary>
Expand Down
Loading
Loading