From f9bfc03bb58158e02cfb7234d5b8017a1dcaccbc Mon Sep 17 00:00:00 2001 From: Mauri Edo Date: Wed, 10 Oct 2018 05:36:46 +1100 Subject: [PATCH] swagger-schema-official: add support for references in parameters and responses (#29532) * add support for references in parameters and responses * update definitions by section * expand scope to schema references --- types/swagger-schema-official/index.d.ts | 27 +++++---- .../swagger-schema-official-tests.ts | 58 +++++++++++++++++++ 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/types/swagger-schema-official/index.d.ts b/types/swagger-schema-official/index.d.ts index 190e1ead7d..4722973cfb 100644 --- a/types/swagger-schema-official/index.d.ts +++ b/types/swagger-schema-official/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for swagger-schema-official 2.0 // Project: http://swagger.io/specification/ -// Definitions by: Mohsen Azimi , Ben Southgate , Nicholas Merritt +// Definitions by: Mohsen Azimi , Ben Southgate , Nicholas Merritt , Mauri Edo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export interface Info { @@ -47,7 +47,7 @@ export interface BaseParameter { } export interface BodyParameter extends BaseParameter { - schema?: Schema; + schema?: Referenceable; } export interface QueryParameter extends BaseParameter, BaseSchema { @@ -87,29 +87,32 @@ export interface Path { options?: Operation; head?: Operation; patch?: Operation; - parameters?: Parameter[]; + parameters?: Array>; } // ----------------------------- Operation ----------------------------------- export interface Operation { - responses: { [responseName: string]: Response }; + responses: { [responseName: string]: Referenceable}; summary?: string; description?: string; externalDocs?: ExternalDocs; operationId?: string; produces?: string[]; consumes?: string[]; - parameters?: Parameter[]; + parameters?: Array>; schemes?: string[]; deprecated?: boolean; security?: Security[]; tags?: string[]; } +// ----------------------------- Reference ----------------------------------- +export type Referenceable = { $ref: string; } | T; + // ----------------------------- Response ------------------------------------ export interface Response { description: string; - schema?: Schema; + schema?: Referenceable; headers?: { [headerName: string]: Header }; examples?: { [exampleName: string]: {} }; } @@ -135,14 +138,14 @@ export interface BaseSchema { minProperties?: number; enum?: Array; type?: string; - items?: Schema|Schema[]; + items?: Referenceable|Array>; } export interface Schema extends BaseSchema { $ref?: string; - allOf?: Schema[]; - additionalProperties?: Schema; - properties?: {[propertyName: string]: Schema}; + allOf?: Array>; + additionalProperties?: Referenceable; + properties?: {[propertyName: string]: Referenceable}; discriminator?: string; readOnly?: boolean; xml?: XML; @@ -221,8 +224,8 @@ export interface Spec { schemes?: string[]; consumes?: string[]; produces?: string[]; - paths: {[pathName: string]: Path}; - definitions?: {[definitionsName: string]: Schema }; + paths: {[pathName: string]: Referenceable}; + definitions?: {[definitionsName: string]: Referenceable }; parameters?: {[parameterName: string]: BodyParameter|QueryParameter}; responses?: {[responseName: string]: Response }; security?: Array<{[securityDefinitionName: string]: string[]}>; diff --git a/types/swagger-schema-official/swagger-schema-official-tests.ts b/types/swagger-schema-official/swagger-schema-official-tests.ts index dd8b1a4485..b336380320 100644 --- a/types/swagger-schema-official/swagger-schema-official-tests.ts +++ b/types/swagger-schema-official/swagger-schema-official-tests.ts @@ -1335,3 +1335,61 @@ const basic_auth: swagger.Spec = { }, "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"} + ], + "responses": { + "200": { + "$ref": "#/responses/sampleResponse" + }, + "404": { + "description": "A sample response with a Schema reference.", + "schema": { + "$ref": "stringSchema" + } + } + } + }, + "parameters": [ + {"$ref": "#/parameters/pathParameter"} + ] + } + }, + "responses": { + "sampleResponse" : { + "description": "A sample response.", + "schema": { + "type": "string" + } + } + } +};