Skip to main content

Class: Swagger

Swagger is a representation of OpenAPI v2 specification's Swagger object.

See: https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#swaggerObject

Example:

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: { title: "Echo API"; version: "1.0"; description: ""; contact: { name: "gRPC-Gateway project"; url: "https://github.com/grpc-ecosystem/grpc-gateway"; email: "none@example.com"; }; license: { name: "BSD 3-Clause License"; url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/main/LICENSE"; }; }; schemes: HTTPS; consumes: "application/json"; produces: "application/json"; };

Properties​

basePath​

basePath: string

The base path on which the API is served, which is relative to the host. If it is not included, the API is served directly under the host. The value MUST start with a leading slash (/). The basePath does not support path templating. Note that using base_path does not change the endpoint paths that are generated in the resulting OpenAPI file. If you wish to use base_path with relatively generated OpenAPI paths, the base_path prefix must be manually removed from your google.api.http paths and your code changed to serve the API from the base_path.


consumes​

consumes: string[]

A list of MIME types the APIs can consume. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types.


extensions​

extensions: object

Custom properties that start with "x-" such as "x-foo" used to describe extra functionality that is not covered by the standard OpenAPI Specification. See: https://swagger.io/docs/specification/2-0/swagger-extensions/

Index Signature​

[k: string]: $Properties


externalDocs?​

optional externalDocs?: $Properties | null

Additional external documentation.


host​

host: string

The host (name or ip) serving the API. This MUST be the host only and does not include the scheme nor sub-paths. It MAY include a port. If the host is not included, the host serving the documentation is to be used (including the port). The host does not support path templating.


info?​

optional info?: $Properties | null

Provides metadata about the API. The metadata can be used by the clients if needed.


produces​

produces: string[]

A list of MIME types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types.


responses​

responses: object

An object to hold responses that can be used across operations. This property does not define global responses for all operations.

Index Signature​

[k: string]: $Properties


schemes​

schemes: Scheme[]

The transfer protocol of the API. Values MUST be from the list: "http", "https", "ws", "wss". If the schemes is not included, the default scheme to be used is the one used to access the OpenAPI definition itself.


security​

security: $Properties[]

A declaration of which security schemes are applied for the API as a whole. The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). Individual operations can override this definition.


securityDefinitions?​

optional securityDefinitions?: $Properties | null

Security scheme definitions that can be used across the specification.


swagger​

swagger: string

Specifies the OpenAPI Specification version being used. It can be used by the OpenAPI UI and other clients to interpret the API listing. The value MUST be "2.0".


tags​

tags: $Properties[]

A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.

Methods​

toJSON()​

toJSON(): object

Converts this Swagger to JSON.

Returns​

object

JSON object


create()​

Call Signature​

static create(properties?): Swagger & $Shape

Creates a new Swagger instance using the specified properties.

Parameters​
properties?​

$Shape

Properties to set

Returns​

Swagger & $Shape

Swagger instance

Call Signature​

static create(properties?): Swagger

Creates a new Swagger instance using the specified properties.

Parameters​
properties?​

$Properties

Properties to set

Returns​

Swagger

Swagger instance


decode()​

static decode(reader, length?): Swagger & $Shape

Decodes a Swagger message from the specified reader or buffer.

Parameters​

reader​

Uint8Array<ArrayBufferLike> | Reader

Reader or buffer to decode from

length?​

number

Message length if known beforehand

Returns​

Swagger & $Shape

Swagger

Throws​

If the payload is not a reader or valid buffer

Throws​

If required fields are missing


decodeDelimited()​

static decodeDelimited(reader): Swagger & $Shape

Decodes a Swagger message from the specified reader or buffer, length delimited.

Parameters​

reader​

Uint8Array<ArrayBufferLike> | Reader

Reader or buffer to decode from

Returns​

Swagger & $Shape

Swagger

Throws​

If the payload is not a reader or valid buffer

Throws​

If required fields are missing


encode()​

static encode(message, writer?): Writer

Encodes the specified Swagger message. Does not implicitly grpc.gateway.protoc_gen_openapiv2.options.Swagger.verify|verify messages.

Parameters​

message​

$Properties

Swagger message or plain object to encode

writer?​

Writer

Writer to encode to

Returns​

Writer

Writer


encodeDelimited()​

static encodeDelimited(message, writer?): Writer

Encodes the specified Swagger message, length delimited. Does not implicitly grpc.gateway.protoc_gen_openapiv2.options.Swagger.verify|verify messages.

Parameters​

message​

$Properties

Swagger message or plain object to encode

writer?​

Writer

Writer to encode to

Returns​

Writer

Writer


fromObject()​

static fromObject(object): Swagger

Creates a Swagger message from a plain object. Also converts values to their respective internal types.

Parameters​

object​

{[k: string]: any; }

Plain object

Returns​

Swagger

Swagger


toObject()​

static toObject(message, options?): object

Creates a plain object from a Swagger message. Also converts values to other types if specified.

Parameters​

message​

Swagger

Swagger

options?​

IConversionOptions

Conversion options

Returns​

object

Plain object