Skip to content

Commit

Permalink
Re-integrate content from camaraproject#22 due to revert in camarapro…
Browse files Browse the repository at this point in the history
…ject#55.

Fix camaraproject#62
Signed-off-by: Patrice Conil <patrice.conil@orange.com>

Signed-off-by: Patrice Conil <patrice.conil@orange.com>
  • Loading branch information
patrice-conil committed Sep 18, 2023
1 parent 32785f0 commit 28420f3
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions documentation/API-design-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,54 @@ 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
simplify serialization/deserialization process and so reduce resource consumption.
To achieve this in the Camara context, we decided that :
##### 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 subset of subclasses.
``` yaml
IpAddr:
type: object
properties:
addressType:
type: string
required:
- addressType
discriminator:
propertyName: addressType
mappings:
- IPV4ADDR: Ipv4Addr
- IPV6ADDR: Ipv6Addr
Ipv4Addr:
allOf: <-- extends IpAddr (no need to define addressType because it's inherited
- $ref: IpAddr
- type: object
required:
- address
properties:
address:
type: string
format: ipv4
...
Ipv6Addr:
allOf: <-- extends IpAddr
- $ref: IpAddr
- type: object
required:
- address
properties:
address:
type: string
format: ipv6
...
```

##### Polymorphism
To help usage of Camara object from strongly typed languages prefer to use inheritance than polymorphism ... Despite this, if you have to use it apply following rules:

- objects containing oneOf or anyOf section MUST include a discriminator defined by a propertyName
- objects involved in oneOf / anyOf section MUST include the property designed by propetyName
Expand Down

0 comments on commit 28420f3

Please sign in to comment.