Skip to content

Commit

Permalink
feat(apidoc): delete, swagger try in redoc, resource filter, layout
Browse files Browse the repository at this point in the history
- add `delete` api doc
- fix `update` that missing `id` apiParam
- add resource filter
- change title name
- beautify html
- add mt-2, mb-2
- change openapi generator input path
- move to `docs/apidoc/apidoc-sources`
- remove `*/` in resource content to prevent comment not working
  • Loading branch information
Chinlinlee committed Feb 18, 2022
1 parent d9a4f9a commit bc57589
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 181 deletions.
87 changes: 86 additions & 1 deletion api_generator/doc-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require('path');
const mkdirp = require('mkdirp');
const beautify = require('js-beautify').js;
const _ = require('lodash');
const GENERATE_API_DOC = true;

/**
* @param {string} resource resource type
Expand Down Expand Up @@ -168,6 +167,7 @@ function getDocCodeUpdate(resource) {
/**
*
* @api {put} /fhir/${resource}/:id update ${resource}
* @apiParam {string} id Resource ID that you want to update
* @apiName update${resource}
* @apiGroup ${resource}
* @apiVersion v2.1.0
Expand Down Expand Up @@ -243,6 +243,86 @@ function getDocCodeUpdate(resource) {
return `${comment}`;
}

function getDocCodeDelete(resource) {
const responseExampleBody = require(`../docs/assets/FHIR/burni-create-examples-response/${resource}.json`);
const comment = `
/**
*
* @api {delete} /fhir/${resource}/:id delete ${resource} by id
* @apiParam {string} id Resource ID in server
* @apiName delete${resource}
* @apiGroup ${resource}
* @apiVersion v2.1.0
* @apiDescription delete ${resource} resource by id.
*
* @apiExample {Shell} cURL
* #example from: https://chinlinlee.github.io/Burni/assets/FHIR/fhir-resource-examples/${resource.toLowerCase()}-example.json
* curl --location --request DELETE 'http://burni.example.com/fhir/${resource}/${responseExampleBody.id}'
* @apiExample {JavaScript} javascript Axios
//example from: https://chinlinlee.github.io/Burni/assets/FHIR/fhir-resource-examples/${resource.toLowerCase()}-example.json
const axios = require('axios');
const config = {
method: 'delete',
url: 'http://burni.example.com/fhir/${resource}/${responseExampleBody.id}'
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
* @apiSuccess (Success 200 Content-Type: application/fhir+json) {object} FHIR-JSON-RESOURCE
* @apiSuccessExample {json} (200) name: Success-Response Content-Type: application/fhir+json
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "information",
"code": "informational",
"diagnostics": "delete ${resource}/${responseExampleBody.id} successfully"
}
]
}
*
* @apiSuccess (Success 200 Content-Type: application/fhir+xml) {object} FHIR-XML-RESOURCE
* @apiSuccessExample {xml} (200) name: Success-Response-XML Content-Type: application/fhir+xml
<OperationOutcome xmlns='http://hl7.org/fhir'>
<issue>
<severity value='information'/>
<code value='informational'/>
<diagnostics value='delete ${resource}/${responseExampleBody.id} successfully'/>
</issue>
</OperationOutcome>
*
* @apiError (Error Not Found 404 Content-Type: application/fhir+json) {object} FHIR-JSON-RESOURCE
* @apiErrorExample {json} (404) name: Not-Found-Response Content-Type: application/fhir+json
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "exception",
"diagnostics": "The id->${responseExampleBody.id} not found in ${resource} resource"
}
]
}
*
* @apiError (Error Not Found 404 Content-Type: application/fhir+xml) {object} FHIR-XML-RESOURCE
* @apiErrorExample {xml} (404) name: Not-Found-Response-XML Content-Type: application/fhir+xml
<OperationOutcome xmlns='http://hl7.org/fhir'>
<issue>
<severity value='error'/>
<code value='not-found'/>
<diagnostics value='The id-&gt;${responseExampleBody.id} not found in ${resource} resource'/>
</issue>
</OperationOutcome>
*
*/
`;
return `${comment}`;
}

/**
*
Expand All @@ -266,6 +346,11 @@ function generateDoc(resources) {
const updateCode = getDocCodeUpdate(res);
fs.writeFileSync(`./docs/apidoc/apidoc-sources/${res}/put${res}.js`, beautify(updateCode));
//#endregion

//#region delete
const deleteCode = getDocCodeDelete(res);
fs.writeFileSync(`./docs/apidoc/apidoc-sources/${res}/delete${res}.js`, beautify(deleteCode));
//#endregion
}
}

Expand Down
60 changes: 60 additions & 0 deletions docs/apidoc/redoc/index.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.mt-2 {
margin-top: 0.5rem!important;
}

.mb-2 {
margin-bottom: 0.5rem!important;
}

.text-center {
text-align: center!important;
}
Expand Down Expand Up @@ -41,4 +49,56 @@

.btn:not(:disabled):not(.disabled) {
cursor: pointer;
}

.filter-search-icon {
position: absolute;
left: 20px;
height: 1.8em;
width: 0.9em;
}

.filter-clear {
position: absolute;
display: inline-block;
width: 10px;
text-align: center;
right: 20px;
line-height: 2em;
vertical-align: middle;
margin-right: 2px;
cursor: pointer;
font-style: normal;
}

.filter-input {
width: calc(100% - 40px);
box-sizing: border-box;
margin: 0px 20px;
padding: 5px 10px 5px 20px;
border-width: 0px 0px 1px;
border-top-style: initial;
border-right-style: initial;
border-left-style: initial;
border-top-color: initial;
border-right-color: initial;
border-left-color: initial;
border-image: initial;
border-bottom-style: solid;
border-bottom-color: rgb(225, 225, 225);
font-family: Roboto, sans-serif;
font-weight: bold;
font-size: 13px;
color: rgb(51, 51, 51);
background-color: transparent;
outline: none;
}

.tryBtn {
line-height: 20px;
margin-right: 0.25rem;
}

.opblock {
overflow-x: auto;
}
Loading

0 comments on commit bc57589

Please sign in to comment.