---
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) &gt; [@loopback/rest](./rest.md) &gt; [RestServer](./rest.restserver.md) &gt; [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`

**Signature:**

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

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

requestContext


</td><td>

[RequestContext](./rest.requestcontext.md)


</td><td>

_(Optional)_ Optional context to update the `servers` list in the returned spec


</td></tr>
</tbody></table>

**Returns:**

Promise&lt;[OpenApiSpec](./openapi-v3.openapispec.md)<!-- -->&gt;


