Skip to content

Commit

Permalink
Merge pull request #78 from patrice-conil/patrice-conil_issue42
Browse files Browse the repository at this point in the history
Use ObjectName as discriminator's mapping key
  • Loading branch information
rartych authored Nov 6, 2023
2 parents 93565cc + 0c85d52 commit 3755022
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions documentation/API-design-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,12 +1072,13 @@ In this part, the error response structure must also be defined, which must be a
</p>

#### 11.5.1 Usage of discriminator
As mentioned in Openapi doc [here](https://spec.openapis.org/oas/v3.0.3#discriminator-object) usage of discriminator may
As mentioned in OpenAPI doc [here](https://spec.openapis.org/oas/v3.0.3#discriminator-object) usage of discriminator may
simplify serialization/deserialization process and so reduce resource consumption.

##### Inheritance
The mappings section is not mandatory in discriminator, by default ClassName are used as values to populate the property. You can use mappings to restrict usage to a subset of subclasses.

The mappings section is not mandatory in discriminator, by default ClassName are used as values to populate the property. You can use mappings to restrict usage to subset of subclasses.
When it's possible, use Object Name as key in mapping section. This will simplify the work of providers and consumers who use OpenAPI code generators.

``` yaml
IpAddr:
Expand All @@ -1090,12 +1091,12 @@ The mappings section is not mandatory in discriminator, by default ClassName are
discriminator:
propertyName: addressType
mappings:
- IPV4ADDR: Ipv4Addr
- IPV6ADDR: Ipv6Addr
- Ipv4Addr: '#/components/schemas/Ipv4Addr' <-- use Object Name as mapping key to simplify usage
- Ipv6Addr: '#/components/schemas/Ipv6Addr'

Ipv4Addr:
Ipv4Addr: <-- Object Name also known as Class Name, used as JsonName by OpenAPI generator
allOf: <-- extends IpAddr (no need to define addressType because it's inherited
- $ref: IpAddr
- $ref: '#/components/schemas/IpAddr'
- type: object
required:
- address
Expand All @@ -1107,7 +1108,7 @@ The mappings section is not mandatory in discriminator, by default ClassName are

Ipv6Addr:
allOf: <-- extends IpAddr
- $ref: IpAddr
- $ref: '#/components/schemas/IpAddr'
- type: object
required:
- address
Expand Down

0 comments on commit 3755022

Please sign in to comment.