openapi-to-graphql-lxwang2
Version:
Generates a GraphQL schema for a given OpenAPI Specification (OAS)
262 lines (234 loc) • 6.08 kB
text/typescript
// Copyright IBM Corp. 2018. All Rights Reserved.
// Node module: openapi-to-graphql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
/**
* Type definitions for the OpenAPI Specification 3.
*/
type ExternalDocumentationObject = {
description?: string
url: string
}
export type SchemaObject = {
$ref?: string
title?: string
type?: 'string' | 'number' | 'object' | 'array' | 'boolean' | 'integer'
format?: string
nullable?: boolean
description?: string
properties?: {
[]: SchemaObject | ReferenceObject
}
required?: string[]
default?: any
additionalProperties?: SchemaObject | ReferenceObject
items?: SchemaObject | ReferenceObject // MUST be a single schema object in OAS, see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#properties
additionalItems?: boolean | string[]
enum?: string[]
allOf?: (SchemaObject | ReferenceObject)[]
anyOf?: (SchemaObject | ReferenceObject)[]
oneOf?: (SchemaObject | ReferenceObject)[]
not?: (SchemaObject | ReferenceObject)[]
}
export type ReferenceObject = {
$ref: string
}
type ExampleObject = {
summary?: string
description?: string
value?: any
externalValue?: string
}
type HeaderObject = {
name?: string
in?: 'query' | 'header' | 'path' | 'cookie'
description?: string
required?: boolean
deprecated?: boolean
allowEmptyValue?: boolean
}
type EncodingObject = {
contentType?: string
headers?: {
[]: HeaderObject | ReferenceObject
}
style?: string
explode?: boolean
allowReserved?: boolean
}
export type MediaTypeObject = {
schema?: SchemaObject | ReferenceObject
example?: any
examples?: {
[]: ExampleObject | ReferenceObject
}
encoding?: {
[]: EncodingObject
}
}
export type ParameterObject = {
name: string
in: 'query' | 'header' | 'path' | 'cookie'
description?: string
required?: boolean
deprecated?: boolean
allowEmptyValue?: boolean
style?: 'form' | 'simple'
explode?: boolean
allowReserved?: boolean
schema?: SchemaObject | ReferenceObject
example?: any
examples?: {
[]: ExampleObject | ReferenceObject
}
content?: {
[]: MediaTypeObject
}
}
export type MediaTypesObject = {
[]: MediaTypeObject
}
export type ServerObject = {
url: string
description?: string
variables?: object // TODO: extend
}
export type RequestBodyObject = {
description?: string
content: {
[]: MediaTypeObject
}
required?: boolean
}
export type LinkObject = {
operationRef?: string
operationId?: string
parameters?: {
[]: any
}
requestBody?: any
description?: string
server?: ServerObject
}
export type LinksObject = {
[]: LinkObject | ReferenceObject
}
export type ResponseObject = {
description: string
headers?: {
[]: HeaderObject | ReferenceObject
}
content?: MediaTypesObject
links?: LinksObject
}
export type ResponsesObject = {
[]: ResponseObject | ReferenceObject
}
export type SecurityRequirementObject = {
[]: string[]
}
export type OperationObject = {
tags?: string[]
summary?: string
description?: string
externalDocs?: ExternalDocumentationObject
operationId?: string
parameters?: Array<ParameterObject | ReferenceObject>
requestBody?: RequestBodyObject | ReferenceObject
responses?: ResponsesObject
callbacks?: any // TODO: extend?
deprecated?: boolean
security?: SecurityRequirementObject[]
servers?: ServerObject[]
}
export type PathItemObject = {
$ref?: string
summary?: string
description: string
[]: any
servers?: ServerObject[]
parameters?: [ParameterObject | ReferenceObject]
}
type PathsObject = {
[]: PathItemObject
}
type OAuthFlowObject = {
authorizationUrl?: string // Optional, beacause applies only to certain flows
tokenUrl?: string // Optional, beacause applies only to certain flows
refreshUrl?: string // Optional, beacause applies only to certain flows
scopes?: {
// Optional, beacause applies only to certain flows
[]: string
}
}
type OAuthFlowsObject = {
implicit?: OAuthFlowObject
password?: OAuthFlowObject
clientCredentials?: OAuthFlowObject
authorizationCode?: OAuthFlowObject
}
export type SecuritySchemeObject = {
type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect'
description?: string
name?: string // Optional, because applies only to apiKey
in?: string // Optional, because applies only to apiKey
scheme?: string // Optional, because applies only to http
bearerFormat?: string
flows?: OAuthFlowsObject // Optional, because applies only to oauth2
openIdConnectUrl?: string // // Optional, because applies only to openIdConnect
}
export type SecuritySchemesObject = {
[]: SecuritySchemeObject | ReferenceObject
}
type ComponentsObject = {
schemas?: {
[]: SchemaObject | ReferenceObject
}
responses?: ResponsesObject
parameters?: {
[]: ParameterObject | ReferenceObject
}
examples?: {
[]: ExampleObject | ReferenceObject
}
requestBodies?: {
[]: RequestBodyObject | ReferenceObject
}
headers?: {
[]: HeaderObject | ReferenceObject
}
securitySchemes?: SecuritySchemesObject
links?: LinksObject
callbacks?: {
[]: object | ReferenceObject
}
}
type TagObject = {
name: string
description?: string
externalDocs?: ExternalDocumentationObject
}
export type Oas3 = {
openapi: string
info: {
title: string
description?: string
termsOfService?: string
contact?: {
name?: string
url?: string
email?: string
}
license?: {
name: string
url?: string
}
version: string
}
servers?: ServerObject[]
paths: PathsObject
components?: ComponentsObject
security?: SecurityRequirementObject[]
tags?: TagObject[]
externalDocs?: ExternalDocumentationObject
}