Skip to content

Commit

Permalink
[BUG][Csharp][GenericHost] OpenApi 3.1: Model property of type map/ad…
Browse files Browse the repository at this point in the history
…ditionalproperties gets generated as object (#18772)

* Fix the bug + add test case

* Add sample output

* Update version number in new sample output

---------

Co-authored-by: Gerwin Jansen <[email protected]>
  • Loading branch information
gerwinjansen and gerwinjansen authored Jun 2, 2024
1 parent 4ae4bc5 commit c08afa3
Show file tree
Hide file tree
Showing 68 changed files with 5,221 additions and 1 deletion.
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
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

0 comments on commit c08afa3

Please sign in to comment.