Skip to content

Commit

Permalink
fix: Use servers array in plugin openApi.json. (#1554)
Browse files Browse the repository at this point in the history
* Use servers array in plugin openApi.json.
* Remove reference to demo.signalk.org
* doc: add servers note
* refactor: rename for clarity

---------

Co-authored-by: Teppo Kurki <[email protected]>
  • Loading branch information
panaaj and tkurki authored May 16, 2023
1 parent d7870ee commit 639eaca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SERVERPLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ Express does not have a public API for deregistering subrouters, so `stop` does
**Consider seriously providing an OpenApi description** for your plugin's API. This promotes further cooperation with other plugin/webapp authors. One way we can work together is by fleshing out new APIs within a plugin and then merge them in the Signal K specification for more cooperation.
Implement `getOpenApi` in your plugin to expose your OpenApi to be included in the server's OpenApi UI tooling. See [testplugin](https://github.com/SignalK/signalk-server/tree/b82477e63ebdc14878164ce1ed3aedd80c5a8b0c/test/plugin-test-config/node_modules/testplugin) for an example.
Implement `getOpenApi` in your plugin to expose your OpenApi to be included in the server's OpenApi UI tooling. The plugin's OpenApi description either not include `servers` property at all or specify only the path in the url. The server will provide servers if it is missing and relative, path only server urls work best in different environments. See [testplugin](https://github.com/SignalK/signalk-server/tree/b82477e63ebdc14878164ce1ed3aedd80c5a8b0c/test/plugin-test-config/node_modules/testplugin) for an example.
## Plugin configuration HTTP API
Expand Down
13 changes: 4 additions & 9 deletions src/api/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,13 @@ export function mountSwaggerUi(app: IRouter & PluginManager, path: string) {
apiRecord = app.getPluginOpenApi(req.params.pluginId as PluginId)
}
const apiDoc = apiRecord?.apiDoc
const apiDocPath = apiRecord?.path
const apiPath = apiRecord?.path

if (apiDoc && apiDocPath !== undefined) {
if (apiDoc && apiPath !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(apiDoc as any).servers = [
;(apiDoc as any).servers = (apiDoc as any).servers ?? [
{
url: `${process.env.PROTOCOL ? 'https' : req.protocol}://${req.get(
'Host'
)}${apiDocPath}`
},
{
url: `https://demo.signalk.org${apiDocPath}`
url: `${apiPath}`
}
]
res.json(apiDoc)
Expand Down

0 comments on commit 639eaca

Please sign in to comment.