typespec icon indicating copy to clipboard operation
typespec copied to clipboard

Provide a decorator or other means to specify OpenAPI tag properties

Open mikekistler opened this issue 2 years ago • 5 comments

OpenAPI v2 and v3 support a global "tags" property that associates additional properties -- a description and link to external docs -- with a tag name.

https://github.com/OAI/OpenAPI-Specification/blob/3.0.3/versions/3.0.3.md#tag-object

Many popular doc generators will display the information in these properties in the generated docs.

image

TypeSpec should provide a means to populate these properties for any tags used in the API definition.

mikekistler avatar Jul 28 '23 16:07 mikekistler

How should we augment the tags decorator to allow additional metadata?

markcowl avatar Jul 31 '23 18:07 markcowl

Is there a plan to implement this soon?

decarufe avatar Jan 30 '24 14:01 decarufe

Proposal: add a new decorator to the OpenAPI library called tagMetadata. It MUST be applied to the service namespace, it is an error if it is applied to any other type. Multiple applications of tagMetadata merge like tag. The decorator takes a tag name and a model of additional properties, so for example:

@service
@tagMetadata("pet", { description: "Pets operations", externalDocs: { url: "https://example.com", description: "More info." } });
namespace PetStore;

We know we want to disambiguate data values from types via #{ ... } syntax, however OpenAPI is already rife with this ambiguity (e.g. with @extension and @info), so there doesn't seem to be much harm in continuing this trend for now.

bterlson avatar Feb 08 '24 22:02 bterlson

I assume multiple instances will merge?

johanste avatar Feb 08 '24 23:02 johanste

Yes, like @tag. Updated.

bterlson avatar Feb 08 '24 23:02 bterlson