Tsoa: Support custom swagger definition parts

Created on 19 Sep 2016  路  2Comments  路  Source: lukeautry/tsoa

It is possible to add the possibility to define a custom swagger.json-skeleton which is used in swagger/specGenerator.ts, possibly like this:

  public GetSpec() {
    const customSpec = require('path-to-spec-file');
    const spec: Swagger.Spec = Object.assign(customSpec, {
      basePath: this.options.basePath,
      consumes: ['application/json'],
      definitions: this.buildDefinitions(),
      host: this.options.host,
      info: {
        description: this.options.description,
        license: {
          name: this.options.license
        },
        title: this.options.name,
        version: this.options.version
      },
      paths: this.buildPaths(),
      produces: ['application/json'],
      swagger: '2.0'
    });

    if (this.options.host) { spec.host = this.options.host; }

    return spec;
  }

Or what is your suggested way to add for example security information?

enhancement

Most helpful comment

If something is part of the spec, then we should make it possible to define via configuration. This should be quite easy to do with a combination of changes in cli.ts and specGenerator.ts. A template is potentially an option, but if we can simply extend the CLI to include supported spec properties, that's my preference.

That said, looking at the example from the docs, the security portion of the spec can include quite a lot:

{
  "api_key": {
    "type": "apiKey",
    "name": "api_key",
    "in": "header"
  },
  "petstore_auth": {
    "type": "oauth2",
    "authorizationUrl": "http://swagger.io/api/oauth/dialog",
    "flow": "implicit",
    "scopes": {
      "write:pets": "modify pets in your account",
      "read:pets": "read your pets"
    }
  }
}

Passing all of that in via the CLI would be pretty gross. How would you feel about a tsoa.json configuration file allowing the customizable portions of the spec to be defined, allowing usage like this?

tsoa swagger --config=tsoa.json

All 2 comments

If something is part of the spec, then we should make it possible to define via configuration. This should be quite easy to do with a combination of changes in cli.ts and specGenerator.ts. A template is potentially an option, but if we can simply extend the CLI to include supported spec properties, that's my preference.

That said, looking at the example from the docs, the security portion of the spec can include quite a lot:

{
  "api_key": {
    "type": "apiKey",
    "name": "api_key",
    "in": "header"
  },
  "petstore_auth": {
    "type": "oauth2",
    "authorizationUrl": "http://swagger.io/api/oauth/dialog",
    "flow": "implicit",
    "scopes": {
      "write:pets": "modify pets in your account",
      "read:pets": "read your pets"
    }
  }
}

Passing all of that in via the CLI would be pretty gross. How would you feel about a tsoa.json configuration file allowing the customizable portions of the spec to be defined, allowing usage like this?

tsoa swagger --config=tsoa.json

@andreasrueedlinger This has been implemented in the latest release (1.0.0). Note that this was a breaking change for the CLI.

Please check out the updated section of the readme for more information: https://github.com/lukeautry/tsoa#command-line-interface

Let me know if you run into any problems or have any questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Izabrr picture Izabrr  路  4Comments

eluft84 picture eluft84  路  6Comments

jakubzloczewski picture jakubzloczewski  路  6Comments

jeremyVignelles picture jeremyVignelles  路  3Comments

cedricboidin picture cedricboidin  路  5Comments