-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement dereferenced openapi schema
- Loading branch information
1 parent
7ac0320
commit 5163714
Showing
6 changed files
with
137 additions
and
44 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
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
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,39 @@ | ||
import refResolver from '@stoplight/json-ref-resolver' | ||
import fs from 'fs' | ||
|
||
|
||
const resolveRefs = async (schema) => { | ||
const resolver = new refResolver.Resolver() | ||
return await resolver.resolve(schema) | ||
} | ||
|
||
const getOpenAPISchema = async (schemaPath) => { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(schemaPath, 'utf8', (err, data) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(JSON.parse(data)) | ||
}) | ||
|
||
}) | ||
} | ||
|
||
const save = (filename, schema) => { | ||
const asJson = JSON.stringify(schema, null, 4) | ||
const written = fs.writeFileSync(filename, asJson) | ||
return written | ||
} | ||
|
||
const main = async (schemaPath) => { | ||
let schema = await getOpenAPISchema(schemaPath) | ||
schema = (await resolveRefs(schema)).result | ||
save(schemaPath, schema) | ||
} | ||
|
||
const argv = process.argv.slice(2) | ||
if (argv.length !== 1) { | ||
throw new Error('Args: <schemaPath>') | ||
} | ||
main(argv[0]) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.