-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to remove x-stoplight tags from OpenAPI file
- Loading branch information
Marcin Slezak
committed
Sep 28, 2023
1 parent
d569ae9
commit 9622364
Showing
3 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
scripts/output/*.md | ||
.env | ||
.env | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |