Skip to content

Instantly share code, notes, and snippets.

@clounie
Created May 26, 2019 10:41
Show Gist options
  • Save clounie/06ab35d7cf3318b560b0648b93eaa75a to your computer and use it in GitHub Desktop.
Save clounie/06ab35d7cf3318b560b0648b93eaa75a to your computer and use it in GitHub Desktop.
OpenAPI 3.0.1 Spec, defined in YAML
# Validations to make:
# typeToClassMappings -
# * Must have no duplicates
# * All Java classes must exist
#
# types -
# * Must have no duplicates
# * Each type.name must exist as a key in typeToClassMappings
# * Each type.fields.*.type|mapKeyType|mapValueType must exist as a key in typeToClassMappings
# * Each type referenced in fields has one and only one definition somewhere else
#
# fields -
# * Must have either name [Fixed], or nameFormat [Patterned]
# * Must follow nameFormat if it exists
# * Must have type
# * Field name must follow `format` regex if it exists
version: 3.0.1
types:
-
name: OpenAPI
fields:
- {name: openapi, type: string, required: true}
- {name: info, type: Info, required: true}
- {name: servers, type: [Server]}
- {name: paths, type: Paths, required: true}
- {name: components, type: Components}
- {name: security, type: [SecurityRequirement]}
- {name: tags, type: [Tag]}
- {name: externalDocs, type: ExternalDocumentation}
-
name: Info
fields:
- {name: title, type: string, required: true}
- {name: description, type: string}
- {name: termsOfService, type: string}
- {name: contact, type: Contact}
- {name: license, type: License}
- {name: version, type: string, required: true}
-
name: Contact
fields:
- {name: name, type: string}
- {name: url, type: string}
- {name: email, type: string}
-
name: License
fields:
- {name: name, type: string, required: true}
- {name: url, type: string}
-
name: Server
fields:
- {name: url, type: string}
- {name: description, type: string}
- {name: variables, type: { key: string, val: ServerVariable}}
-
name: ServerVariable
fields:
- {name: enum, type: [string]}
- {name: default, type: string, required: true}
- {name: description, type: string, required: true}
-
name: Components
fields:
- {name: schemas, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Schema, refAllowed: true}}
- {name: responses, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Response, refAllowed: true}}
- {name: parameters, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Parameter, refAllowed: true}}
- {name: examples, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Example, refAllowed: true}}
- {name: requestBodies, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: RequestBody, refAllowed: true}}
- {name: headers, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Header, refAllowed: true}}
- {name: securitySchemes, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: SecurityScheme, refAllowed: true}}
- {name: links, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Link, refAllowed: true}}
- {name: callbacks, type: { key: string, keyFormat: '^[a-zA-Z0-9\.\-_]+$', val: Callback, refAllowed: true}}
-
name: Paths
fields:
- {nameFormat: '^\/.*$', type: PathItem}
-
name: PathItem
fields:
- {name: '$ref', type: string}
- {name: summary, type: string}
- {name: description, type: string}
- {name: get, type: Operation}
- {name: put, type: Operation}
- {name: post, type: Operation}
- {name: delete, type: Operation}
- {name: options, type: Operation}
- {name: head, type: Operation}
- {name: patch, type: Operation}
- {name: trace, type: Operation}
- {name: servers, type: [Server]}
- {name: parameters, type: [Parameter], refAllowed: true}
-
name: Operation
fields:
- {name: tags, type: [string]}
- {name: summary, type: string}
- {name: description, type: string}
- {name: externalDocs, type: ExternalDocumentation}
- {name: operationId, type: string}
- {name: parameters, type: [Parameter], refAllowed: true}
- {name: requestBody, type: RequestBody, refAllowed: true}
- {name: responses, type: Responses}
- {name: callbacks, type: {key: string, val: Callback, refAllowed: true}}
- {name: deprecated, type: boolean}
- {name: security, type: SecurityRequirement}
- {name: servers, type: [Server]}
-
name: ExternalDocumentation
fields:
- {name: description, type: string}
- {name: url, type: string, required: true}
-
# Note that Parameter has a LOT more detailed stuff that we haven't modeled here.
name: Parameter
fields:
- {name: name, type: string, required: true}
- {name: in, type: string, format: '^(query)|(header)|(path)|(coookie)$', required: true}
- {name: description, type: string}
- {name: required, type: boolean, required: true}
- {name: deprecated, type: boolean}
- {name: allowEmptyValue, type: boolean}
-
name: RequestBody
fields:
- {name: description, type: string}
- {name: content, type: {key: string, val: MediaType}, required: true}
- {name: required, type: boolean}
-
name: MediaType
fields:
- {name: schema, type: Schema, refAllowed: true}
- {name: example, type: any}
- {name: examples, type: { key: string, val: Example, refAllowed: true}}
- {name: encoding, type: { key: string, val: Encoding}}
-
name: Encoding
fields:
- {name: contentType, type: string}
- {name: headers, type: {key: string, val: Header, refAllowed: true}}
- {name: style, type: string}
- {name: explode, type: boolean}
- {name: allowReserved, type: boolean}
-
name: Responses
fields:
- {name: default, type: Response, refAllowed: true}
# TODO regex for HTTP codes in the response is too inclusive
- {nameFormat: '^[0-9]{1,3}$', type: Response, refAllowed: true}
-
name: Callback
fields:
# TODO regex is extremely inclusive
- {nameFormat: '^*+', type: PathItem}
-
name: Example
fields:
- {name: summary, type: string}
- {name: description, type: string}
- {name: value, type: any}
- {name: externalValue, type: string}
-
name: Link
fields:
- {name: operationRef, type: string}
- {name: operationId, type: string}
# TODO parameters and requestBody can also use type.val of {expression}
- {name: parameters, type: { key: string, val: any}}
- {name: requestBody, type: { key: string, val: any}}
- {name: description, type: string}
- {name: server, type: Server}
-
# Same as Parameter except that name && in MUST NOT be specified.
name: Header
fields:
- {name: description, type: string}
- {name: required, type: boolean, required: true}
- {name: deprecated, type: boolean}
- {name: allowEmptyValue, type: boolean}
-
name: Tag
fields:
- {name: name, type: string, required: true}
- {name: description, type: string}
- {name: externalDocs, type: ExternalDocumentation}
-
name: Reference
fields:
- {name: '$ref', type: string, required: true}
-
name: Schema
fields:
# Taken from JSON Schema definition without adaptation
- {name: title, type: string}
- {name: multipleOf, type: integer}
- {name: maximum, type: double}
- {name: exclusiveMaximum, type: double}
- {name: minimum, type: double}
- {name: exclusiveMinimum, type: double}
- {name: maxLength, type: integer}
- {name: minLength, type: integer}
- {name: pattern, type: string}
- {name: maxItems, type: integer}
- {name: minItems, type: integer}
- {name: uniqueItems, type: boolean}
- {name: maxProperties, type: integer}
- {name: minProperties, type: integer}
- {name: required, type: boolean}
- {name: enum, type: [any]}
# Adjusted from JSON Schema definition
- {name: type, type: string}
- {name: allOf, type: Schema}
- {name: oneOf, type: Schema}
- {name: anyOf, type: Schema}
- {name: not, type: Schema}
- {name: items, type: Schema}
- {name: properties, type: Schema}
- {name: additionalProperties, type: boolean|Schema}
- {name: description, type: string}
- {name: format, type: string, format: '^(integer)|(long)|(float)|(double)|(string)|(byte)|(binary)|(boolean)|(date)|(dateTime)|(password)$'}
- {name: default, type: any}
# Other fixed fields
- {name: nullable, type: boolean}
- {name: discriminator, type: Discriminator}
- {name: readOnly, type: boolean}
- {name: writeOnly, type: boolean}
- {name: xml, type: XML}
- {name: externalDocs, type: ExternalDocumentation}
- {name: example, type: any}
- {name: deprecated, type: boolean}
-
name: Discriminator
fields:
- {name: propertyName, type: string, required: true}
- {name: mapping, type: {key: string, val: string}}
-
name: XML
fields:
- {name: name, type: string}
- {name: namespace, type: string}
- {name: prefix, type: string}
- {name: attribute, type: boolean}
- {name: wrapped, type: boolean}
-
name: SecurityScheme
fields:
- {name: type, type: string, required: true}
- {name: description, type: string}
- {name: name, type: string, required: true}
- {name: in, type: string, required: true}
- {name: scheme, type: string, required: true}
- {name: bearerFormat, type: string}
- {name: flows, type: OAuthFlows, required: true}
- {name: openIdConnectUrl, type: string, required: true}
-
name: OAuthFlows
fields:
- {name: implicit, type: OAuthFlow}
- {name: password, type: OAuthFlow}
- {name: clientCredentials, type: OAuthFlow}
- {name: authorizationCode, type: OAuthFlow}
-
name: OAuthFlow
fields:
- {name: authorizationUrl, type: string}
- {name: tokenUrl, type: string}
- {name: refreshUrl, type: string}
- {name: scopes, type: { key: string, val: string}}
-
name: SecurityRequirements
fields:
# TODO really must be a value declared in Security Schemes under the Components object
- {nameFormat: '^.+$', type: [string]}
-
name: SpecificationExtensions
fields:
- {nameFormat: '^x-', type: any}
typeToClassMappings:
# Core Data Types
any: java.lang.Object
integer: java.lang.Integer
long: java.lang.Long
float: java.lang.Float
double: java.lang.Double
string: java.lang.String
byte: java.lang.Byte
binary: java.lang.String
boolean: java.lang.Boolean
date: java.lang.String
dateTime: java.lang.String
password: java.lang.String
# OpenAPI classes
Callback: io.swagger.v3.oas.models.callbacks.Callback
Components: io.swagger.v3.oas.models.Components
Contact: io.swagger.v3.oas.models.info.Contact
Discriminator: io.swagger.v3.oas.models.media.Discriminator
Encoding: io.swagger.v3.oas.models.media.Encoding
Example: io.swagger.v3.oas.models.examples.Example
ExternalDocumentation: io.swagger.v3.oas.models.ExternalDocumentation
Header: io.swagger.v3.oas.models.headers.Header
Info: io.swagger.v3.oas.models.info.Info
License: io.swagger.v3.oas.models.info.License
Link: io.swagger.v3.oas.models.links.Link
MediaType: io.swagger.v3.oas.models.media.MediaType
OAuthFlow: io.swagger.v3.oas.models.security.OAuthFlow
OAuthFlows: io.swagger.v3.oas.models.security.OAuthFlows
OpenAPI: io.swagger.v3.oas.models.OpenAPI
Operation: io.swagger.v3.oas.models.Operation
Parameter: io.swagger.v3.oas.models.parameters.Parameter
Paths: io.swagger.v3.oas.models.Paths
PathItem: io.swagger.v3.oas.models.PathItem
Reference: null # Doesn't exist in models
RequestBody: io.swagger.v3.oas.models.parameters.RequestBody
Response: io.swagger.v3.oas.models.responses.ApiResponse
Responses: io.swagger.v3.oas.models.responses.ApiResponses
Schema: io.swagger.v3.oas.models.media.Schema
SecurityRequirement: io.swagger.v3.oas.models.security.SecurityRequirement
SecurityScheme: io.swagger.v3.oas.models.security.SecurityScheme
Server: io.swagger.v3.oas.models.servers.Server
ServerVariable: io.swagger.v3.oas.models.servers.ServerVariable
Tag: io.swagger.v3.oas.models.tags.Tag
#integer integer int32 signed 32 bits
#long integer int64 signed 64 bits
#float number float
#double number double
#string string
#byte string byte base64 encoded characters
#binary string binary any sequence of octets
#boolean boolean
#date string date As defined by full-date - RFC3339
#dateTime string date-time As defined by date-time - RFC3339
#password string password A hint to UIs to obscure input.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment