Skip to content

Commit bd54342

Browse files
authored
EFS-1491 Add swagger doc for (#1842)
* EFS-1491 Add swagger doc for * EFS-1491 Added patch * EFS-1491 updated evn setting
1 parent c00a18e commit bd54342

7 files changed

+175
-414
lines changed

env.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
"type": "string",
6868
"default": "local"
6969
},
70-
"SWAGGER_CONFIG_URL": {
70+
"ENABLE_SWAGGER_DOC": {
7171
"type": "string",
72-
"default": "./swagger_local.json"
72+
"default": "0"
7373
},
7474
"RENDER_HTML": {
7575
"type": "string",

src/app.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ function createFhirApp (fnGetContainer, app1) {
8686
* @return {import('express').Express}
8787
*/
8888
function createApp ({ fnGetContainer }) {
89-
const swaggerUi = require('swagger-ui-express');
90-
const swaggerDocument = require(env.SWAGGER_CONFIG_URL);
91-
9289
/**
9390
* @type {import('express').Express}
9491
*/
@@ -293,7 +290,17 @@ function createApp ({ fnGetContainer }) {
293290
};
294291

295292
// noinspection JSCheckFunctionSignatures
296-
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
293+
// http://localhost:3000/api-docs
294+
if(isTrue(env.ENABLE_SWAGGER_DOC)){
295+
const swaggerUi = require('swagger-ui-express');
296+
const swaggerDocument = require('./swagger_doc.json');
297+
let swaggerString = JSON.stringify(swaggerDocument)
298+
swaggerString = swaggerString
299+
.replace(/<HOST_SERVER>/g, env.HOST_SERVER + "/4_0_0")
300+
.replace(/<ENVIRONMENT>/g, env.ENVIRONMENT);
301+
const configuredSwaggerDocument = JSON.parse(swaggerString);
302+
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(configuredSwaggerDocument));
303+
}
297304

298305
app.use('/oauth', express.static(path.join(__dirname, 'oauth')));
299306

src/swagger_dev.json

-92
This file was deleted.

src/swagger_doc.json

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "b.Well FHIR Server API",
5+
"version": "4.3.0",
6+
"description": "b.Well FHIR Server API documentation",
7+
"license": {
8+
"name": "MIT",
9+
"url": "https://opensource.org/licenses/MIT"
10+
}
11+
},
12+
"servers": [
13+
{
14+
"url": "<HOST_SERVER>",
15+
"description": "<ENVIRONMENT> FHIR Server"
16+
}
17+
],
18+
"paths": {
19+
"/Patient/{id}/$everything": {
20+
"get": {
21+
"summary": "FHIR $everything Operation",
22+
"description": "The FHIR server supports the $everything endpoint of the FHIR specification. This operation is used to retrieve all resources related to the provided patient resource.\n\nIt is mandatory to provide id in path param.",
23+
"parameters": [
24+
{
25+
"name": "id",
26+
"in": "path",
27+
"required": true,
28+
"schema": {
29+
"type": "string"
30+
},
31+
"description": "The sourceId or UUID of the patient whose related resources are to be fetched."
32+
},
33+
{
34+
"name": "_type",
35+
"in": "query",
36+
"required": false,
37+
"schema": {
38+
"type": "string"
39+
},
40+
"description": "A comma-separated list of resource names to filter the resources fetched."
41+
}
42+
],
43+
"responses": {
44+
"200": {
45+
"description": "A Bundle containing the related resources.",
46+
"content": {
47+
"application/json": {
48+
"schema": {
49+
"$ref": "#/components/schemas/Bundle"
50+
},
51+
"example": {
52+
"entry": [
53+
{
54+
"resource": {
55+
"resourceType": "Observation",
56+
"id": "obs1"
57+
}
58+
}
59+
],
60+
"id": "53653e72-9943-451f-a4a3-f3d8b37bf43d",
61+
"resourceType": "Bundle",
62+
"type": "searchset",
63+
"timestamp": "2021-12-31T23:59:59Z",
64+
"total": 1,
65+
"link": [
66+
{
67+
"relation": "self",
68+
"url": "http://fhir.icanbwell.com/4_0_0/Patient/123/$everything"
69+
}
70+
]
71+
}
72+
}
73+
}
74+
},
75+
"401": {
76+
"description": "Unauthorized. JWT is missing, invalid, or expired.",
77+
"content": {
78+
"text/plain": {}
79+
}
80+
},
81+
"404": {
82+
"description": "Not Found. The endpoint or service does not exist.",
83+
"content": {
84+
"application/json": {}
85+
}
86+
}
87+
},
88+
"security": [
89+
{
90+
"bearerAuth": []
91+
}
92+
]
93+
}
94+
}
95+
},
96+
"components": {
97+
"securitySchemes": {
98+
"bearerAuth": {
99+
"type": "http",
100+
"scheme": "bearer",
101+
"bearerFormat": "JWT",
102+
"description": "JWT based authentication. Please enter your jwt token for authentication."
103+
}
104+
},
105+
"schemas": {
106+
"Bundle": {
107+
"type": "object",
108+
"properties": {
109+
"entry": {
110+
"type": "array",
111+
"items": {
112+
"type": "object",
113+
"description": "An individual resource entry."
114+
},
115+
"description": "Array of resource entries."
116+
},
117+
"id": {
118+
"type": "string",
119+
"description": "A unique identifier for this request."
120+
},
121+
"resourceType": {
122+
"type": "string",
123+
"example": "Bundle",
124+
"description": "The type of resource returned, always 'Bundle'."
125+
},
126+
"type": {
127+
"type": "string",
128+
"example": "searchset",
129+
"description": "The bundle type, e.g., 'searchset'."
130+
},
131+
"timestamp": {
132+
"type": "string",
133+
"format": "date-time",
134+
"description": "The time at which the bundle was generated."
135+
},
136+
"total": {
137+
"type": "integer",
138+
"description": "The total number of resources retrieved."
139+
},
140+
"link": {
141+
"type": "array",
142+
"items": {
143+
"type": "object",
144+
"properties": {
145+
"relation": {
146+
"type": "string",
147+
"description": "The relation type, e.g., 'self'."
148+
},
149+
"url": {
150+
"type": "string",
151+
"description": "The URL for the corresponding relation."
152+
}
153+
}
154+
},
155+
"description": "Link to the current request."
156+
}
157+
}
158+
}
159+
}
160+
}
161+
}
162+

0 commit comments

Comments
 (0)