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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ private boolean codegenPropertyIsNew(CodegenModel model, CodegenProperty propert
? false
: model.parentModel.allVars.stream().anyMatch(p ->
p.name.equals(property.name) &&
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false || p.isDiscriminator));
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ private void patchPropertyVendorExtensions(CodegenProperty property) {
property.vendorExtensions.put("x-is-value-type", isValueType);
property.vendorExtensions.put("x-is-reference-type", !isValueType);
property.vendorExtensions.put("x-is-nullable-type", this.getNullableReferencesTypes() || isValueType);
property.vendorExtensions.put("x-is-base-or-new-discriminator", (property.isDiscriminator && !property.isInherited) || (property.isDiscriminator && property.isNew));
}

protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
}

protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
Expand All @@ -741,6 +745,8 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo
property.isPrimitiveType = true;
}

this.patchPropertyIsInherited(model, property);

patchPropertyVendorExtensions(property);

property.name = patchPropertyName(model, property.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,18 @@ public String toInstantiationType(Schema schema) {
}
}

@Override
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
if (GENERICHOST.equals(getLibrary())) {
// the isInherited property is not always correct
// fixing it here causes a breaking change in some generators
// only do this in generators that are prepared for the improvement
if (model.parentModel != null && model.parentModel.allVars.stream().anyMatch(v -> v.baseName.equals(property.baseName))) {
property.isInherited = true;
}
}
}

@Override
protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
super.patchProperty(enumRefs, model, property);
Expand All @@ -1616,10 +1628,6 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo
if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) {
property.vendorExtensions.put("x-csharp-value-type", true);
}
} else {
if (model.parentModel != null && model.parentModel.allVars.stream().anyMatch(v -> v.baseName.equals(property.baseName))) {
property.isInherited = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
{{#isDiscriminator}}
{{^model.composedSchemas.anyOf}}
{{^model.composedSchemas.oneOf}}
writer.WriteString("{{baseName}}", {{^isEnum}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{/isEnum}}{{#isNew}}{{#isEnum}}{{#isInnerEnum}}{{classname}}.{{{datatypeWithEnum}}}ToJsonValue{{/isInnerEnum}}{{^isInnerEnum}}{{{datatypeWithEnum}}}ValueConverter.ToJsonValue{{/isInnerEnum}}({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}.Value{{/required}}){{/isEnum}}{{/isNew}});
writer.WriteString("{{baseName}}", {{^isEnum}}{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{/isEnum}}{{#isEnum}}{{#isInnerEnum}}{{classname}}.{{{datatypeWithEnum}}}ToJsonValue{{/isInnerEnum}}{{^isInnerEnum}}{{{datatypeWithEnum}}}ValueConverter.ToJsonValue{{/isInnerEnum}}({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}.Value{{/required}}){{/isEnum}});

{{/model.composedSchemas.oneOf}}
{{/model.composedSchemas.anyOf}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
{{/isNew}}
{{/isInherited}}
{{/isDiscriminator}}
{{#vendorExtensions.x-is-base-or-new-discriminator}}
{{^model.composedSchemas.anyOf}}
{{^model.composedSchemas.oneOf}}
{{name}} = {{^isEnum}}this.GetType().Name{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), this.GetType().Name){{/isEnum}};
{{/model.composedSchemas.oneOf}}
{{/model.composedSchemas.anyOf}}
{{/vendorExtensions.x-is-base-or-new-discriminator}}
{{/allVars}}
OnCreated();
}
Expand Down Expand Up @@ -71,6 +78,13 @@
{{/isNew}}
{{/isInherited}}
{{/isDiscriminator}}
{{#vendorExtensions.x-is-base-or-new-discriminator}}
{{^model.composedSchemas.anyOf}}
{{^model.composedSchemas.oneOf}}
{{name}} = {{^isEnum}}this.GetType().Name{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), this.GetType().Name){{/isEnum}};
{{/model.composedSchemas.oneOf}}
{{/model.composedSchemas.anyOf}}
{{/vendorExtensions.x-is-base-or-new-discriminator}}
{{/allVars}}
OnCreated();
}
Expand Down Expand Up @@ -162,20 +176,20 @@
{{/vendorExtensions.x-duplicated-data-type}}
{{/composedSchemas.oneOf}}
{{#allVars}}
{{#isDiscriminator}}
{{#vendorExtensions.x-is-base-or-new-discriminator}}
{{^model.composedSchemas.anyOf}}
{{^model.composedSchemas.oneOf}}
/// <summary>
/// The discriminator
/// </summary>
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public {{#isNew}}new {{/isNew}}{{datatypeWithEnum}} {{name}} { get; } = {{^isNew}}"{{classname}}"{{/isNew}}{{#isNew}}{{^isEnum}}"{{classname}}"{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), "{{classname}}"){{/isEnum}}{{/isNew}};
public {{#isNew}}new {{/isNew}}{{datatypeWithEnum}} {{name}} { get; }

{{/model.composedSchemas.oneOf}}
{{/model.composedSchemas.anyOf}}
{{/isDiscriminator}}
{{^isDiscriminator}}
{{/vendorExtensions.x-is-base-or-new-discriminator}}
{{^vendorExtensions.x-is-base-or-new-discriminator}}
{{^isEnum}}
{{#isInherited}}
{{#isNew}}
Expand Down Expand Up @@ -228,7 +242,7 @@

{{/isInherited}}
{{/isEnum}}
{{/isDiscriminator}}
{{/vendorExtensions.x-is-base-or-new-discriminator}}
{{/allVars}}
{{#isAdditionalPropertiesTrue}}
{{^parentModel}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,40 @@ components:
properties:
id:
type: string
Descendant1:
allOf:
- $ref: "#/components/schemas/TestDescendants"
- required:
- "descendantName"
type: "object"
properties:
descendantName:
type: "string"
Descendant2:
allOf:
- $ref: "#/components/schemas/TestDescendants"
- required:
- "confidentiality"
type: "object"
properties:
confidentiality:
type: "string"
TestDescendants:
required:
- "alternativeName"
- "objectType"
type: "object"
properties:
alternativeName:
type: "string"
objectType:
type: "string"
enum:
- "Descendant1"
- "Descendant2"
description: ""
discriminator:
propertyName: "objectType"
CopyActivity:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ public Adult(Option<List<Child>> children = default, Option<string> firstName =
[JsonPropertyName("children")]
public List<Child> Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new Option<List<Child>>(value); } }

/// <summary>
/// The discriminator
/// </summary>
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public new string Type { get; } = "Adult";

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ public Child(Option<int?> age = default, Option<string> firstName = default, Opt
[JsonPropertyName("age")]
public int? Age { get { return this.AgeOption; } set { this.AgeOption = new Option<int?>(value); } }

/// <summary>
/// The discriminator
/// </summary>
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public new string Type { get; } = "Child";

/// <summary>
/// Used to track the state of BoosterSeat
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Person(Option<string> firstName = default, Option<string> lastName = defa
{
FirstNameOption = firstName;
LastNameOption = lastName;
Type = this.GetType().Name;
OnCreated();
}

Expand Down Expand Up @@ -75,7 +76,7 @@ public Person(Option<string> firstName = default, Option<string> lastName = defa
/// </summary>
[JsonIgnore]
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
public string Type { get; } = "Person";
public string Type { get; }

/// <summary>
/// Gets or Sets additional properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ docs/models/CopyActivity.md
docs/models/DanishPig.md
docs/models/DateOnlyClass.md
docs/models/DeprecatedObject.md
docs/models/Descendant1.md
docs/models/Descendant2.md
docs/models/Dog.md
docs/models/Drawing.md
docs/models/EntityBase.md
Expand Down Expand Up @@ -116,6 +118,8 @@ docs/models/SpecialModelName.md
docs/models/Tag.md
docs/models/TestCollectionEndingWithWordList.md
docs/models/TestCollectionEndingWithWordListObject.md
docs/models/TestDescendants.md
docs/models/TestDescendantsObjectType.md
docs/models/TestEnumParametersEnumHeaderStringParameter.md
docs/models/TestEnumParametersEnumQueryDoubleParameter.md
docs/models/TestEnumParametersEnumQueryIntegerParameter.md
Expand Down Expand Up @@ -195,6 +199,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs
src/Org.OpenAPITools/Model/DanishPig.cs
src/Org.OpenAPITools/Model/DateOnlyClass.cs
src/Org.OpenAPITools/Model/DeprecatedObject.cs
src/Org.OpenAPITools/Model/Descendant1.cs
src/Org.OpenAPITools/Model/Descendant2.cs
src/Org.OpenAPITools/Model/Dog.cs
src/Org.OpenAPITools/Model/Drawing.cs
src/Org.OpenAPITools/Model/EntityBase.cs
Expand Down Expand Up @@ -277,6 +283,8 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs
src/Org.OpenAPITools/Model/Tag.cs
src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs
src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs
src/Org.OpenAPITools/Model/TestDescendants.cs
src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs
src/Org.OpenAPITools/Model/TestEnumParametersEnumHeaderStringParameter.cs
src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs
src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2592,6 +2592,37 @@ components:
properties:
id:
type: string
Descendant1:
allOf:
- $ref: '#/components/schemas/TestDescendants'
- properties:
descendantName:
type: string
required:
- descendantName
type: object
Descendant2:
allOf:
- $ref: '#/components/schemas/TestDescendants'
- properties:
confidentiality:
type: string
required:
- confidentiality
type: object
TestDescendants:
description: ""
discriminator:
propertyName: objectType
properties:
alternativeName:
type: string
objectType:
$ref: '#/components/schemas/TestDescendants_objectType'
required:
- alternativeName
- objectType
type: object
CopyActivity:
allOf:
- $ref: '#/components/schemas/EntityBase'
Expand Down Expand Up @@ -2984,6 +3015,11 @@ components:
type: number
- $ref: '#/components/schemas/MixedSubId'
description: Mixed anyOf types for testing
TestDescendants_objectType:
enum:
- Descendant1
- Descendant2
type: string
securitySchemes:
petstore_auth:
flows:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Org.OpenAPITools.Model.Descendant1

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AlternativeName** | **string** | |
**ObjectType** | **TestDescendantsObjectType** | |
**DescendantName** | **string** | |

[[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
@@ -0,0 +1,12 @@
# Org.OpenAPITools.Model.Descendant2

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AlternativeName** | **string** | |
**ObjectType** | **TestDescendantsObjectType** | |
**Confidentiality** | **string** | |

[[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
@@ -0,0 +1,11 @@
# Org.OpenAPITools.Model.TestDescendants

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AlternativeName** | **string** | |
**ObjectType** | **TestDescendantsObjectType** | |

[[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
@@ -0,0 +1,9 @@
# Org.OpenAPITools.Model.TestDescendantsObjectType

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

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

Loading
Loading