Package Exports
- openapi-ref-flatten
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (openapi-ref-flatten) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
OpenAPI Ref Flatten
Resolve $ref values in JSON Schema, OpenAPI (Swagger), and any other objects with $ref values inside them.
Project status: draft
TODOs
- resolve $ref;
- add README;
- make the code more elegant;
- add tests;
- add yaml reader;
- (???) support
--dereferenceflag;
Installation
Supported in modern browsers and node.
npm i openapi-ref-flattenExample
For the convenience of examples, I will use YAML-files (see TODOs). Currently only JSON is supported.
Input
For example, we have the following project structure:
super-project/
|--- api/
|--- example.yml
|--- models/
|--- pet-model.yml
|--- kind-model.yml
The files contain the following:
# file: super-project/api/example.yml
pet1:
$ref: ../models/pet-model.yml#/components/schemas/Pet
pet2:
$ref: ../models/pet-model.yml#/components/schemas/Pet
kind1:
$ref: ../models/kind-model.yml#/components/schemas/Kind# file: super-project/models/pet-model.yml
components:
schemas:
Pet:
type: object
properties:
name:
type: string
kind:
$ref: ./kind-model.yml#/components/schemas/Kind# file: super-project/models/kind-model.yml
components:
schemas:
Kind:
type: object
properties:
name:
type: stringOutput
Run command:
node cli.js --input ./super-project/api/example.yml --output ./dist/result.yml# file: dist/result.yml
pet1:
$ref: #/components/schemas/Pet
pet2:
$ref: #/components/schemas/Pet
kind1:
$ref: #/components/schemas/Kind
components:
schemas:
Pet:
type: object
properties:
name:
type: string
kind:
$ref: #/components/schemas/Kind
Kind:
type: object
properties:
name:
type: stringClassic dereference
In a simple dereference, we will have the following output:
node cli.js --input ./super-project/api/example.yml --output ./dist/result.yml --derefence
The --derefence flag is not supported now.
pet1:
type: object
properties:
name:
type: string
kind:
type: object
properties:
name:
type: string
pet2:
type: object
properties:
name:
type: string
kind:
type: object
properties:
name:
type: string
kind1:
type: object
properties:
name:
type: string