Skip to content

Commit 28420f3

Browse files
committed
Re-integrate content from camaraproject#22 due to revert in camaraproject#55.
Fix camaraproject#62 Signed-off-by: Patrice Conil <patrice.conil@orange.com> Signed-off-by: Patrice Conil <patrice.conil@orange.com>
1 parent 32785f0 commit 28420f3

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

documentation/API-design-guidelines.md

+45-2
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,54 @@ In this part, the error response structure must also be defined, which must be a
10581058
</p>
10591059
10601060
#### 11.5.1 Usage of discriminator
1061-
10621061
As mentioned in Openapi doc [here](https://spec.openapis.org/oas/v3.0.3#discriminator-object) usage of discriminator may
10631062
simplify serialization/deserialization process and so reduce resource consumption.
10641063
1065-
To achieve this in the Camara context, we decided that :
1064+
##### Inheritance
1065+
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.
1066+
1067+
1068+
``` yaml
1069+
IpAddr:
1070+
type: object
1071+
properties:
1072+
addressType:
1073+
type: string
1074+
required:
1075+
- addressType
1076+
discriminator:
1077+
propertyName: addressType
1078+
mappings:
1079+
- IPV4ADDR: Ipv4Addr
1080+
- IPV6ADDR: Ipv6Addr
1081+
1082+
Ipv4Addr:
1083+
allOf: <-- extends IpAddr (no need to define addressType because it's inherited
1084+
- $ref: IpAddr
1085+
- type: object
1086+
required:
1087+
- address
1088+
properties:
1089+
address:
1090+
type: string
1091+
format: ipv4
1092+
...
1093+
1094+
Ipv6Addr:
1095+
allOf: <-- extends IpAddr
1096+
- $ref: IpAddr
1097+
- type: object
1098+
required:
1099+
- address
1100+
properties:
1101+
address:
1102+
type: string
1103+
format: ipv6
1104+
...
1105+
```
1106+
1107+
##### Polymorphism
1108+
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:
10661109

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

0 commit comments

Comments
 (0)