OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including:
Available endpoints (/users) and operations on each endpoint (GET /users, POST /users)
Operation parameters Input and output for each operation
Authentication methods
Contact information, license, terms of use and other information.
More information:
https://swagger.io/docs/specification/about/
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md
The OpenAPI 3 data types are based on an extended subset JSON Schema Specification. As the TITAN natively supports JSON encoding the OpenAPI data types can be represented in TTCN-3.
OpenAPI 3 <-> TTCN-3 type mapping
integer
The OpenAPI integer type is mapped to TTCN-3 integer. The range restrictions are mapped to the TTCN-3 range restrictions. The format specifier can be ignored during the mapping.
Example:
components:
schemas:
Uint16:
type: integer
minimum: 0
maximum: 65535
Int32:
format: int32
type: integer
The TTCN-3 type definitions
type integer Uint16 (0..65535)
type integer Int32
string
The OpenAPI string type is mapped to TTCN-3 charstring or universal charstring. The format specifier can be ignored during the mapping. The pattern can be mapped to TTCN-3 pattern restriction.
Example:
components:
schemas:
Date:
format: date
type: string
DiameterIdentity:
type: string
pattern: '^([A-Za-z0-9]+([-A-Za-z0-9]+)\.)+[a-z]{2,}$'
The TTCN-3 type definitions
type charstring Date
type charstring DiameterIdentity // pattern "([A-Za-z0-9]+([-A-Za-z0-9]+)\.)+[a-z]{2,}"
boolean
The OpenAPI boolean type is mapped to TTCN-3 boolean.
Example:
components:
schemas:
BoolT:
type: boolean
The TTCN-3 type definitions
array
The OpenAPI array type is mapped to TTCN-3 record of. The length restriction properties minItems and maxItems can be mapped to the TTCN-3 length restriction
Example:
components:
schemas:
ArrayT:
type: array
items:
type: integer
minItems: 1
maxItems: 10
The TTCN-3 type definitions
type reocrd of integer ArrayT length(1..10)
Any Type
A schema without a type matches any data type is mapped to JSON_generic_val which can represent any kind of JSON value.
Example:
components:
schemas:
AnyValue: {}
The TTCN-3 type definitions
type JSON_Generic.JSON_generic_val AnyValue
enum
The OpenAPI string types enum type is mapped to TTCN-3 enumerated.
Example:
components:
schemas:
Color:
type: string
enum:
- black
- white
- red
The TTCN-3 type definitions
type enumarated Color {black, white, red}
object
The OpenAPI object type is mapped to TTCN-3 set. The elements listed under the properties are the fields of the set. The fields are optional except the ones are present on the required list.
Example:
components:
schemas:
Property:
type: object
required:
- name
properties:
name:
type: string
required:
type: boolean
regex:
type: string
value:
type: string
The TTCN-3 type definitions
type set Property {
charstring name,
boolean required optional,
charstring regex optional,
charstring value_ optional
} with {
variant (value_) "name as 'value'"
}
Please note as the value is a keyword in TTCN-3, it can't be used as field name.
Dictionaries, HashMaps and Associative Arrays
In OpenApi to define a dictionary, use type: object and use the additionalProperties keyword to specify the type of values in key/value pairs. The OpenAPI dictionary type is mapped to TTCN-3 set of record.
Example:
components:
schemas:
DictT:
type: object
additionalProperties:
type: string
The TTCN-3 type definitions
type set of record {
universal charstring key,
charstring additionalProperties optional
} DictT
with {
variant "as map"
}
Please note dictionary with a fixed keys are not supported. It should be handled as normal dictionary.
oneOf
The OpenAPI oneOf is mapped to TTCN-3 union. The union members are the alternative schemas. Because the union field names are not used during the encoding, they can be named freely.
Example:
components:
schemas:
OneOfT:
oneOf:
- integer
- boolean
The TTCN-3 type definitions
type union OneOfT {
integer field1,
boolean field2
} with {
variant "JSON: as value"
}
allOf
The OpenAPI allOf is mapped to TTCN-3 set. The mapping is the same as the mapping of object, just the list of the properties are merged.
anyOf
The OpenAPI anyOf is mapped to TTCN-3 set. The mapping is the same as the mapping of object, just the list of the properties are merged. Please note this mapping can't validate the received data correctly.
nullable
The nullable properties modifies the mapping of the schema. The schema is mapped to special TTCN-3 union. The type of the schema is mapped to one of the union member. The other member of the union represents the null value.
Example:
components:
schemas:
NidRm:
type: string
nullable: true
The TTCN-3 type definitions
type union NidRm {
JSON_generic_val.JSON_null_val null_val,
charstring val
} with {
variant "JSON: as value"
}
discriminator
The mapping of the discriminator is not supported.