OpenApi 3 support- generator script [message #1834558] |
Thu, 12 November 2020 12:17 |
Gábor Szalai Messages: 134 Registered: December 2015 |
Senior Member |
|
|
The 5G_system_TS29571_CommonData protocol module https://git.eclipse.org/r/plugins/gitiles/titan/titan.ProtocolModules.5G_system_TS29571_CommonData_v15 contains a converter script:
tools/OpenApi.py
The OpenApi.py scripts focuses on the yaml definition used in the 5G network function definitions. It contains some optimization for them.
The OpenApi.py creates a TTCN-3 module using the type mapping described here: https://www.eclipse.org/forums/index.php/t/1105886/
Usage:
python3 OpenApi.py <yaml_file>
The uses the following rules;
- The name of the module is the yaml file name, without the extension
- import statement are added for every referenced module
- Encoder/decoder function is defined for every type used in API messages
- Maps the schemas to TTCN-3 type definition according to the mapping rules with the clarification below.
Type mapping rule clarifications
- pattern of strings are not mapped.
- oneOf mapped to union with fields named as field1, field2 etc. The fields are ordered as they appear in the yaml file
- allOf mapped to set by collecting the fields of from the references. If the allOf can't be resolved then it is mapped to JSON_generic_val
- string is mapped to charstring
- Extendable enumeration is converted as the example:
UpIntegrity:
anyOf:
- type: string
enum:
- REQUIRED
- PREFERRED
- NOT_NEEDED
- type: string
Converted to:
type enumerated UpIntegrity_enum { REQUIRED, PREFERRED, NOT_NEEDED}
type union UpIntegrity {
UpIntegrity_enum enum_val,
charstring other_val
} with {
variant "JSON: as value"
}
- anyOf is mapped to union
- TTCN-3 keywords and names are sanitized. The proper encoding attributes are added to the TTCN type definition.
Manual post processing of the generated TTCN-3 module
The OpenApi.py converts only one yaml file at a time. The OpenApi.py creates encoder functions for type defined in another modules. These function declarations should be moved manually to the right module.
[Edit]: allOf support added.
[Updated on: Sat, 14 November 2020 09:10] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04022 seconds