Skip to content

Commit b7af48e

Browse files
bajtoshacksparrow
andcommitted
docs: extract "How to customize OpenAPI serving" into a guide
Co-authored-by: Hage Yaapa <[email protected]> Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent d2d9749 commit b7af48e

File tree

3 files changed

+55
-34
lines changed

3 files changed

+55
-34
lines changed

docs/site/Server.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,6 @@ const app = new RestApplication({
6969
});
7070
```
7171

72-
### Customize How OpenAPI Spec is Served
73-
74-
There are a few options under `rest.openApiSpec` to configure how OpenAPI spec
75-
is served by the given REST server.
76-
77-
- servers: Configure servers for OpenAPI spec
78-
- setServersFromRequest: Set `servers` based on HTTP request headers, default to
79-
`false`
80-
- disabled: Set to `true` to disable endpoints for the OpenAPI spec. It will
81-
disable API Explorer too.
82-
- endpointMapping: Maps urls for various forms of the spec. Default to:
83-
84-
```js
85-
{
86-
'/openapi.json': {version: '3.0.0', format: 'json'},
87-
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
88-
}
89-
```
90-
91-
```ts
92-
const app = new RestApplication({
93-
rest: {
94-
openApiSpec: {
95-
servers: [{url: 'http://127.0.0.1:8080'}],
96-
setServersFromRequest: false,
97-
endpointMapping: {
98-
'/openapi.json': {version: '3.0.0', format: 'json'},
99-
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
100-
},
101-
},
102-
},
103-
});
104-
```
105-
10672
### Configure the API Explorer
10773

10874
LoopBack allows externally hosted API Explorer UI to render the OpenAPI
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
lang: en
3+
title: 'Customizing how OpenAPI spec is served'
4+
keywords: LoopBack 4.0, LoopBack 4, Node.js, OpenAPI, Customization
5+
sidebar: lb4_sidebar
6+
permalink: /doc/en/lb4/Customizing-how-openapi-spec-is-served.html
7+
---
8+
9+
By default, LoopBack REST API server provides endpoints exposing an OpenAPI spec
10+
document describing application's API. You can configure this behavior using
11+
`rest.openApiSpec` field in the configuration object passed to `RestApplication`
12+
constructor.
13+
14+
- servers: Configure servers for OpenAPI spec
15+
16+
- setServersFromRequest: Set `servers` based on HTTP request headers, default to
17+
`false`
18+
19+
- disabled: Set to `true` to disable endpoints for the OpenAPI spec. It will
20+
disable API Explorer too.
21+
22+
- endpointMapping: Maps urls for various forms of the spec. Default to:
23+
24+
```js
25+
{
26+
'/openapi.json': {version: '3.0.0', format: 'json'},
27+
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
28+
}
29+
```
30+
31+
Example application configuration object showing possible customizations:
32+
33+
{% include code-caption.html content="/src/index.ts" %}
34+
35+
```ts
36+
const config: ApplicationConfig = {
37+
rest: {
38+
openApiSpec: {
39+
servers: [{url: 'http://127.0.0.1:8080'}],
40+
setServersFromRequest: false,
41+
endpointMapping: {
42+
'/openapi.json': {version: '3.0.0', format: 'json'},
43+
'/openapi.yaml': {version: '3.0.0', format: 'yaml'},
44+
},
45+
},
46+
};
47+
});
48+
```

docs/site/sidebars/lb4_sidebar.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ children:
181181
output: 'web, pdf'
182182
children:
183183

184+
- title: 'Building REST APIs'
185+
output: 'web, pdf'
186+
children:
187+
- title: 'Customizing how OpenAPI spec is served'
188+
url: Customizing-how-openapi-spec-is-served.html
189+
output: 'web, pdf'
190+
184191
- title: 'Create Other Forms of APIs'
185192
url: Create-other-forms-of-apis.html
186193
output: 'web, pdf'

0 commit comments

Comments
 (0)