Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken swagger for APIv3 (#6201) #49

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,12 @@ function create (env, ctx) {
// API docs

const swaggerUi = require('swagger-ui-express');
const swaggerUseSchema = schema => (...args) => swaggerUi.setup(schema)(...args);
const swaggerDocument = require('./swagger.json');
const swaggerDocumentApiV3 = require('./lib/api3/swagger.json');

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api-docs', swaggerUi.serve, swaggerUseSchema(swaggerDocument));
app.use('/api3-docs', swaggerUi.serve, swaggerUseSchema(swaggerDocumentApiV3));

app.use('/swagger-ui-dist', (req, res) => {
res.redirect(307, '/api-docs');
Expand Down
22 changes: 11 additions & 11 deletions lib/api3/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Each NS instance with API v3 contains self-included OpenAPI specification at [/a
---
### VERSION

[VERSION](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/other/get_version) operation gets you basic information about software packages versions.
[VERSION](https://nsapiv3.herokuapp.com/api3-docs/#/other/get_version) operation gets you basic information about software packages versions.
It is public (there is no need to add authorization parameters/headers).

Sample GET `/version` client code (to get actual versions):
Expand All @@ -38,7 +38,7 @@ Sample result:
---
### STATUS

[STATUS](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/other/get_status) operation gets you basic information about software packages versions.
[STATUS](https://nsapiv3.herokuapp.com/api3-docs/#/other/get_status) operation gets you basic information about software packages versions.
It is public (there is no need to add authorization parameters/headers).

Sample GET `/status` client code (to get my actual permissions):
Expand Down Expand Up @@ -75,7 +75,7 @@ Sample result:
---
### SEARCH

[SEARCH](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/SEARCH) operation filters, sorts, paginates and projects documents from the collection.
[SEARCH](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/SEARCH) operation filters, sorts, paginates and projects documents from the collection.

Sample GET `/entries` client code (to retrieve last 3 BG values):
```javascript
Expand Down Expand Up @@ -110,7 +110,7 @@ Sample result:
---
### CREATE

[CREATE](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/generic/post__collection_) operation inserts a new document into the collection.
[CREATE](https://nsapiv3.herokuapp.com/api3-docs/#/generic/post__collection_) operation inserts a new document into the collection.

Sample POST `/treatments` client code:
```javascript
Expand Down Expand Up @@ -140,7 +140,7 @@ Sample result:
---
### READ

[READ](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/generic/get__collection___identifier_) operation retrieves you a single document from the collection by its identifier.
[READ](https://nsapiv3.herokuapp.com/api3-docs/#/generic/get__collection___identifier_) operation retrieves you a single document from the collection by its identifier.

Sample GET `/treatments/{identifier}` client code:
```javascript
Expand Down Expand Up @@ -172,7 +172,7 @@ Sample result:
---
### LAST MODIFIED

[LAST MODIFIED](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/other/LAST-MODIFIED) operation finds the date of last modification for each collection.
[LAST MODIFIED](https://nsapiv3insecure.herokuapp.com/api3-docs/#/other/LAST-MODIFIED) operation finds the date of last modification for each collection.

Sample GET `/lastModified` client code (to get latest modification dates):
```javascript
Expand All @@ -199,7 +199,7 @@ Sample result:
---
### UPDATE

[UPDATE](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/put__collection___identifier_) operation updates existing document in the collection.
[UPDATE](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/put__collection___identifier_) operation updates existing document in the collection.

Sample PUT `/treatments/{identifier}` client code (to update `insulin` from 0.3 to 0.4):
```javascript
Expand Down Expand Up @@ -231,7 +231,7 @@ Sample result:
---
### PATCH

[PATCH](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/patch__collection___identifier_) operation partially updates existing document in the collection.
[PATCH](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/patch__collection___identifier_) operation partially updates existing document in the collection.

Sample PATCH `/treatments/{identifier}` client code (to update `insulin` from 0.4 to 0.5):
```javascript
Expand Down Expand Up @@ -259,7 +259,7 @@ Sample result:
---
### DELETE

[DELETE](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/delete__collection___identifier_) operation deletes existing document from the collection.
[DELETE](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/delete__collection___identifier_) operation deletes existing document from the collection.

Sample DELETE `/treatments/{identifier}` client code (to update `insulin` from 0.4 to 0.5):
```javascript
Expand All @@ -282,7 +282,7 @@ Sample result:
---
### HISTORY

[HISTORY](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/HISTORY2) operation queries all changes since the timestamp.
[HISTORY](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/HISTORY2) operation queries all changes since the timestamp.

Sample HISTORY `/treatments/history/{lastModified}` client code:
```javascript
Expand Down Expand Up @@ -326,4 +326,4 @@ Sample result:
}
]
```
Notice the `"isValid":false` field marking the deletion of the document.
Notice the `"isValid":false` field marking the deletion of the document.
8 changes: 5 additions & 3 deletions lib/api3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const express = require('express')
, apiConst = require('./const.json')
, security = require('./security')
, genericSetup = require('./generic/setup')
, swaggerSetup = require('./swagger')
;

function configure (env, ctx) {
Expand Down Expand Up @@ -35,7 +34,7 @@ function configure (env, ctx) {


self.setupApiEnvironment = function setupApiEnvironment () {

app.use(bodyParser.json({
limit: 1048576 * 50
}), function errorHandler (err, req, res, next) {
Expand Down Expand Up @@ -100,7 +99,10 @@ function configure (env, ctx) {
self.setupApiEnvironment();
genericSetup(ctx, env, app);
self.setupApiRoutes();
swaggerSetup(app);

app.use('/swagger-ui-dist', (req, res) => {
res.redirect(307, '../../../api3-docs');
});

ctx.storageSocket = new StorageSocket(app, env, ctx);

Expand Down
41 changes: 0 additions & 41 deletions lib/api3/swagger.js

This file was deleted.

Loading