---
lang: en
title: 'API docs: rest.restserver.getapispec'
keywords: LoopBack 4.0, LoopBack 4
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/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`

<b>Signature:</b>

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

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  requestContext | <code>RequestContext</code> | Optional context to update the <code>servers</code> list in the returned spec |

<b>Returns:</b>

`Promise<OpenApiSpec>`


