@loopback/docs
Version:
Documentation files rendered at [https://loopback.io](https://loopback.io)
39 lines (24 loc) • 1.66 kB
Markdown
---
lang: en
title: 'API docs: rest.restserver.getapispec'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/rest
permalink: /doc/en/lb4/apidocs.rest.restserver.getapispec.html
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@loopback/rest](./rest.md) > [RestServer](./rest.restserver.md) > [getApiSpec](./rest.restserver.getapispec.md)
## 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`
<b>Signature:</b>
```typescript
getApiSpec(requestContext?: RequestContext): Promise<OpenApiSpec>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| requestContext | [RequestContext](./rest.requestcontext.md) | Optional context to update the <code>servers</code> list in the returned spec |
<b>Returns:</b>
Promise<[OpenApiSpec](./openapi-v3.openapispec.md)<!-- -->>