Skip to content

Commit

Permalink
add script to remove x-stoplight tags from OpenAPI file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Slezak committed Sep 28, 2023
1 parent d569ae9 commit 9622364
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
scripts/output/*.md
.env
.env
.DS_Store
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scripts": {
"update-md-tables-in-doc": "ts-node ./scripts/update-md-tables-in-doc.ts",
"build-md-tables-from-openapi": "ts-node ./scripts/build-md-tables-from-openapi.ts",
"readme-fix-docs-order": "ts-node ./scripts/readme-fix-docs-order.ts"
"readme-fix-docs-order": "ts-node ./scripts/readme-fix-docs-order.ts",
"remove-stoplight-tags-from-openapi": "ts-node ./scripts/remove-stoplight-tags-from-openapi.ts"
},
"dependencies": {
"dotenv": "^16.3.1",
Expand Down
31 changes: 31 additions & 0 deletions scripts/remove-stoplight-tags-from-openapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs/promises';
import path from 'path';

function isObject(value) {
return (
typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
);
}

const removeStoplightTag = (node: object): object => {
delete node['x-stoplight'];
for(const attr in node){
if(isObject(node[attr])){
removeStoplightTag(node[attr])
}
}
return node;
}

const main = async() => {
const openApiPath = path.join(__dirname, '../reference/OpenAPI.json');
const openAPIContent = JSON.parse((await fs.readFile(openApiPath)).toString())

removeStoplightTag(openAPIContent)

await fs.writeFile(openApiPath, JSON.stringify(openAPIContent, null, 2) )
}

main()

0 comments on commit 9622364

Please sign in to comment.