enable OpenAPI spec, link to it 📝

This commit is contained in:
Jannis R 2021-02-04 19:24:13 +01:00
parent a34fe93230
commit b214b57976
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
7 changed files with 97 additions and 1 deletions

View file

@ -10,6 +10,8 @@ const HEAD = `\
You can just use the API without authentication. There's a [rate limit](https://apisyouwonthate.com/blog/what-is-api-rate-limiting-all-about) of 100 request/minute (burst 200 requests/minute) set up. You can just use the API without authentication. There's a [rate limit](https://apisyouwonthate.com/blog/what-is-api-rate-limiting-all-about) of 100 request/minute (burst 200 requests/minute) set up.
[OpenAPI playground](https://petstore.swagger.io/?url=https%3A%2F%2Fv5.db.transport.rest%2F.well-known%2Fservice-desc%0A)
*Note:* For [URL-encoding](https://de.wikipedia.org/wiki/URL-Encoding), this documentation uses the \`url-encode\` tool of the [\`url-decode-encode-cli\` package](https://www.npmjs.com/package/url-decode-encode-cli). *Note:* For [URL-encoding](https://de.wikipedia.org/wiki/URL-Encoding), this documentation uses the \`url-encode\` tool of the [\`url-decode-encode-cli\` package](https://www.npmjs.com/package/url-decode-encode-cli).
` `

1
api.js
View file

@ -56,6 +56,7 @@ const config = {
homepage: pkg.homepage, homepage: pkg.homepage,
version: pkg.version, version: pkg.version,
docsLink: 'https://github.com/derhuerst/db-rest/blob/5/docs/readme.md', docsLink: 'https://github.com/derhuerst/db-rest/blob/5/docs/readme.md',
openapiSpec: true,
logging: true, logging: true,
aboutPage: false, aboutPage: false,
etags: 'strong', etags: 'strong',

View file

@ -4,6 +4,8 @@
You can just use the API without authentication. There's a [rate limit](https://apisyouwonthate.com/blog/what-is-api-rate-limiting-all-about) of 100 request/minute (burst 200 requests/minute) set up. You can just use the API without authentication. There's a [rate limit](https://apisyouwonthate.com/blog/what-is-api-rate-limiting-all-about) of 100 request/minute (burst 200 requests/minute) set up.
[OpenAPI playground](https://petstore.swagger.io/?url=https%3A%2F%2Fv5.db.transport.rest%2F.well-known%2Fservice-desc%0A)
*Note:* For [URL-encoding](https://de.wikipedia.org/wiki/URL-Encoding), this documentation uses the `url-encode` tool of the [`url-decode-encode-cli` package](https://www.npmjs.com/package/url-decode-encode-cli). *Note:* For [URL-encoding](https://de.wikipedia.org/wiki/URL-Encoding), this documentation uses the `url-encode` tool of the [`url-decode-encode-cli` package](https://www.npmjs.com/package/url-decode-encode-cli).

View file

@ -316,4 +316,4 @@ Note that `departure` includes the `departureDelay`, and `arrival` includes the
### 4. more features ### 4. more features
These are the basics. Check the full [API docs](api.md) for all features! These are the basics. Check the full [API docs](api.md) for all features or use the [OpenAPI playground](https://petstore.swagger.io/?url=https%3A%2F%2Fv5.db.transport.rest%2F.well-known%2Fservice-desc%0A) or explore the API!

View file

@ -8,6 +8,7 @@ Because it wraps [an API](https://github.com/public-transport/hafas-client/blob/
- [Getting Started](getting-started.md) - [Getting Started](getting-started.md)
- [API documentation](api.md) - [API documentation](api.md)
- [OpenAPI playground](https://petstore.swagger.io/?url=https%3A%2F%2Fv5.db.transport.rest%2F.well-known%2Fservice-desc%0A)
## Why use this API? ## Why use this API?

View file

@ -25,4 +25,36 @@ const stationRoute = (req, res, next) => {
.catch(next) .catch(next)
} }
stationRoute.openapiPaths = {
'/stations/{id}': {
get: {
summary: 'Returns a stop/station from `db-stations`.',
description: `\
Returns a stop/station from [\`db-stations\`](https://npmjs.com/package/db-stations).`,
parameters: [{
name: 'id',
in: 'path',
description: 'Stop/station ID.',
required: true,
schema: {
type: 'string',
},
}],
responses: {
'2XX': {
description: 'A stop/station, in the [`db-stations` format](https://github.com/derhuerst/db-stations/blob/master/readme.md).',
content: {
'application/json': {
schema: {
type: 'object', // todo
},
// todo: example(s)
},
},
},
},
},
},
}
module.exports = stationRoute module.exports = stationRoute

View file

@ -109,6 +109,64 @@ const stationsRoute = (req, res, next) => {
.catch(next) .catch(next)
} }
stationsRoute.openapiPaths = {
'/stations': {
get: {
summary: 'Autocompletes stops/stations by name or filters stops/stations.',
description: `\
If the \`query\` parameter is used, it will use [\`db-stations-autocomplete\`](https://npmjs.com/package/db-stations-autocomplete) to autocomplete *Deutsche Bahn*-operated stops/stations by name. Otherwise, it will filter the stops/stations in [\`db-stations\`](https://npmjs.com/package/db-stations).
Instead of receiving a JSON response, you can request [newline-delimited JSON](http://ndjson.org) by sending \`Accept: application/x-ndjson\`.`,
parameters: [{
name: 'query',
in: 'query',
description: 'Find stations by name using [`db-stations-autocomplete`](https://npmjs.com/package/db-stations-autocomplete).',
schema: {
type: 'string',
},
}, {
name: 'limit',
in: 'query',
description: '*If `query` is used:* Return at most `n` stations.',
schema: {
type: 'integer',
default: 3,
},
}, {
name: 'fuzzy',
in: 'query',
description: '*If `query` is used:* Find stations despite typos.',
schema: {
type: 'boolean',
default: false,
},
}, {
name: 'completion',
in: 'query',
description: '*If `query` is used:* Autocomplete stations.',
schema: {
type: 'boolean',
default: true,
},
}],
responses: {
'2XX': {
description: 'An array of stops/stations, in the [`db-stations` format](https://github.com/derhuerst/db-stations/blob/master/readme.md).',
content: {
'application/json': {
schema: {
type: 'array',
items: {type: 'object'}, // todo
},
// todo: example(s)
},
},
},
},
},
},
}
stationsRoute.queryParameters = { stationsRoute.queryParameters = {
query: { query: {
description: 'Find stations by name using [`db-stations-autocomplete`](https://npmjs.com/package/db-stations-autocomplete).', description: 'Find stations by name using [`db-stations-autocomplete`](https://npmjs.com/package/db-stations-autocomplete).',