Skip to content

Commit 47bd9f2

Browse files
committed
update samples
2 parents 97c805f + 152e9b0 commit 47bd9f2

File tree

375 files changed

+18145
-409
lines changed

Some content is hidden

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

375 files changed

+18145
-409
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ private boolean codegenPropertyIsNew(CodegenModel model, CodegenProperty propert
555555
? false
556556
: model.parentModel.allVars.stream().anyMatch(p ->
557557
p.name.equals(property.name) &&
558-
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false || p.isDiscriminator));
558+
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false));
559559
}
560560

561561
/**

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

+6
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ private void patchPropertyVendorExtensions(CodegenProperty property) {
726726
property.vendorExtensions.put("x-is-value-type", isValueType);
727727
property.vendorExtensions.put("x-is-reference-type", !isValueType);
728728
property.vendorExtensions.put("x-is-nullable-type", this.getNullableReferencesTypes() || isValueType);
729+
property.vendorExtensions.put("x-is-base-or-new-discriminator", (property.isDiscriminator && !property.isInherited) || (property.isDiscriminator && property.isNew));
730+
}
731+
732+
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
729733
}
730734

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

748+
this.patchPropertyIsInherited(model, property);
749+
744750
patchPropertyVendorExtensions(property);
745751

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

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,18 @@ public String toInstantiationType(Schema schema) {
16081608
}
16091609
}
16101610

1611+
@Override
1612+
protected void patchPropertyIsInherited(CodegenModel model, CodegenProperty property) {
1613+
if (GENERICHOST.equals(getLibrary())) {
1614+
// the isInherited property is not always correct
1615+
// fixing it here causes a breaking change in some generators
1616+
// only do this in generators that are prepared for the improvement
1617+
if (model.parentModel != null && model.parentModel.allVars.stream().anyMatch(v -> v.baseName.equals(property.baseName))) {
1618+
property.isInherited = true;
1619+
}
1620+
}
1621+
}
1622+
16111623
@Override
16121624
protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel model, CodegenProperty property) {
16131625
super.patchProperty(enumRefs, model, property);
@@ -1616,10 +1628,6 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo
16161628
if (!property.isContainer && (this.getNullableTypes().contains(property.dataType) || property.isEnum)) {
16171629
property.vendorExtensions.put("x-csharp-value-type", true);
16181630
}
1619-
} else {
1620-
if (model.parentModel != null && model.parentModel.allVars.stream().anyMatch(v -> v.baseName.equals(property.baseName))) {
1621-
property.isInherited = true;
1622-
}
16231631
}
16241632
}
16251633

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/JsonConverter.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
439439
{{#isDiscriminator}}
440440
{{^model.composedSchemas.anyOf}}
441441
{{^model.composedSchemas.oneOf}}
442-
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}});
442+
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}});
443443

444444
{{/model.composedSchemas.oneOf}}
445445
{{/model.composedSchemas.anyOf}}

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache

+19-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
{{/isNew}}
3535
{{/isInherited}}
3636
{{/isDiscriminator}}
37+
{{#vendorExtensions.x-is-base-or-new-discriminator}}
38+
{{^model.composedSchemas.anyOf}}
39+
{{^model.composedSchemas.oneOf}}
40+
{{name}} = {{^isEnum}}this.GetType().Name{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), this.GetType().Name){{/isEnum}};
41+
{{/model.composedSchemas.oneOf}}
42+
{{/model.composedSchemas.anyOf}}
43+
{{/vendorExtensions.x-is-base-or-new-discriminator}}
3744
{{/allVars}}
3845
OnCreated();
3946
}
@@ -71,6 +78,13 @@
7178
{{/isNew}}
7279
{{/isInherited}}
7380
{{/isDiscriminator}}
81+
{{#vendorExtensions.x-is-base-or-new-discriminator}}
82+
{{^model.composedSchemas.anyOf}}
83+
{{^model.composedSchemas.oneOf}}
84+
{{name}} = {{^isEnum}}this.GetType().Name{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), this.GetType().Name){{/isEnum}};
85+
{{/model.composedSchemas.oneOf}}
86+
{{/model.composedSchemas.anyOf}}
87+
{{/vendorExtensions.x-is-base-or-new-discriminator}}
7488
{{/allVars}}
7589
OnCreated();
7690
}
@@ -162,20 +176,20 @@
162176
{{/vendorExtensions.x-duplicated-data-type}}
163177
{{/composedSchemas.oneOf}}
164178
{{#allVars}}
165-
{{#isDiscriminator}}
179+
{{#vendorExtensions.x-is-base-or-new-discriminator}}
166180
{{^model.composedSchemas.anyOf}}
167181
{{^model.composedSchemas.oneOf}}
168182
/// <summary>
169183
/// The discriminator
170184
/// </summary>
171185
[JsonIgnore]
172186
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
173-
public {{#isNew}}new {{/isNew}}{{datatypeWithEnum}} {{name}} { get; } = {{^isNew}}"{{classname}}"{{/isNew}}{{#isNew}}{{^isEnum}}"{{classname}}"{{/isEnum}}{{#isEnum}}({{datatypeWithEnum}})Enum.Parse(typeof({{datatypeWithEnum}}), "{{classname}}"){{/isEnum}}{{/isNew}};
187+
public {{#isNew}}new {{/isNew}}{{datatypeWithEnum}} {{name}} { get; }
174188

175189
{{/model.composedSchemas.oneOf}}
176190
{{/model.composedSchemas.anyOf}}
177-
{{/isDiscriminator}}
178-
{{^isDiscriminator}}
191+
{{/vendorExtensions.x-is-base-or-new-discriminator}}
192+
{{^vendorExtensions.x-is-base-or-new-discriminator}}
179193
{{^isEnum}}
180194
{{#isInherited}}
181195
{{#isNew}}
@@ -228,7 +242,7 @@
228242

229243
{{/isInherited}}
230244
{{/isEnum}}
231-
{{/isDiscriminator}}
245+
{{/vendorExtensions.x-is-base-or-new-discriminator}}
232246
{{/allVars}}
233247
{{#isAdditionalPropertiesTrue}}
234248
{{^parentModel}}

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

+34
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,40 @@ components:
28362836
properties:
28372837
id:
28382838
type: string
2839+
Descendant1:
2840+
allOf:
2841+
- $ref: "#/components/schemas/TestDescendants"
2842+
- required:
2843+
- "descendantName"
2844+
type: "object"
2845+
properties:
2846+
descendantName:
2847+
type: "string"
2848+
Descendant2:
2849+
allOf:
2850+
- $ref: "#/components/schemas/TestDescendants"
2851+
- required:
2852+
- "confidentiality"
2853+
type: "object"
2854+
properties:
2855+
confidentiality:
2856+
type: "string"
2857+
TestDescendants:
2858+
required:
2859+
- "alternativeName"
2860+
- "objectType"
2861+
type: "object"
2862+
properties:
2863+
alternativeName:
2864+
type: "string"
2865+
objectType:
2866+
type: "string"
2867+
enum:
2868+
- "Descendant1"
2869+
- "Descendant2"
2870+
description: ""
2871+
discriminator:
2872+
propertyName: "objectType"
28392873
CopyActivity:
28402874
type: object
28412875
required:

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Adult.cs

-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ public Adult(Option<List<Child>> children = default, Option<string> firstName =
5757
[JsonPropertyName("children")]
5858
public List<Child> Children { get { return this.ChildrenOption; } set { this.ChildrenOption = new Option<List<Child>>(value); } }
5959

60-
/// <summary>
61-
/// The discriminator
62-
/// </summary>
63-
[JsonIgnore]
64-
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
65-
public new string Type { get; } = "Adult";
66-
6760
/// <summary>
6861
/// Returns the string presentation of the object
6962
/// </summary>

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Child.cs

-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ public Child(Option<int?> age = default, Option<string> firstName = default, Opt
5959
[JsonPropertyName("age")]
6060
public int? Age { get { return this.AgeOption; } set { this.AgeOption = new Option<int?>(value); } }
6161

62-
/// <summary>
63-
/// The discriminator
64-
/// </summary>
65-
[JsonIgnore]
66-
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
67-
public new string Type { get; } = "Child";
68-
6962
/// <summary>
7063
/// Used to track the state of BoosterSeat
7164
/// </summary>

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Model/Person.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Person(Option<string> firstName = default, Option<string> lastName = defa
3939
{
4040
FirstNameOption = firstName;
4141
LastNameOption = lastName;
42+
Type = this.GetType().Name;
4243
OnCreated();
4344
}
4445

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

8081
/// <summary>
8182
/// Gets or Sets additional properties

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

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ docs/models/CopyActivity.md
3434
docs/models/DanishPig.md
3535
docs/models/DateOnlyClass.md
3636
docs/models/DeprecatedObject.md
37+
docs/models/Descendant1.md
38+
docs/models/Descendant2.md
3739
docs/models/Dog.md
3840
docs/models/Drawing.md
3941
docs/models/EntityBase.md
@@ -116,6 +118,8 @@ docs/models/SpecialModelName.md
116118
docs/models/Tag.md
117119
docs/models/TestCollectionEndingWithWordList.md
118120
docs/models/TestCollectionEndingWithWordListObject.md
121+
docs/models/TestDescendants.md
122+
docs/models/TestDescendantsObjectType.md
119123
docs/models/TestEnumParametersEnumHeaderStringParameter.md
120124
docs/models/TestEnumParametersEnumQueryDoubleParameter.md
121125
docs/models/TestEnumParametersEnumQueryIntegerParameter.md
@@ -195,6 +199,8 @@ src/Org.OpenAPITools/Model/CopyActivity.cs
195199
src/Org.OpenAPITools/Model/DanishPig.cs
196200
src/Org.OpenAPITools/Model/DateOnlyClass.cs
197201
src/Org.OpenAPITools/Model/DeprecatedObject.cs
202+
src/Org.OpenAPITools/Model/Descendant1.cs
203+
src/Org.OpenAPITools/Model/Descendant2.cs
198204
src/Org.OpenAPITools/Model/Dog.cs
199205
src/Org.OpenAPITools/Model/Drawing.cs
200206
src/Org.OpenAPITools/Model/EntityBase.cs
@@ -277,6 +283,8 @@ src/Org.OpenAPITools/Model/SpecialModelName.cs
277283
src/Org.OpenAPITools/Model/Tag.cs
278284
src/Org.OpenAPITools/Model/TestCollectionEndingWithWordList.cs
279285
src/Org.OpenAPITools/Model/TestCollectionEndingWithWordListObject.cs
286+
src/Org.OpenAPITools/Model/TestDescendants.cs
287+
src/Org.OpenAPITools/Model/TestDescendantsObjectType.cs
280288
src/Org.OpenAPITools/Model/TestEnumParametersEnumHeaderStringParameter.cs
281289
src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryDoubleParameter.cs
282290
src/Org.OpenAPITools/Model/TestEnumParametersEnumQueryIntegerParameter.cs

samples/client/petstore/csharp/generichost/net4.7/FormModels/api/openapi.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,37 @@ components:
25922592
properties:
25932593
id:
25942594
type: string
2595+
Descendant1:
2596+
allOf:
2597+
- $ref: '#/components/schemas/TestDescendants'
2598+
- properties:
2599+
descendantName:
2600+
type: string
2601+
required:
2602+
- descendantName
2603+
type: object
2604+
Descendant2:
2605+
allOf:
2606+
- $ref: '#/components/schemas/TestDescendants'
2607+
- properties:
2608+
confidentiality:
2609+
type: string
2610+
required:
2611+
- confidentiality
2612+
type: object
2613+
TestDescendants:
2614+
description: ""
2615+
discriminator:
2616+
propertyName: objectType
2617+
properties:
2618+
alternativeName:
2619+
type: string
2620+
objectType:
2621+
$ref: '#/components/schemas/TestDescendants_objectType'
2622+
required:
2623+
- alternativeName
2624+
- objectType
2625+
type: object
25952626
CopyActivity:
25962627
allOf:
25972628
- $ref: '#/components/schemas/EntityBase'
@@ -2984,6 +3015,11 @@ components:
29843015
type: number
29853016
- $ref: '#/components/schemas/MixedSubId'
29863017
description: Mixed anyOf types for testing
3018+
TestDescendants_objectType:
3019+
enum:
3020+
- Descendant1
3021+
- Descendant2
3022+
type: string
29873023
securitySchemes:
29883024
petstore_auth:
29893025
flows:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Org.OpenAPITools.Model.Descendant1
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**AlternativeName** | **string** | |
8+
**ObjectType** | **TestDescendantsObjectType** | |
9+
**DescendantName** | **string** | |
10+
11+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Org.OpenAPITools.Model.Descendant2
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**AlternativeName** | **string** | |
8+
**ObjectType** | **TestDescendantsObjectType** | |
9+
**Confidentiality** | **string** | |
10+
11+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Org.OpenAPITools.Model.TestDescendants
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**AlternativeName** | **string** | |
8+
**ObjectType** | **TestDescendantsObjectType** | |
9+
10+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Org.OpenAPITools.Model.TestDescendantsObjectType
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
8+
[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
9+

0 commit comments

Comments
 (0)