Skip to content

Commit 5d26124

Browse files
committed
fixed composed any of
1 parent 0fe5747 commit 5d26124

File tree

92 files changed

+4290
-123
lines changed

Some content is hidden

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

92 files changed

+4290
-123
lines changed

.github/workflows/samples-dotnet9.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
matrix:
2525
sample:
2626
- samples/client/petstore/csharp/generichost/latest/ComposedEnum
27+
- samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf
2728
- samples/client/petstore/csharp/generichost/latest/Tags
2829
- samples/client/petstore/csharp/generichost/latest/HelloWorld
2930
- samples/client/petstore/csharp/generichost/latest/OneOfList

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ build_script:
4444

4545
test_script:
4646
- dotnet test samples\client\petstore\csharp\generichost\latest\ComposedEnum\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
47+
- dotnet test samples\client\petstore\csharp\generichost\latest\InlineEnumAnyOf\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
4748
- dotnet test samples\client\petstore\csharp\generichost\latest\Tags\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
4849
- dotnet test samples\client\petstore\csharp\generichost\latest\HelloWorld\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
4950
- dotnet test samples\client\petstore\csharp\generichost\latest\OneOfList\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -629,18 +629,18 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
629629
List<CodegenProperty> allOf = composedSchemas.getAllOf();
630630
if (allOf != null) {
631631
for (CodegenProperty property : allOf) {
632+
patchProperty(enumRefs, model, property);
632633
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
633-
patchPropertyVendorExtensions(property);
634634
}
635635
}
636636

637637
List<CodegenProperty> anyOf = composedSchemas.getAnyOf();
638638
if (anyOf != null) {
639639
removePropertiesDeclaredInComposedTypes(objs, model, anyOf);
640640
for (CodegenProperty property : anyOf) {
641+
patchProperty(enumRefs, model, property);
641642
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
642643
property.isNullable = true;
643-
patchPropertyVendorExtensions(property);
644644
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
645645
}
646646
}
@@ -649,18 +649,10 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
649649
if (oneOf != null) {
650650
removePropertiesDeclaredInComposedTypes(objs, model, oneOf);
651651
for (CodegenProperty property : oneOf) {
652+
patchProperty(enumRefs, model, property);
652653
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
653654
property.isNullable = true;
654-
patchPropertyVendorExtensions(property);
655655
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
656-
657-
if (!property.isEnum) {
658-
CodegenModel composedOf = ModelUtils.getModelByName(property.name, processed);
659-
if (composedOf != null) {
660-
property.isEnum = composedOf.isEnum;
661-
patchPropertyVendorExtensions(property);
662-
}
663-
}
664656
}
665657
}
666658
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,17 @@
393393
{{#isNumeric}}
394394
writer.WriteNumber("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value.Value);
395395
{{/isNumeric}}
396+
{{#isEnum}}
397+
{
398+
{{datatypeWithEnum}}JsonConverter {{#lambda.camelcase}}{{datatypeWithEnum}}{{/lambda.camelcase}}JsonConverter = ({{datatypeWithEnum}}JsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert({{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}}.GetType()));
399+
{{#lambda.camelcase}}{{datatypeWithEnum}}{{/lambda.camelcase}}JsonConverter.Write{{^isEnumRef}}Properties{{/isEnumRef}}(writer, {{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}, jsonSerializerOptions);
400+
}
401+
{{/isEnum}}
396402
{{/isPrimitiveType}}
397403
{{^isPrimitiveType}}
398404
{
399-
{{datatypeWithEnum}}JsonConverter {{datatypeWithEnum}}JsonConverter = ({{datatypeWithEnum}}JsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert({{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}}.GetType()));
400-
{{datatypeWithEnum}}JsonConverter.Write{{^isEnumRef}}Properties{{/isEnumRef}}(writer, {{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}, jsonSerializerOptions);
405+
{{datatypeWithEnum}}JsonConverter {{#lambda.camelcase}}{{datatypeWithEnum}}{{/lambda.camelcase}}JsonConverter = ({{datatypeWithEnum}}JsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert({{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}}.GetType()));
406+
{{#lambda.camelcase}}{{datatypeWithEnum}}{{/lambda.camelcase}}JsonConverter.Write{{^isEnumRef}}Properties{{/isEnumRef}}(writer, {{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}, jsonSerializerOptions);
401407
}
402408
{{/isPrimitiveType}}
403409

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
openapi: 3.0.0
2+
info:
3+
description: >-
4+
This spec is mainly for testing Petstore server and contains fake endpoints,
5+
models. Please do not use this for any other purpose. Special characters: "
6+
\
7+
version: 1.0.0
8+
title: OpenAPI Petstore
9+
license:
10+
name: Apache-2.0
11+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
12+
tags:
13+
- name: pet
14+
description: Everything about your Pets
15+
- name: store
16+
description: Access to Petstore orders
17+
- name: user
18+
description: Operations about user
19+
paths:
20+
'/icons':
21+
get:
22+
description: Returns a forecast icon. Icon services in API are deprecated.
23+
operationId: icons
24+
responses:
25+
default:
26+
description: response
27+
content:
28+
application/json:
29+
schema:
30+
type: object
31+
properties:
32+
string:
33+
$ref: '#/components/schemas/Foo'
34+
parameters:
35+
- name: size
36+
in: query
37+
description: Font size
38+
schema:
39+
anyOf:
40+
- enum:
41+
- small
42+
- medium
43+
- large
44+
type: string
45+
- maximum: 500
46+
minimum: 10
47+
type: integer
48+
servers:
49+
- url: 'http://{server}.swagger.io:{port}/v2'
50+
description: petstore server
51+
variables:
52+
server:
53+
enum:
54+
- 'petstore'
55+
- 'qa-petstore'
56+
- 'dev-petstore'
57+
default: 'petstore'
58+
port:
59+
enum:
60+
- 80
61+
- 8080
62+
default: 80
63+
- url: https://localhost:8080/{version}
64+
description: The local server
65+
variables:
66+
version:
67+
enum:
68+
- 'v1'
69+
- 'v2'
70+
default: 'v2'
71+
- url: https://127.0.0.1/no_variable
72+
description: The local server without variables
73+
components:
74+
schemas:
75+
Foo:
76+
type: object
77+
properties:
78+
bar:
79+
$ref: '#/components/schemas/Bar'
80+
Bar:
81+
type: string
82+
default: bar

0 commit comments

Comments
 (0)