Page Contents

Home > @loopback/rest > RestServer > getApiSpec

RestServer.getApiSpec() method

Get the OpenAPI specification describing the REST API provided by this application.

This method merges operations (HTTP endpoints) from the following sources: - app.api(spec) - app.controller(MyController) - app.route(route) - app.route('get', '/greet', operationSpec, MyController, 'greet')

If the optional requestContext is provided, then the servers list in the returned spec will be updated to work in that context. Specifically: 1. if config.openApi.setServersFromRequest is enabled, the servers list will be replaced with the context base url 2. Any servers entries with a path of / will have that path replaced with requestContext.basePath

Signature:

getApiSpec(requestContext?: RequestContext): Promise<OpenApiSpec>;

Parameters

Parameter Type Description
requestContext RequestContext (Optional) Optional context to update the servers list in the returned spec

Returns:

Promise<OpenApiSpec>