Skip to content

Commit

Permalink
docs: extract "How to customize OpenAPI serving" into a guide
Browse files Browse the repository at this point in the history
Co-authored-by: Hage Yaapa <[email protected]>
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos and hacksparrow committed Jun 23, 2020
1 parent d2d9749 commit b7af48e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
34 changes: 0 additions & 34 deletions docs/site/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,6 @@ const app = new RestApplication({
});
```

### Customize How OpenAPI Spec is Served

There are a few options under `rest.openApiSpec` to configure how OpenAPI spec
is served by the given REST server.

- servers: Configure servers for OpenAPI spec
- setServersFromRequest: Set `servers` based on HTTP request headers, default to
`false`
- disabled: Set to `true` to disable endpoints for the OpenAPI spec. It will
disable API Explorer too.
- endpointMapping: Maps urls for various forms of the spec. Default to:

```js
{
'/openapi.json': {version: '3.0.0', format: 'json'},
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
}
```

```ts
const app = new RestApplication({
rest: {
openApiSpec: {
servers: [{url: 'http://127.0.0.1:8080'}],
setServersFromRequest: false,
endpointMapping: {
'/openapi.json': {version: '3.0.0', format: 'json'},
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
},
},
},
});
```

### Configure the API Explorer

LoopBack allows externally hosted API Explorer UI to render the OpenAPI
Expand Down
48 changes: 48 additions & 0 deletions docs/site/guides/rest/customize-openapi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
lang: en
title: 'Customizing how OpenAPI spec is served'
keywords: LoopBack 4.0, LoopBack 4, Node.js, OpenAPI, Customization
sidebar: lb4_sidebar
permalink: /doc/en/lb4/Customizing-how-openapi-spec-is-served.html
---

By default, LoopBack REST API server provides endpoints exposing an OpenAPI spec
document describing application's API. You can configure this behavior using
`rest.openApiSpec` field in the configuration object passed to `RestApplication`
constructor.

- servers: Configure servers for OpenAPI spec

- setServersFromRequest: Set `servers` based on HTTP request headers, default to
`false`

- disabled: Set to `true` to disable endpoints for the OpenAPI spec. It will
disable API Explorer too.

- endpointMapping: Maps urls for various forms of the spec. Default to:

```js
{
'/openapi.json': {version: '3.0.0', format: 'json'},
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
}
```

Example application configuration object showing possible customizations:

{% include code-caption.html content="/src/index.ts" %}

```ts
const config: ApplicationConfig = {
rest: {
openApiSpec: {
servers: [{url: 'http://127.0.0.1:8080'}],
setServersFromRequest: false,
endpointMapping: {
'/openapi.json': {version: '3.0.0', format: 'json'},
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
},
},
};
});
```
7 changes: 7 additions & 0 deletions docs/site/sidebars/lb4_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ children:
output: 'web, pdf'
children:

- title: 'Building REST APIs'
output: 'web, pdf'
children:
- title: 'Customizing how OpenAPI spec is served'
url: Customizing-how-openapi-spec-is-served.html
output: 'web, pdf'

- title: 'Create Other Forms of APIs'
url: Create-other-forms-of-apis.html
output: 'web, pdf'
Expand Down

0 comments on commit b7af48e

Please sign in to comment.