diff --git a/types/swagger-schema-official/index.d.ts b/types/swagger-schema-official/index.d.ts index d2a8b0da14..262e469599 100644 --- a/types/swagger-schema-official/index.d.ts +++ b/types/swagger-schema-official/index.d.ts @@ -2,6 +2,7 @@ // Project: https://swagger.io/specification/ // Definitions by: Mohsen Azimi , Ben Southgate , Nicholas Merritt , Mauri Edo , Vincenzo Chianese // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 export interface Info { title: string; @@ -35,56 +36,76 @@ export interface Tag { } export interface Header extends BaseSchema { - type: string; + type: ParameterType; } // ----------------------------- Parameter ----------------------------------- -export type ParameterType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'file'; +export type ParameterType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object'; -export interface BaseParameter { +export type BaseParameter = { name: string; in: 'body' | 'query' | 'path' | 'header' | 'formData' | 'body'; required?: boolean; description?: string; -} +}; -export interface BodyParameter extends BaseParameter { +export type BodyParameter = BaseParameter & { in: 'body'; schema?: Schema; -} +}; -export interface QueryParameter extends BaseParameter, BaseSchema { - in: 'query'; - type: ParameterType; - allowEmptyValue?: boolean; - collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'; -} +export type GenericFormat = { + type?: ParameterType; + format?: string; +}; -export interface PathParameter extends BaseParameter, BaseSchema { - in: 'path'; - type: ParameterType; - required: boolean; -} +export type IntegerFormat = { + type: 'integer'; + format?: 'int32' | 'int64'; +}; -export interface HeaderParameter extends BaseParameter, BaseSchema { - in: 'header'; - type: ParameterType; -} +export type NumberFormat = { + type: 'number'; + format?: 'float' | 'double'; +}; -export interface FormDataParameter extends BaseParameter, BaseSchema { - in: 'formData'; - type: ParameterType; - collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'; - allowEmptyValue?: boolean; -} +export type StringFormat = { + type: 'string'; + format?: '' | 'byte' | 'binary' | 'date' | 'date-time' | 'password'; +}; -export type Parameter = - BodyParameter | - FormDataParameter | - QueryParameter | - PathParameter | - HeaderParameter; +export type SchemaFormatConstraints = GenericFormat | IntegerFormat | NumberFormat | StringFormat; +export type BaseFormatContrainedParameter = BaseParameter & SchemaFormatConstraints; +export type ParameterCollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'; + +export type QueryParameter = BaseFormatContrainedParameter & + BaseSchema & { + in: 'query'; + allowEmptyValue?: boolean; + collectionFormat?: ParameterCollectionFormat; + }; + +export type PathParameter = BaseFormatContrainedParameter & + BaseSchema & { + in: 'path'; + required: true; + }; + +export type HeaderParameter = BaseFormatContrainedParameter & + BaseSchema & { + in: 'header'; + }; + +export type FormDataParameter = BaseFormatContrainedParameter & + BaseSchema & { + in: 'formData'; + type: ParameterType | 'file'; + allowEmptyValue?: boolean; + collectionFormat?: ParameterCollectionFormat; + }; + +export type Parameter = BodyParameter | FormDataParameter | QueryParameter | PathParameter | HeaderParameter; // ------------------------------- Path -------------------------------------- export interface Path { @@ -129,11 +150,12 @@ export interface Response { } // ------------------------------ Schema ------------------------------------- -export interface BaseSchema { +export type BaseSchema = { + type?: ParameterType; format?: string; title?: string; description?: string; - default?: string | boolean | number | {}; + default?: any; multipleOf?: number; maximum?: number; exclusiveMaximum?: boolean; @@ -147,10 +169,9 @@ export interface BaseSchema { uniqueItems?: boolean; maxProperties?: number; minProperties?: number; - enum?: Array; - type?: string; + enum?: any[]; items?: Schema | Schema[]; -} +}; export interface Schema extends BaseSchema { $ref?: string; @@ -225,12 +246,12 @@ export interface OAuthScope { } export type Security = - BasicAuthenticationSecurity | - OAuth2AccessCodeSecurity | - OAuth2ApplicationSecurity | - OAuth2ImplicitSecurity | - OAuth2PasswordSecurity | - ApiKeySecurity; + | BasicAuthenticationSecurity + | OAuth2AccessCodeSecurity + | OAuth2ApplicationSecurity + | OAuth2ImplicitSecurity + | OAuth2PasswordSecurity + | ApiKeySecurity; // --------------------------------- Spec ------------------------------------ export interface Spec { diff --git a/types/swagger-schema-official/swagger-schema-official-tests.ts b/types/swagger-schema-official/swagger-schema-official-tests.ts index 4d46e4aa86..0b8f037e97 100644 --- a/types/swagger-schema-official/swagger-schema-official-tests.ts +++ b/types/swagger-schema-official/swagger-schema-official-tests.ts @@ -1329,7 +1329,7 @@ const uber: swagger.Spec = { const basic_auth: swagger.Spec = { "swagger": "2.0", - "info": { "version": "1.0.0", "title": "Minimal example with basic auth"}, + "info": { "version": "1.0.0", "title": "Minimal example with basic auth" }, "schemes": [ "https" ], @@ -1337,74 +1337,74 @@ const basic_auth: swagger.Spec = { "securityDefinitions": { basicAuth: { type: 'basic' }, }, - "security": [{basicAuth: []}] + "security": [{ basicAuth: [] }] }; const reference_support: swagger.Spec = { - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "Swagger Petstore" - }, - "definitions": { - "stringSchema": { - "type": "string" - } - }, - "parameters": { - "operationParameter": { - "in": "query", - "name": "operationParameter", - "type": "integer", - "description": "A sample operation parameter" - }, - "pathParameter": { - "in": "query", - "name": "pathParameter", - "type": "string", - "description": "A sample path parameter" - } - }, - "paths": { - "/path": { - "get": { - "parameters": [ - {"$ref": "#/parameters/operationParameter"}, - { - "in": "body", - "name": "bodyParameter", - "description": "The body parameter" - } - ], - "responses": { - "200": { - "$ref": "#/responses/sampleResponse" - }, - "404": { - "description": "A sample response with a Schema reference.", - "schema": { - "$ref": "stringSchema" - } - } - } - }, - "parameters": [ - {"$ref": "#/parameters/pathParameter"}, - { - "in": "query", - "name": "queryParameter", - "type": "string", - "description": "Another query parameter" - } - ] - } - }, - "responses": { - "sampleResponse" : { - "description": "A sample response.", - "schema": { - "type": "string" - } - } + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore" + }, + "definitions": { + "stringSchema": { + "type": "string" } + }, + "parameters": { + "operationParameter": { + "in": "query", + "name": "operationParameter", + "type": "integer", + "description": "A sample operation parameter" + }, + "pathParameter": { + "in": "query", + "name": "pathParameter", + "type": "string", + "description": "A sample path parameter" + } + }, + "paths": { + "/path": { + "get": { + "parameters": [ + { "$ref": "#/parameters/operationParameter" }, + { + "in": "body", + "name": "bodyParameter", + "description": "The body parameter" + } + ], + "responses": { + "200": { + "$ref": "#/responses/sampleResponse" + }, + "404": { + "description": "A sample response with a Schema reference.", + "schema": { + "$ref": "stringSchema" + } + } + } + }, + "parameters": [ + { "$ref": "#/parameters/pathParameter" }, + { + "in": "query", + "name": "queryParameter", + "type": "string", + "description": "Another query parameter" + } + ] + } + }, + "responses": { + "sampleResponse": { + "description": "A sample response.", + "schema": { + "type": "string" + } + } + } }; diff --git a/types/swagger-schema-official/tslint.json b/types/swagger-schema-official/tslint.json index 4de1adc227..9673949f8e 100644 --- a/types/swagger-schema-official/tslint.json +++ b/types/swagger-schema-official/tslint.json @@ -2,6 +2,7 @@ "extends": "dtslint/dt.json", "rules": { "max-line-length": false, - "object-literal-key-quotes": false + "object-literal-key-quotes": false, + "interface-over-type-literal": false } }