Skip to content

Commit

Permalink
[csharp][generichost] Add support for primitive composed (OpenAPITool…
Browse files Browse the repository at this point in the history
…s#18825)

* add support for primitive composed

* build samples again

* rebuild tests

* addressed comment
  • Loading branch information
devhl-labs authored Jun 4, 2024
1 parent ed2aad6 commit 91a1931
Show file tree
Hide file tree
Showing 289 changed files with 24,035 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
property.name = patchPropertyName(model, camelize(property.baseType));
property.isNullable = true;
patchPropertyVendorExtensions(property);
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
}
}

Expand All @@ -613,6 +614,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
property.name = patchPropertyName(model, camelize(property.baseType));
property.isNullable = true;
patchPropertyVendorExtensions(property);
property.vendorExtensions.put("x-base-name", model.name.substring(model.name.lastIndexOf('_') + 1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,24 @@
{{#model.hasDiscriminatorWithNonEmptyMapping}}
{{#composedSchemas.oneOf}}
{{^vendorExtensions.x-duplicated-data-type}}
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} != null) {
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} != null)
{{#isPrimitiveType}}
{{#isString}}
writer.WriteString("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value);
{{/isString}}
{{#isBoolean}}
writer.WriteBoolean("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value.Value);
{{/isBoolean}}
{{#isNumeric}}
writer.WriteNumber("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value.Value);
{{/isNumeric}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{
{{baseType}}JsonConverter {{#lambda.camelcase_sanitize_param}}{{baseType}}JsonConverter{{/lambda.camelcase_sanitize_param}} = ({{baseType}}JsonConverter) jsonSerializerOptions.Converters.First(c => c.CanConvert({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}.GetType()));
{{#lambda.camelcase_sanitize_param}}{{baseType}}JsonConverter{{/lambda.camelcase_sanitize_param}}.WriteProperties(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}, jsonSerializerOptions);
}
{{/isPrimitiveType}}

{{/vendorExtensions.x-duplicated-data-type}}
{{/composedSchemas.oneOf}}
Expand All @@ -373,10 +387,23 @@
{{#composedSchemas}}
{{#anyOf}}
if ({{#lambda.joinWithAmpersand}}{{^required}}{{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.IsSet {{/required}}{{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}} != null{{/lambda.joinWithAmpersand}})
{{#isPrimitiveType}}
{{#isString}}
writer.WriteString("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value);
{{/isString}}
{{#isBoolean}}
writer.WriteBoolean("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value.Value);
{{/isBoolean}}
{{#isNumeric}}
writer.WriteNumber("{{vendorExtensions.x-base-name}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value.Value);
{{/isNumeric}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{
{{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()));
{{datatypeWithEnum}}JsonConverter.WriteProperties(writer, {{#lambda.camelcase_sanitize_param}}{{model.classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}}, jsonSerializerOptions);
}
{{/isPrimitiveType}}

{{/anyOf}}
{{/composedSchemas}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,32 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ArrayOfEnums'
/fake/mixed/anyOf:
get:
tags:
- fake
summary: Test mixed type anyOf deserialization
operationId: getMixedAnyOf
responses:
200:
description: Got mixed anyOf
content:
application/json:
schema:
$ref: '#/components/schemas/MixedAnyOf'
/fake/mixed/oneOf:
get:
tags:
- fake
summary: Test mixed type oneOf deserialization
operationId: getMixedOneOf
responses:
200:
description: Got mixed oneOf
content:
application/json:
schema:
$ref: '#/components/schemas/MixedOneOf'
/country:
post:
operationId: getCountry
Expand Down Expand Up @@ -2753,6 +2779,41 @@ components:
type: array
items:
$ref: '#/components/schemas/Custom-Variableobject-Response'
MixedOneOf:
properties:
content:
oneOf:
- type: string
- type: boolean
# JsonReader will give back C# System.Int64 regardless of format.
- type: integer
format: uint8
# JsonReader will give back C# System.Double regardless of format.
- type: number
format: float32
- type: object
$ref: '#/components/schemas/MixedSubId'
description: Mixed oneOf types for testing
MixedAnyOf:
properties:
content:
anyOf:
- type: string
- type: boolean
# JsonReader will give back C# System.Int64 regardless of format.
- type: integer
format: uint8
# JsonReader will give back C# System.Double regardless of format.
- type: number
format: float32
- type: object
$ref: '#/components/schemas/MixedSubId'

description: Mixed anyOf types for testing
MixedSubId:
properties:
id:
type: string
# this class ensures that the CodegenProperties are sorted correctly
# https://github.com/OpenAPITools/openapi-generator/issues/18607
MixLog:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ docs/models/Mammal.md
docs/models/MapTest.md
docs/models/MapTestMapOfEnumStringValue.md
docs/models/MixLog.md
docs/models/MixedAnyOf.md
docs/models/MixedAnyOfContent.md
docs/models/MixedOneOf.md
docs/models/MixedOneOfContent.md
docs/models/MixedPropertiesAndAdditionalPropertiesClass.md
docs/models/MixedSubId.md
docs/models/Model200Response.md
docs/models/ModelClient.md
docs/models/Name.md
Expand Down Expand Up @@ -215,7 +220,12 @@ src/Org.OpenAPITools/Model/Mammal.cs
src/Org.OpenAPITools/Model/MapTest.cs
src/Org.OpenAPITools/Model/MapTestMapOfEnumStringValue.cs
src/Org.OpenAPITools/Model/MixLog.cs
src/Org.OpenAPITools/Model/MixedAnyOf.cs
src/Org.OpenAPITools/Model/MixedAnyOfContent.cs
src/Org.OpenAPITools/Model/MixedOneOf.cs
src/Org.OpenAPITools/Model/MixedOneOfContent.cs
src/Org.OpenAPITools/Model/MixedPropertiesAndAdditionalPropertiesClass.cs
src/Org.OpenAPITools/Model/MixedSubId.cs
src/Org.OpenAPITools/Model/Model200Response.cs
src/Org.OpenAPITools/Model/ModelClient.cs
src/Org.OpenAPITools/Model/Name.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,32 @@ paths:
summary: Array of Enums
tags:
- fake
/fake/mixed/anyOf:
get:
operationId: getMixedAnyOf
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/MixedAnyOf'
description: Got mixed anyOf
summary: Test mixed type anyOf deserialization
tags:
- fake
/fake/mixed/oneOf:
get:
operationId: getMixedOneOf
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/MixedOneOf'
description: Got mixed oneOf
summary: Test mixed type oneOf deserialization
tags:
- fake
/country:
post:
operationId: getCountry
Expand Down Expand Up @@ -2528,6 +2554,22 @@ components:
- a_objVariableobject
- pkiNotificationtestID
type: object
MixedOneOf:
example:
content: MixedOneOf_content
properties:
content:
$ref: '#/components/schemas/MixedOneOf_content'
MixedAnyOf:
example:
content: MixedAnyOf_content
properties:
content:
$ref: '#/components/schemas/MixedAnyOf_content'
MixedSubId:
properties:
id:
type: string
MixLog:
properties:
id:
Expand Down Expand Up @@ -2950,6 +2992,26 @@ components:
- unknown
- notUnknown
type: string
MixedOneOf_content:
description: Mixed oneOf types for testing
oneOf:
- type: string
- type: boolean
- format: uint8
type: integer
- format: float32
type: number
- $ref: '#/components/schemas/MixedSubId'
MixedAnyOf_content:
anyOf:
- type: string
- type: boolean
- format: uint8
type: integer
- format: float32
type: number
- $ref: '#/components/schemas/MixedSubId'
description: Mixed anyOf types for testing
securitySchemes:
petstore_auth:
flows:
Expand Down
Loading

0 comments on commit 91a1931

Please sign in to comment.