Skip to content

Commit

Permalink
fix(swagger): Remove decorators and refactoring @tsed/swagger module
Browse files Browse the repository at this point in the history
- Remove @BaseParameter
- Remove @consumes
- Remove @deprecated
- Remove @description
- Remove @example
- Remove @name
- Remove @operation
- Remove @produces
- Remove @Responses
- Remove @returns
- Remove @ReturnsArray
- Remove @Security
- Remove @summary
- Remove @title

BREAKING CHANGE: Use @tsed/schema and his decorators to generate your swagger API documentation.

- @BaseParameter have been removed. No replacement.
- Use @consumes from @tsed/schema
- Use @deprecated from @tsed/schema
- Use @description from @tsed/schema
- Use @example from @tsed/schema
- Use @name from @tsed/schema
- Use @operation
- Use @produces from @tsed/schema
- Use @Responses
- Use @returns from @tsed/schema
- @ReturnsArray have been removed. Use @returns from @tsed/schema.
- Use @Security from @tsed/schema
- Use @summary from @tsed/schema
- Use @title from @tsed/schema
  • Loading branch information
Romain Lenzotti committed Aug 17, 2020
1 parent df9af4b commit bb271a6
Show file tree
Hide file tree
Showing 35 changed files with 46 additions and 1,832 deletions.
2 changes: 1 addition & 1 deletion .nycrc
Expand Up @@ -27,6 +27,6 @@
"check-coverage": true,
"lines": 99.81,
"statements": 99.79,
"functions": 99.6,
"functions": 99.49,
"branches": 88.67
}
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -24,12 +24,12 @@ jobs:
script: yarn release
- stage: deploy-artifacts
name: 'Deploy github pages'
if: (NOT type IN (pull_request)) AND (branch = production)
script: monorepo ci configure && git fetch --quiet && git rebase origin/production && yarn docs:publish
if: (NOT type IN (pull_request)) AND (branch = production || branch = alpha)
script: monorepo ci configure && git fetch --quiet && git rebase origin/${TRAVIS_BRANCH} && yarn docs:publish
- stage: deploy-artifacts
name: 'Deploy examples'
if: (NOT type IN (pull_request)) AND (branch = production)
script: monorepo ci configure && git fetch --quiet && git rebase origin/production && yarn examples:publish
script: monorepo ci configure && git fetch --quiet && git rebase origin/${TRAVIS_BRANCH} && yarn examples:publish

stages:
- test
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorials/swagger.md
Expand Up @@ -38,10 +38,12 @@ Some options are available to configure Swagger-ui, Ts.ED and the default spec i
Key | Example | Description
---|---|---
path | `/api-doc` | The url subpath to access to the documentation.
fileName | `swagger.json` | Swagger file name. By default swagger.json.
doc | `hidden-doc` | The documentation key used by `@Docs` decorator to create several swagger documentations.
viewPath | `${rootDir}/../views/swagger.ejs` or `false` | The path to the ejs template. Set false to disabled swagger-ui.
cssPath | `${rootDir}/spec/style.css` | The path to the CSS file.
jsPath | `${rootDir}/spec/main.js` | The path to the JS file.
viewPath | `${rootDir}/views/swagger.ejs` | The path to the ejs file to create html page.
showExplorer | `true` | Display the search field in the navbar.
spec | `{swagger: "2.0"}` | The default information spec.
specPath | `${rootDir}/spec/swagger.base.json` | Load the base spec documentation from the specified path.
Expand Down
14 changes: 9 additions & 5 deletions packages/swagger/src/SwaggerModule.ts
@@ -1,11 +1,12 @@
import {BeforeRoutesInit, Configuration, InjectorService, Module, OnReady, PlatformApplication, redirectMiddleware} from "@tsed/common";
import {BeforeRoutesInit, Configuration, InjectorService, Module, OnReady, PlatformApplication} from "@tsed/common";
import * as Express from "express";
import * as Fs from "fs";
import {join} from "path";
import {SwaggerSettings} from "./interfaces";
import {cssMiddleware} from "./middlewares/cssMiddleware";
import {indexMiddleware} from "./middlewares/indexMiddleware";
import {jsMiddleware} from "./middlewares/jsMiddleware";
import {redirectMiddleware} from "./middlewares/redirectMiddleware";
import {SwaggerService} from "./services/SwaggerService";

const swaggerUiPath = require("swagger-ui-dist").absolutePath();
Expand All @@ -19,10 +20,13 @@ export class SwaggerModule implements BeforeRoutesInit, OnReady {
private swaggerService: SwaggerService,
@Configuration() private configuration: Configuration,
private platformApplication: PlatformApplication
) {}
) {
}

get settings() {
return ([] as SwaggerSettings[]).concat(this.configuration.get<SwaggerSettings[]>("swagger")).filter(o => !!o);
return ([] as SwaggerSettings[])
.concat(this.configuration.get<SwaggerSettings[]>("swagger"))
.filter(o => !!o);
}

/**
Expand All @@ -46,7 +50,7 @@ export class SwaggerModule implements BeforeRoutesInit, OnReady {
}

$onRoutesInit() {
this.settings.forEach(conf => {
this.settings.forEach((conf) => {
const {outFile} = conf;
const spec = this.swaggerService.getOpenAPISpec(conf);

Expand All @@ -60,7 +64,7 @@ export class SwaggerModule implements BeforeRoutesInit, OnReady {
const {httpsPort, httpPort} = this.configuration;

const displayLog = (host: any) => {
this.settings.forEach(conf => {
this.settings.forEach((conf) => {
const {path = "/", doc} = conf;
const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";

Expand Down
159 changes: 0 additions & 159 deletions packages/swagger/src/class/OpenApiModelSchemaBuilder.ts

This file was deleted.

0 comments on commit bb271a6

Please sign in to comment.