Skip to content

Commit f6eeb01

Browse files
authored
[csharp] Fixed any of inline enum (#21764)
* fixed composed any of * fixed composed any of * fixed spacing
1 parent 8ee69bf commit f6eeb01

File tree

210 files changed

+5683
-786
lines changed

Some content is hidden

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

210 files changed

+5683
-786
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
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# for csharp generichost
2+
generatorName: csharp
3+
outputDir: samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/csharp/inline-enum-any-of.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/csharp
6+
additionalProperties:
7+
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
8+
modelPropertySorting: alphabetical
9+
operationParameterSorting: alphabetical
10+
validateSpec: false
11+
inlineSchemaOptions:
12+
RESOLVE_INLINE_ENUMS: true

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
@@ -626,18 +626,18 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
626626
List<CodegenProperty> allOf = composedSchemas.getAllOf();
627627
if (allOf != null) {
628628
for (CodegenProperty property : allOf) {
629+
patchProperty(enumRefs, model, property);
629630
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
630-
patchPropertyVendorExtensions(property);
631631
}
632632
}
633633

634634
List<CodegenProperty> anyOf = composedSchemas.getAnyOf();
635635
if (anyOf != null) {
636636
removePropertiesDeclaredInComposedTypes(objs, model, anyOf);
637637
for (CodegenProperty property : anyOf) {
638+
patchProperty(enumRefs, model, property);
638639
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
639640
property.isNullable = true;
640-
patchPropertyVendorExtensions(property);
641641
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
642642
}
643643
}
@@ -646,18 +646,10 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
646646
if (oneOf != null) {
647647
removePropertiesDeclaredInComposedTypes(objs, model, oneOf);
648648
for (CodegenProperty property : oneOf) {
649+
patchProperty(enumRefs, model, property);
649650
property.name = patchPropertyName(model, property, camelize(property.baseType), composedPropertyNames);
650651
property.isNullable = true;
651-
patchPropertyVendorExtensions(property);
652652
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
653-
654-
if (!property.isEnum) {
655-
CodegenModel composedOf = ModelUtils.getModelByName(property.name, processed);
656-
if (composedOf != null) {
657-
property.isEnum = composedOf.isEnum;
658-
patchPropertyVendorExtensions(property);
659-
}
660-
}
661653
}
662654
}
663655
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
if (!suppressDefaultLog)
2-
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
2+
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);

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

samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ private void AfterHelloWorldPostDefaultImplementation(IHelloWorldPostApiResponse
166166
bool suppressDefaultLog = false;
167167
AfterHelloWorldPost(ref suppressDefaultLog, apiResponseLocalVar, helloWorldPostRequest);
168168
if (!suppressDefaultLog)
169-
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path); }
169+
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
170+
}
170171

171172
/// <summary>
172173
/// Processes the server response

0 commit comments

Comments
 (0)