From fb95a990dd2aec60cdb8ec1623820d532ad7c128 Mon Sep 17 00:00:00 2001 From: Simon Nilius Date: Sat, 29 May 2021 16:52:20 +0200 Subject: [PATCH] fix(@nestjs/swagger) Change created document property order Ensure that the paths property comes before the components property, as this may lead to several strange display bugs in swagger-ui. See swagger-api/swagger-ui#5972 or https://github.com/swagger-api/swagger-ui/issues/3325#issuecomment-847733645 Closes nestjs/swagger#1369 --- e2e/api-spec.json | 494 +++++++++++++++++++++--------------------- lib/swagger-module.ts | 1 + 2 files changed, 248 insertions(+), 247 deletions(-) diff --git a/e2e/api-spec.json b/e2e/api-spec.json index 476c0dcbf..183a58389 100644 --- a/e2e/api-spec.json +++ b/e2e/api-spec.json @@ -1,251 +1,5 @@ { "openapi": "3.0.0", - "info": { - "title": "Cats example", - "description": "The cats API description", - "version": "1.0", - "contact": {} - }, - "tags": [ - { - "name": "cats", - "description": "" - } - ], - "servers": [], - "components": { - "securitySchemes": { - "basic": { - "type": "http", - "scheme": "basic" - }, - "bearer": { - "scheme": "bearer", - "bearerFormat": "JWT", - "type": "http" - }, - "oauth2": { - "type": "oauth2", - "flows": {} - }, - "api_key": { - "type": "apiKey", - "in": "header", - "name": "api_key" - }, - "key1": { - "type": "apiKey", - "in": "header", - "name": "key1" - }, - "key2": { - "type": "apiKey", - "in": "header", - "name": "key2" - }, - "cookie": { - "type": "apiKey", - "in": "cookie", - "name": "connect.sid" - } - }, - "schemas": { - "ExtraModel": { - "type": "object", - "properties": { - "one": { - "type": "string" - }, - "two": { - "type": "number" - } - }, - "required": [ - "one", - "two" - ] - }, - "LettersEnum": { - "type": "string", - "enum": [ - "A", - "B", - "C" - ] - }, - "TagDto": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "name" - } - }, - "required": [ - "name" - ] - }, - "CreateCatDto": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "age": { - "type": "number", - "minimum": 1, - "maximum": 200 - }, - "_breed": { - "type": "string" - }, - "tags": { - "type": "array", - "items": { - "type": "string", - "format": "uri" - } - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "urls": { - "type": "array", - "items": { - "type": "string" - } - }, - "options": { - "type": "array", - "items": { - "type": "object", - "properties": { - "isReadonly": { - "type": "string" - } - } - } - }, - "enum": { - "$ref": "#/components/schemas/LettersEnum" - }, - "enumArr": { - "type": "array", - "items": { - "$ref": "#/components/schemas/LettersEnum" - } - }, - "tag": { - "description": "tag", - "allOf": [ - { - "$ref": "#/components/schemas/TagDto" - } - ] - } - }, - "required": [ - "name", - "age", - "_breed", - "tags", - "createdAt", - "urls", - "options", - "enum", - "enumArr" - ] - }, - "Cat": { - "type": "object", - "properties": { - "name": { - "type": "string", - "example": "Kitty", - "description": "The name of the Cat" - }, - "age": { - "type": "number", - "example": 1, - "minimum": 0, - "description": "The age of the Cat" - }, - "breed": { - "type": "string", - "example": "Maine Coon", - "description": "The breed of the Cat" - }, - "_tags": { - "type": "array", - "items": { - "type": "string" - } - }, - "createdAt": { - "format": "date-time", - "type": "string" - }, - "urls": { - "type": "array", - "items": { - "type": "string" - } - }, - "_options": { - "type": "array", - "items": { - "type": "object", - "properties": { - "isReadonly": { - "type": "string" - } - } - } - }, - "enum": { - "type": "string", - "enum": [ - "A", - "B", - "C" - ] - }, - "enumArr": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "A", - "B", - "C" - ] - } - } - }, - "required": [ - "name", - "age", - "breed", - "_tags", - "createdAt", - "urls", - "_options", - "enum", - "enumArr" - ] - } - } - }, - "security": [ - { - "bearer": [] - }, - { - "basic": [], - "cookie": [] - } - ], "paths": { "/api/cats": { "post": { @@ -762,5 +516,251 @@ ] } } - } + }, + "info": { + "title": "Cats example", + "description": "The cats API description", + "version": "1.0", + "contact": {} + }, + "tags": [ + { + "name": "cats", + "description": "" + } + ], + "servers": [], + "components": { + "securitySchemes": { + "basic": { + "type": "http", + "scheme": "basic" + }, + "bearer": { + "scheme": "bearer", + "bearerFormat": "JWT", + "type": "http" + }, + "oauth2": { + "type": "oauth2", + "flows": {} + }, + "api_key": { + "type": "apiKey", + "in": "header", + "name": "api_key" + }, + "key1": { + "type": "apiKey", + "in": "header", + "name": "key1" + }, + "key2": { + "type": "apiKey", + "in": "header", + "name": "key2" + }, + "cookie": { + "type": "apiKey", + "in": "cookie", + "name": "connect.sid" + } + }, + "schemas": { + "ExtraModel": { + "type": "object", + "properties": { + "one": { + "type": "string" + }, + "two": { + "type": "number" + } + }, + "required": [ + "one", + "two" + ] + }, + "LettersEnum": { + "type": "string", + "enum": [ + "A", + "B", + "C" + ] + }, + "TagDto": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "name" + } + }, + "required": [ + "name" + ] + }, + "CreateCatDto": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "age": { + "type": "number", + "minimum": 1, + "maximum": 200 + }, + "_breed": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + } + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "urls": { + "type": "array", + "items": { + "type": "string" + } + }, + "options": { + "type": "array", + "items": { + "type": "object", + "properties": { + "isReadonly": { + "type": "string" + } + } + } + }, + "enum": { + "$ref": "#/components/schemas/LettersEnum" + }, + "enumArr": { + "type": "array", + "items": { + "$ref": "#/components/schemas/LettersEnum" + } + }, + "tag": { + "description": "tag", + "allOf": [ + { + "$ref": "#/components/schemas/TagDto" + } + ] + } + }, + "required": [ + "name", + "age", + "_breed", + "tags", + "createdAt", + "urls", + "options", + "enum", + "enumArr" + ] + }, + "Cat": { + "type": "object", + "properties": { + "name": { + "type": "string", + "example": "Kitty", + "description": "The name of the Cat" + }, + "age": { + "type": "number", + "example": 1, + "minimum": 0, + "description": "The age of the Cat" + }, + "breed": { + "type": "string", + "example": "Maine Coon", + "description": "The breed of the Cat" + }, + "_tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "createdAt": { + "format": "date-time", + "type": "string" + }, + "urls": { + "type": "array", + "items": { + "type": "string" + } + }, + "_options": { + "type": "array", + "items": { + "type": "object", + "properties": { + "isReadonly": { + "type": "string" + } + } + } + }, + "enum": { + "type": "string", + "enum": [ + "A", + "B", + "C" + ] + }, + "enumArr": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "A", + "B", + "C" + ] + } + } + }, + "required": [ + "name", + "age", + "breed", + "_tags", + "createdAt", + "urls", + "_options", + "enum", + "enumArr" + ] + } + } + }, + "security": [ + { + "bearer": [] + }, + { + "basic": [], + "cookie": [] + } + ] } \ No newline at end of file diff --git a/lib/swagger-module.ts b/lib/swagger-module.ts index 89fd3ddc6..7700cbabc 100644 --- a/lib/swagger-module.ts +++ b/lib/swagger-module.ts @@ -22,6 +22,7 @@ export class SwaggerModule { }; return { openapi: '3.0.0', + paths: {}, ...config, ...document };