Sample project for structured OpenAPI schema.
This project includes OpenAPI schema, based on structured YAML files.
https://swagger.io/specification/
YAML files reference each other using $ref.
https://swagger.io/docs/specification/using-ref/
The directory structure based on OpenAPI object.
https://swagger.io/specification/#oasObject
paths/ # https://swagger.io/specification/#pathItemObject
components/ # https://swagger.io/specification/#componentsObject
schemas/ # https://swagger.io/specification/#schemaObject
parameters/ # https://swagger.io/specification/#parameterObjectBut you can change directory structure as you like.
For the case of adding /notes to routing.
Add notes.yml into ./paths.
# paths/notes.yml
get:
responses:
200:
description: okThen add a reference to this file into root.yml.
# root.yml
paths:
/notes:
$ref: ./paths/notes.ymlThis reference means path definition as below.
paths:
/notes:
get:
responses:
200:
description: okIf you need OpenAPI schema as a single JSON (or YAML) file, you can merge structured files using openapi-generator.
# generate openapi.json
$ openapi-generator-cli generate -g openapi -i root.yml -o generated
# generate openapi.yaml
$ openapi-generator-cli generate -g openapi-yaml -i root.yml -o generatedLint OpenAPI schema using Stoplight Spectral.
$ spectral lint ./generated/openapi.jsonRun mock server based on OpenAPI schema using Stoplight Prism.
$ prism mock ./generated/openapi.json