---
lang: en
title: 'API docs: rest.restserver.exportopenapispec'
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.exportopenapispec.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; [exportOpenApiSpec](./rest.restserver.exportopenapispec.md)

## RestServer.exportOpenApiSpec() method

Export the OpenAPI spec to the given json or yaml file

**Signature:**

```typescript
exportOpenApiSpec(outFile?: string, log?: (message?: any, ...optionalParams: any[]) => void): Promise<void>;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td markdown="1">

outFile


</td><td markdown="1">

string


</td><td markdown="1">

_(Optional)_ File name for the spec. The extension of the file determines the format of the file. - `yaml` or `yml`<!-- -->: YAML - `json` or other: JSON If the outFile is not provided or its value is `''` or `'-'`<!-- -->, the spec is written to the console using the `log` function.


</td></tr>
<tr><td markdown="1">

log


</td><td markdown="1">

(message?: any, ...optionalParams: any\[\]) =&gt; void


</td><td markdown="1">

_(Optional)_ Log function, default to `console.log`


</td></tr>
</tbody></table>

**Returns:**

Promise&lt;void&gt;


