typescript-rest-swagger icon indicating copy to clipboard operation
typescript-rest-swagger copied to clipboard

Add description and externalDocs to @Tags decorator

Open alemmonteiro opened this issue 7 years ago • 3 comments

Hi, how can I add description and externalDocs to Tags?

I saw the Tag interface:

export interface Tag {
  name: string;
  description?: string;
  externalDocs?: ExternalDocs;
}

How can I use it?

Thanks

alemmonteiro avatar Apr 09 '18 20:04 alemmonteiro

You can use the spec property of swaggerconfig.json to define your tags, then use the @Tags decorator on your controllers and methods . Example swaggerconfig.json:

{
    "swagger": {
        "name": "My API",
        "version": "1.0.0",
        "description": "The best API ever",
        "spec": {
            "info": {
                "termsOfService": "http://example.com/",
                "contact": {
                    "email": "[email protected]"
                },
                "license": {
                    "name": "License Agreement",
                    "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
                }
            },
            "tags": [
                {
                    "name": "Person",
                    "description": "Description of Person tag",
                    "externalDocs": {
                        "description": "More info",
                        "url": "http://example.com/api-info/person"
                    }
                }
            ]
        }
    }
}

ngraef avatar Apr 10 '18 16:04 ngraef

@ngraef, I've tried change the swaggerConfig.json and didn't work, cause I've forgotten the spec and written the "tags" one level ahead. Thanks, it's working now.

Maybe it should be describe in README.md file. How to use @Tags decorator with description and externalDocs.

alemmonteiro avatar Apr 10 '18 17:04 alemmonteiro

Reopening to remind me to add this to the docs.

ngraef avatar Apr 11 '18 03:04 ngraef