Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Csharp][GenericHost] OpenApi 3.1: Model property of type map/additionalproperties gets generated as object #18772

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bin/configs/csharp-generichost-net8-oneOf-3.1.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# for csharp generichost
generatorName: csharp
outputDir: samples/client/petstore/csharp/generichost/net8/OneOfDiscriminator-3.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR, which looks good me.

after merging, i'll replace this test (sample) with a unit test instead similar to other 3.1 tests we've added so far.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done via #18828

inputSpec: modules/openapi-generator/src/test/resources/3_1/csharp/oneOfDiscriminator.yaml
library: generichost
templateDir: modules/openapi-generator/src/main/resources/csharp
additionalProperties:
packageGuid: '{321C8C3F-0156-40C1-AE42-D59761FB9B6C}'
useCompareNetObjects: true
disallowAdditionalPropertiesIfNotPresent: false
nullableReferenceTypes: true
equatable: true
targetFramework: net8.0
useOneOfDiscriminatorLookup: true
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public static boolean isMapSchema(Schema schema) {
}

if (schema instanceof JsonSchema) { // 3.1 spec
return ((schema.getAdditionalProperties() instanceof JsonSchema) ||
return ((schema.getAdditionalProperties() instanceof Schema) ||
(schema.getAdditionalProperties() instanceof Boolean && (Boolean) schema.getAdditionalProperties()));
} else { // 3.0 or 2.x spec
return (schema instanceof MapSchema) ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
openapi: 3.1.0
info:
title: oneof
version: 0.0.1
paths:
/:
get:
responses:
'200':
description: Key-value pairs with results
content:
application/json:
schema:
$ref: '#/components/schemas/Response'
components:
schemas:

Result:
properties:
type:
type: string
checksum:
type: string
required:
- type
- checksum
discriminator:
propertyName: type

FileResult:
allOf:
- $ref: '#/components/schemas/Result'
properties:
downloadUrl:
type: string
required:
- downloadUrl

StringResult:
allOf:
- $ref: '#/components/schemas/Result'
properties:
data:
type: string
required:
- data

Response:
type: object
properties:
success:
type: boolean
results:
additionalProperties: #key-value map
oneOf:
- $ref: '#/components/schemas/FileResult'
- $ref: '#/components/schemas/StringResult'
required:
- success
- results
Loading
Loading