├── packages
├── oas-resolver
│ ├── .gitignore
│ ├── README.md
│ ├── package.json
│ ├── LICENSE
│ └── resolve.js
├── oas-kit-common
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── LICENSE
│ └── index.js
├── reftools
│ ├── .gitignore
│ ├── package-lock.json
│ ├── lib
│ │ ├── isref.js
│ │ ├── findObj.js
│ │ ├── flatten.js
│ │ ├── reref.js
│ │ ├── recurse.js
│ │ ├── visit.js
│ │ ├── clone.js
│ │ └── jptr.js
│ ├── package.json
│ ├── LICENSE
│ └── api
│ │ └── testapi.js
├── oas-schema-walker
│ ├── package-lock.json
│ ├── package.json
│ ├── README.md
│ └── LICENSE
├── swagger2openapi
│ ├── Dockerfile
│ ├── lib
│ │ └── statusCodes.js
│ ├── .gitignore
│ ├── LICENSE
│ ├── package.json
│ └── swagger2openapi.js
├── oas-linter
│ ├── README.md
│ ├── package.json
│ ├── LICENSE
│ ├── package-lock.json
│ └── rules.yaml
└── oas-validator
│ ├── README.md
│ ├── package.json
│ ├── LICENSE
│ └── package-lock.json
├── test
├── s2o-test
│ ├── !issue217
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue145
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue39
│ │ ├── options.yaml
│ │ ├── subdir1
│ │ │ ├── subdir2
│ │ │ │ └── ok.yaml
│ │ │ └── test.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue51a
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue51b
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── !issue217b
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── !missing-ref
│ │ ├── options.yaml
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── speccy 141
│ │ ├── include.yaml
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── speccy249
│ │ ├── options.yaml
│ │ ├── xyz.json
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue130-allOf
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue130-remove
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue130-preserve
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue112
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue117
│ │ ├── options.yaml
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── minimal
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── issue102
│ │ ├── schemas
│ │ │ └── ping.json
│ │ ├── swagger.yaml
│ │ ├── openapi.yaml
│ │ └── endpoints
│ │ │ └── ping.yaml
│ ├── without-schemes
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── without-schemes-with-base-path
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── pull348-trailing-slash
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── include
│ │ └── health.yml
│ ├── issue164
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue6
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue41
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── speccy286
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue70
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue201
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── issue202
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── issue51c
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── !issue79
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue51d
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue189
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue76
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue215
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ ├── issue186
│ │ ├── openapi.yaml
│ │ └── swagger.yaml
│ ├── issue169
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
│ └── issue229
│ │ ├── swagger.yaml
│ │ └── openapi.yaml
├── validator
│ ├── escapedRef
│ │ ├── options.yaml
│ │ └── openapi.yaml
│ ├── speccy21
│ │ ├── options.yaml
│ │ └── openapi.yaml
│ ├── invalidVersion
│ │ ├── options.yaml
│ │ └── openapi.yaml
│ ├── issue418
│ │ ├── options.yaml
│ │ └── openapi.yaml
│ └── speccy286
│ │ └── openapi.yaml
├── http2
│ └── simple
│ │ ├── options.yaml
│ │ ├── schema.yaml
│ │ ├── output.yaml
│ │ └── input.yaml
├── resolver
│ ├── speccy 141
│ │ ├── include.yaml
│ │ ├── output.yaml
│ │ └── input.yaml
│ ├── issue152
│ │ ├── options.yaml
│ │ ├── responses.yaml
│ │ ├── schemas.yaml
│ │ ├── input.yaml
│ │ └── output.yaml
│ ├── issue282
│ │ ├── options.yaml
│ │ ├── pet.yaml
│ │ ├── input.yaml
│ │ └── output.yaml
│ ├── simple
│ │ ├── options.yaml
│ │ ├── output.yaml
│ │ └── input.yaml
│ ├── speccy249
│ │ ├── include
│ │ │ └── xyz.json
│ │ ├── output.yaml
│ │ └── input.yaml
│ ├── prevalidate
│ │ ├── options.yaml
│ │ ├── include.yaml
│ │ ├── output.yaml
│ │ └── input.yaml
│ ├── issue196
│ │ ├── SchemaDog.yaml
│ │ ├── SchemaAnimal.yaml
│ │ ├── Parameters.yaml
│ │ ├── input.yaml
│ │ └── output.yaml
│ └── speccy420
│ │ ├── input.yaml
│ │ ├── temp.json
│ │ └── output.yaml
├── testreref.js
├── localhost.cert
├── testisref.js
├── testfindobj.js
├── validator.test.js
├── resolver.test.js
├── localhost.key
├── s2o.test.js
├── testderef.js
├── testtopo.js
├── testclone.js
├── http2.test.js
└── testflatten.js
├── docs
├── _config.yml
├── logo.png
├── default-rules.md
├── handlers.md
├── browser.md
├── README.md
├── extensions.md
├── externals.md
└── linter-rules.md
├── lerna.json
├── bin
├── updateCoverage.sh
├── setflags.sh
└── jsdocToMarkdown.sh
├── .editorconfig
├── .gitignore
├── CONTRIBUTING.md
├── webpack.reftools.js
├── CHANGELOG.md
├── .github
├── workflows
│ ├── ci.yaml
│ └── codeql-analysis.yml
├── ISSUE_TEMPLATE.md
└── dependabot.yml
├── webpack.converter.js
├── README.md
├── LICENSE
├── package.json
├── webpack.validator.js
└── webpack.config.js
/packages/oas-resolver/.gitignore:
--------------------------------------------------------------------------------
1 | resolved*.yaml
2 |
--------------------------------------------------------------------------------
/test/s2o-test/!issue217/options.yaml:
--------------------------------------------------------------------------------
1 | throws: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/issue145/options.yaml:
--------------------------------------------------------------------------------
1 | patch: false
2 |
--------------------------------------------------------------------------------
/test/s2o-test/issue39/options.yaml:
--------------------------------------------------------------------------------
1 | resolve: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51a/options.yaml:
--------------------------------------------------------------------------------
1 | resolve: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51b/options.yaml:
--------------------------------------------------------------------------------
1 | resolve: true
2 |
--------------------------------------------------------------------------------
/test/validator/escapedRef/options.yaml:
--------------------------------------------------------------------------------
1 | lint: true
2 |
--------------------------------------------------------------------------------
/test/validator/speccy21/options.yaml:
--------------------------------------------------------------------------------
1 | lint: true
2 |
--------------------------------------------------------------------------------
/test/http2/simple/options.yaml:
--------------------------------------------------------------------------------
1 | resolveInternal: true
2 |
--------------------------------------------------------------------------------
/test/resolver/speccy 141/include.yaml:
--------------------------------------------------------------------------------
1 | type: string
2 |
--------------------------------------------------------------------------------
/test/s2o-test/!issue217b/options.yaml:
--------------------------------------------------------------------------------
1 | anchors: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/!missing-ref/options.yaml:
--------------------------------------------------------------------------------
1 | warnOnly: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy 141/include.yaml:
--------------------------------------------------------------------------------
1 | type: string
2 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy 141/options.yaml:
--------------------------------------------------------------------------------
1 | resolve: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy249/options.yaml:
--------------------------------------------------------------------------------
1 | resolve: true
2 |
--------------------------------------------------------------------------------
/test/resolver/issue152/options.yaml:
--------------------------------------------------------------------------------
1 | #preserveMiro: false
2 |
--------------------------------------------------------------------------------
/test/resolver/issue282/options.yaml:
--------------------------------------------------------------------------------
1 | ignoreIOErrors: true
2 |
--------------------------------------------------------------------------------
/test/resolver/simple/options.yaml:
--------------------------------------------------------------------------------
1 | resolveInternal: true
2 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-allOf/options.yaml:
--------------------------------------------------------------------------------
1 | refSiblings: allOf
2 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-remove/options.yaml:
--------------------------------------------------------------------------------
1 | refSiblings: remove
2 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy249/xyz.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "integer"
3 | }
4 |
--------------------------------------------------------------------------------
/test/validator/invalidVersion/options.yaml:
--------------------------------------------------------------------------------
1 | expectFailure: true
2 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
2 | show_downloads: true
3 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-preserve/options.yaml:
--------------------------------------------------------------------------------
1 | refSiblings: preserve
2 |
--------------------------------------------------------------------------------
/docs/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Mermade/oas-kit/main/docs/logo.png
--------------------------------------------------------------------------------
/test/resolver/speccy249/include/xyz.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "integer"
3 | }
4 |
--------------------------------------------------------------------------------
/test/validator/issue418/options.yaml:
--------------------------------------------------------------------------------
1 | lint: true
2 | expectFailure: true
3 |
--------------------------------------------------------------------------------
/test/s2o-test/issue112/options.yaml:
--------------------------------------------------------------------------------
1 | patch: true
2 | rbname: x-codegen-request-body-name
--------------------------------------------------------------------------------
/test/s2o-test/issue117/options.yaml:
--------------------------------------------------------------------------------
1 | patch: true
2 | rbname: x-codegen-request-body-name
--------------------------------------------------------------------------------
/test/resolver/prevalidate/options.yaml:
--------------------------------------------------------------------------------
1 | resolve: true
2 | prevalidate: true
3 | patch: false
4 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "packages": [
3 | "packages/*"
4 | ],
5 | "version": "independent"
6 | }
7 |
--------------------------------------------------------------------------------
/packages/oas-kit-common/README.md:
--------------------------------------------------------------------------------
1 | # oas-kit-common
2 |
3 | Common utility functions for oas-kit
4 |
--------------------------------------------------------------------------------
/packages/reftools/.gitignore:
--------------------------------------------------------------------------------
1 | *.out
2 | t.*
3 | wip/
4 | node_modules/
5 | api/*
6 | .nyc_output
7 |
--------------------------------------------------------------------------------
/bin/updateCoverage.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cat coverage/lcov.info | node node_modules/coveralls/bin/coveralls.js
3 |
--------------------------------------------------------------------------------
/test/s2o-test/issue39/subdir1/subdir2/ok.yaml:
--------------------------------------------------------------------------------
1 | type: object
2 | properties:
3 | name:
4 | type: string
5 |
--------------------------------------------------------------------------------
/test/validator/invalidVersion/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 4.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 |
--------------------------------------------------------------------------------
/packages/reftools/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reftools",
3 | "version": "1.1.9",
4 | "lockfileVersion": 1
5 | }
6 |
--------------------------------------------------------------------------------
/bin/setflags.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | if [ "$TRAVIS_NODE_VERSION" -eq "4" ] ; then
3 | export nflags="--harmony"
4 | fi
5 | echo flags: $nflags
6 |
--------------------------------------------------------------------------------
/packages/oas-schema-walker/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-schema-walker",
3 | "version": "1.1.5",
4 | "lockfileVersion": 1
5 | }
6 |
--------------------------------------------------------------------------------
/test/s2o-test/minimal/openapi.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: 3.0.0
3 | info:
4 | version: 1.0.0
5 | title: Minimal valid OpenAPI document
6 | paths: {}
7 |
--------------------------------------------------------------------------------
/test/s2o-test/minimal/swagger.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | swagger: '2.0'
3 | info:
4 | version: 1.0.0
5 | title: Minimal valid OpenAPI document
6 | paths: {}
7 |
--------------------------------------------------------------------------------
/test/s2o-test/issue39/subdir1/test.yaml:
--------------------------------------------------------------------------------
1 | get:
2 | responses:
3 | 200:
4 | description: OK
5 | schema:
6 | $ref: ./subdir2/ok.yaml
7 |
--------------------------------------------------------------------------------
/test/s2o-test/issue102/schemas/ping.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "object",
3 | "properties": {
4 | "foo": {
5 | "type": "string"
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/test/s2o-test/issue39/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | version: 0.0.0
4 | title: Simple API
5 | paths:
6 | /test:
7 | $ref: ./subdir1/test.yaml
8 |
--------------------------------------------------------------------------------
/test/s2o-test/without-schemes/swagger.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | swagger: '2.0'
3 | info:
4 | version: 1.0.0
5 | title: Swagger 2.0 Without Scheme
6 | host: example.com
7 | paths: {}
8 |
--------------------------------------------------------------------------------
/test/resolver/issue196/SchemaDog.yaml:
--------------------------------------------------------------------------------
1 | type: object
2 | allOf:
3 | - $ref: "./Parameters.yaml#/parameter_colour/schema"
4 | - $ref: "./Parameters.yaml#/parameter_size/schema"
5 |
--------------------------------------------------------------------------------
/test/http2/simple/schema.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.2
2 | info:
3 | title: fragment
4 | version: 1.0.0
5 | paths: {}
6 | components:
7 | schemas:
8 | xyz:
9 | type: integer
10 |
--------------------------------------------------------------------------------
/test/s2o-test/without-schemes/openapi.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: 3.0.0
3 | servers:
4 | - url: "//example.com"
5 | info:
6 | version: 1.0.0
7 | title: Swagger 2.0 Without Scheme
8 | paths: {}
9 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | end_of_line = lf
5 | indent_style = space
6 | indent_size = 4
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 |
--------------------------------------------------------------------------------
/test/resolver/issue196/SchemaAnimal.yaml:
--------------------------------------------------------------------------------
1 | type: object
2 | properties:
3 | colour:
4 | $ref: "./Parameters.yaml#/parameter_colour/schema"
5 | size:
6 | $ref: "./Parameters.yaml#/parameter_size/schema"
7 |
--------------------------------------------------------------------------------
/test/resolver/prevalidate/include.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: ''
4 | title: ''
5 | paths: {}
6 | responses: {}
7 | components:
8 | schemas:
9 | xyz:
10 | type: 'integer'
11 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy 141/swagger.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | swagger: '2.0'
3 | info:
4 | version: 1.0.0
5 | title: Swagger 2.0 Without Scheme
6 | paths: {}
7 | definitions:
8 | test:
9 | $ref: include.yaml
10 |
--------------------------------------------------------------------------------
/test/s2o-test/!missing-ref/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 |
--------------------------------------------------------------------------------
/test/resolver/issue282/pet.yaml:
--------------------------------------------------------------------------------
1 | type: object
2 | required:
3 | - id
4 | - name
5 | properties:
6 | id:
7 | type: integer
8 | format: int64
9 | name:
10 | type: string
11 | tag:
12 | type: string
--------------------------------------------------------------------------------
/test/resolver/speccy 141/output.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: '3.0.0'
3 | info:
4 | version: 1.0.0
5 | title: OpenAPI 3.0 spaces test
6 | paths: {}
7 | components:
8 | schemas:
9 | test:
10 | type: string
11 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy 141/openapi.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: 3.0.0
3 | info:
4 | version: 1.0.0
5 | title: Swagger 2.0 Without Scheme
6 | paths: {}
7 | components:
8 | schemas:
9 | test:
10 | type: string
11 |
--------------------------------------------------------------------------------
/test/s2o-test/without-schemes-with-base-path/openapi.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: 3.0.0
3 | servers:
4 | - url: "//example.com/api"
5 | info:
6 | version: 1.0.0
7 | title: Swagger 2.0 Without Scheme with Base Path
8 | paths: {}
9 |
--------------------------------------------------------------------------------
/test/s2o-test/without-schemes-with-base-path/swagger.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | swagger: '2.0'
3 | info:
4 | version: 1.0.0
5 | title: Swagger 2.0 Without Scheme with Base Path
6 | host: example.com
7 | basePath: "/api"
8 | paths: {}
9 |
--------------------------------------------------------------------------------
/test/resolver/speccy 141/input.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: '3.0.0'
3 | info:
4 | version: 1.0.0
5 | title: OpenAPI 3.0 spaces test
6 | paths: {}
7 | components:
8 | schemas:
9 | test:
10 | $ref: include.yaml
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | node_modules/
3 | in/
4 | dist/
5 | test/s2o-test/_*/
6 | .vscode
7 | utils/
8 | packages/oas-validator/schemas/henry*
9 | packages/oas-repair/*
10 | test/oas-repair*
11 | .project
12 | docs/bundling.md
13 |
--------------------------------------------------------------------------------
/packages/reftools/lib/isref.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | function isRef(obj,key) {
4 | return ((key === '$ref') && (!!obj && typeof obj[key] === 'string'));
5 | }
6 |
7 | module.exports = {
8 | isRef: isRef
9 | };
10 |
11 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-remove/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths: {}
6 | definitions:
7 | a:
8 | $ref: '#/definitions/b'
9 | description: a
10 | b:
11 | type: integer
12 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-preserve/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths: {}
6 | definitions:
7 | a:
8 | $ref: '#/definitions/b'
9 | description: a
10 | b:
11 | type: integer
12 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-remove/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths: {}
6 | components:
7 | schemas:
8 | a:
9 | $ref: '#/components/schemas/b'
10 | b:
11 | type: integer
12 |
--------------------------------------------------------------------------------
/test/s2o-test/issue102/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /ping:
7 | $ref: "endpoints/ping.yaml#/paths/~1ping"
8 | definitions:
9 | ping:
10 | $ref: 'schemas/ping.json'
11 |
--------------------------------------------------------------------------------
/test/s2o-test/pull348-trailing-slash/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | servers:
6 | - url: https://example.com
7 | paths:
8 | /:
9 | get:
10 | responses:
11 | '200':
12 | description: OK
13 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-preserve/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths: {}
6 | components:
7 | schemas:
8 | a:
9 | $ref: '#/components/schemas/b'
10 | description: a
11 | b:
12 | type: integer
13 |
--------------------------------------------------------------------------------
/test/s2o-test/!missing-ref/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: 2.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths:
6 | /:
7 | get:
8 | parameters:
9 | - $ref: '#/parameters/notthere'
10 | responses:
11 | '200':
12 | description: OK
13 |
--------------------------------------------------------------------------------
/test/s2o-test/issue102/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /ping:
7 | $ref: "endpoints/ping.yaml#/paths/~1ping"
8 | components:
9 | schemas:
10 | ping:
11 | $ref: 'schemas/ping.json'
12 |
--------------------------------------------------------------------------------
/test/s2o-test/pull348-trailing-slash/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: 2.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | basePath: /
6 | host: example.com
7 | schemes:
8 | - https
9 | paths:
10 | /:
11 | get:
12 | responses:
13 | '200':
14 | description: OK
15 |
--------------------------------------------------------------------------------
/packages/swagger2openapi/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:dubnium-alpine
2 | LABEL maintainer="mike.ralphson@gmail.com" description="Swagger to OpenAPI"
3 | ENV NODE_ENV=production
4 |
5 | WORKDIR /usr/src/app
6 |
7 | # install the app
8 | RUN npm i -g swagger2openapi
9 |
10 | CMD [ "swagger2openapi", "--help" ]
11 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51a/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: 2.0
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 |
6 | paths:
7 |
8 | /health/all.json:
9 | get:
10 | responses:
11 | 200:
12 | description: OK
13 | schema:
14 | $ref: ../include/health.yml#/Result
15 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy249/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | version: 1.0.0
4 | title: API
5 | produces:
6 | - 'application/vnd.api+json'
7 | paths:
8 | /:
9 | get:
10 | responses:
11 | '200':
12 | description: OK
13 | schema:
14 | $ref: ./xyz.json
15 |
--------------------------------------------------------------------------------
/test/s2o-test/include/health.yml:
--------------------------------------------------------------------------------
1 | Check:
2 | title: Check
3 | type: object
4 | properties:
5 | message:
6 | type: string
7 | description: "bla"
8 |
9 | Result:
10 | type: object
11 | properties:
12 | default:
13 | $ref: '#/Check'
14 | database:
15 | $ref: '#/Check'
16 |
--------------------------------------------------------------------------------
/test/http2/simple/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | type: 'integer'
15 |
--------------------------------------------------------------------------------
/test/resolver/issue196/Parameters.yaml:
--------------------------------------------------------------------------------
1 | parameter_colour:
2 | name: parameter_colour
3 | description: Colour
4 | in: query
5 | required: true
6 | schema:
7 | type: string
8 | parameter_size:
9 | name: parameter_size
10 | in: query
11 | description: Size
12 | required: true
13 | schema:
14 | type: string
15 |
--------------------------------------------------------------------------------
/test/resolver/speccy249/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | type: 'integer'
15 |
--------------------------------------------------------------------------------
/test/s2o-test/issue164/swagger.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | swagger: '2.0'
3 | info:
4 | version: 1.0.0
5 | title: Swagger 2.0 With Example
6 | produces:
7 | - application/json
8 | paths:
9 | /:
10 | get:
11 | responses:
12 | '200':
13 | description: OK
14 | schema:
15 | example: null
16 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy249/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | type: 'integer'
15 |
--------------------------------------------------------------------------------
/test/resolver/prevalidate/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | type: 'integer'
15 |
--------------------------------------------------------------------------------
/test/resolver/speccy249/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | $ref: include/xyz.json
15 |
--------------------------------------------------------------------------------
/test/s2o-test/issue102/endpoints/ping.yaml:
--------------------------------------------------------------------------------
1 | paths:
2 | '/ping':
3 | get:
4 | responses:
5 | '200':
6 | description: OK
7 | content:
8 | application/json:
9 | schema:
10 | $ref: '../openapi.yaml#/components/schemas/ping'
11 |
--------------------------------------------------------------------------------
/test/s2o-test/issue164/openapi.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | openapi: 3.0.0
3 | info:
4 | version: 1.0.0
5 | title: Swagger 2.0 With Example
6 | paths:
7 | /:
8 | get:
9 | responses:
10 | '200':
11 | description: OK
12 | content:
13 | application/json:
14 | schema:
15 | example: null
16 |
--------------------------------------------------------------------------------
/test/s2o-test/issue6/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: 2.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths:
6 | /:
7 | get:
8 | parameters:
9 | - name: indexer
10 | in: body
11 | required: true
12 | schema:
13 | type: object
14 | responses:
15 | '200':
16 | description: OK
17 |
--------------------------------------------------------------------------------
/test/s2o-test/issue41/swagger.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | swagger: '2.0'
3 | info:
4 | title: Test
5 | version: ''
6 | paths:
7 | "/test":
8 | get:
9 | responses:
10 | '200':
11 | description: OK
12 | schema:
13 | "$ref": "#/definitions/Def%20with%20space"
14 | definitions:
15 | Def with space:
16 | type: string
17 |
--------------------------------------------------------------------------------
/test/s2o-test/issue6/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | requestBody:
12 | content:
13 | application/json:
14 | schema:
15 | type: object
16 | required: true
17 |
--------------------------------------------------------------------------------
/test/resolver/prevalidate/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | $ref: './include.yaml#/components/schemas/xyz'
15 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51b/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: 2.0
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | paths:
6 | /health/all.json:
7 | get:
8 | responses:
9 | 200:
10 | description: OK
11 | schema:
12 | $ref: '#/definitions/health'
13 | definitions:
14 | health:
15 | $ref: ../include/health.yml#/Result
16 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy286/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | version: 1.0.0
4 | title: Example
5 | produces:
6 | - application/json
7 | paths:
8 | /pets:
9 | get:
10 | responses:
11 | '200':
12 | description: Example
13 | schema:
14 | type: number
15 | x-nullable: true
16 | default: null
17 |
--------------------------------------------------------------------------------
/test/http2/simple/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | $ref: 'https://localhost:8321/simple/schema.yaml#/components/schemas/xyz'
15 |
--------------------------------------------------------------------------------
/packages/oas-linter/README.md:
--------------------------------------------------------------------------------
1 | # oas-linter
2 |
3 | This is a plugin for [oas-validator](https://github.com/mermade/oas-kit) which implements a simple linter using a [DSL](https://mermade.github.io/oas-kit/linter-rules.html) and a set of [default rules](https://mermade.github.io/oas-kit/default-rules.html).
4 |
5 | See here for complete [documentation](/docs/options.md) of the `options` object.
6 |
7 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | First of all, many thanks for considering making a contribution to this project.
4 |
5 | # Submitting PRs
6 |
7 | Please run the tests before submitting your pull request.
8 |
9 | * `npm run lint`
10 | * `npm test`
11 |
12 | # Known issues
13 | [GitHub search](https://github.com/Mermade/oas-kit/search?utf8=%E2%9C%93&q=fixme+language%3Ajavascript&type=)
14 |
--------------------------------------------------------------------------------
/test/resolver/simple/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | type: 'integer'
15 | components:
16 | schemas:
17 | xyz:
18 | type: 'integer'
19 |
--------------------------------------------------------------------------------
/test/s2o-test/issue70/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | version: ""
4 | title: ""
5 | paths: {}
6 | definitions:
7 | Pet:
8 | type: object
9 | properties:
10 | petType:
11 | type: string
12 | x-discriminator:
13 | propertyName: petType
14 | mapping:
15 | dog: Hound
16 | cat: '#/definitions/Feline'
17 | Hound: {}
18 | Feline: {}
19 |
--------------------------------------------------------------------------------
/test/s2o-test/speccy286/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: "3.0.0"
2 | info:
3 | version: 1.0.0
4 | title: Example
5 | paths:
6 | /pets:
7 | get:
8 | responses:
9 | '200':
10 | description: Example
11 | content:
12 | application/json:
13 | schema:
14 | type: number
15 | nullable: true
16 | default: null
17 |
--------------------------------------------------------------------------------
/test/validator/speccy286/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: "3.0.0"
2 | info:
3 | version: 1.0.0
4 | title: Example
5 | paths:
6 | /pets:
7 | get:
8 | responses:
9 | '200':
10 | description: Example
11 | content:
12 | application/json:
13 | schema:
14 | type: number
15 | nullable: true
16 | default: null
17 |
--------------------------------------------------------------------------------
/test/resolver/simple/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | /:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/vnd.api+json:
13 | schema:
14 | $ref: '#/components/schemas/xyz'
15 | components:
16 | schemas:
17 | xyz:
18 | type: 'integer'
19 |
--------------------------------------------------------------------------------
/test/s2o-test/issue39/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 0.0.0
4 | title: Simple API
5 | paths:
6 | /test:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | '*/*':
13 | schema:
14 | type: object
15 | properties:
16 | name:
17 | type: string
18 |
--------------------------------------------------------------------------------
/test/validator/escapedRef/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.3
2 | info:
3 | title: API
4 | version: 1.0.0
5 | contact:
6 | name: example.com
7 | email: foo@bar.com
8 | url: https://foobar.com
9 | tags:
10 | - name: tag
11 | description: A tag
12 | paths:
13 | x-foo/bar:
14 | get:
15 | responses:
16 | '200':
17 | description: OK
18 | /test:
19 | $ref: '#/paths/x-foo~1bar'
20 |
--------------------------------------------------------------------------------
/test/s2o-test/issue70/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: "3.0.0"
2 | info:
3 | version: ""
4 | title: ""
5 | paths: {}
6 | components:
7 | schemas:
8 | Pet:
9 | type: object
10 | properties:
11 | petType:
12 | type: string
13 | discriminator:
14 | propertyName: petType
15 | mapping:
16 | dog: Hound
17 | cat: '#/components/schemas/Feline'
18 | Hound: {}
19 | Feline: {}
20 |
--------------------------------------------------------------------------------
/test/resolver/issue152/responses.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: '1.0'
4 | title: Common Response schemas
5 | description: Response definitions commonly used in API-docs in a separate reference file
6 | paths: {}
7 | components:
8 | responses:
9 | Post201:
10 | description: Success post
11 | content:
12 | application/json:
13 | schema:
14 | $ref: 'schemas.yaml#/components/schemas/xyz'
15 |
--------------------------------------------------------------------------------
/bin/jsdocToMarkdown.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo '# OAS-Schema-Walker' > packages/oas-schema-walker/README.md
4 | echo '' >> echo '# OAS-Schema-Walker' > packages/oas-schema-walker/README.md
5 | npx jsdoc-to-markdown packages/oas-schema-walker/index.js >> packages/oas-schema-walker/README.md
6 |
7 | echo '# RefTools' > packages/reftools/README.md
8 | echo '' >> packages/reftools/README.md
9 | npx jsdoc-to-markdown packages/reftools/lib/*.js >> packages/reftools/README.md
10 |
11 |
--------------------------------------------------------------------------------
/packages/oas-kit-common/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-kit-common",
3 | "version": "1.0.8",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "fast-safe-stringify": {
8 | "version": "2.0.7",
9 | "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz",
10 | "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA=="
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/packages/oas-resolver/README.md:
--------------------------------------------------------------------------------
1 | # oas-resolver
2 |
3 | ## Usage
4 |
5 | ```js
6 | const yaml = require('yaml');
7 | const input = yaml.parse(str);
8 | const source = url; // or filename
9 | resolver.resolve(input,source,options)
10 | .then(function(options){
11 | fs.writeFileSync(outputFile,yaml.stringify(options.openapi),'utf8');
12 | })
13 | .catch(function(ex){
14 | // ...
15 | });
16 | ```
17 |
18 | See here for complete [documentation](/docs/options.md) of the `options` object.
19 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-allOf/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | title: API
4 | version: 1.0.0
5 | parameters:
6 | c:
7 | name: c
8 | in: query
9 | type: string
10 | paths:
11 | '/':
12 | get:
13 | parameters:
14 | - $ref: '#/parameters/c'
15 | description: c
16 | responses:
17 | default:
18 | description: OK
19 | definitions:
20 | a:
21 | $ref: '#/definitions/b'
22 | description: a
23 | b:
24 | type: integer
25 |
--------------------------------------------------------------------------------
/test/resolver/issue152/schemas.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: '1.0'
4 | title: Common Message/JSON schemas
5 | description: Message schemas / JSON datatypes commonly used in API-docs in a separate reference file
6 | paths: {}
7 | components:
8 | schemas:
9 | xyz:
10 | title: XYZ
11 | description: this is xyz
12 | type: object
13 | properties:
14 | id:
15 | description: the local identifier (not necessarily globally unique)
16 | type: string
17 |
--------------------------------------------------------------------------------
/packages/swagger2openapi/lib/statusCodes.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const http = require('http');
4 |
5 | const ours = {
6 | "default": "Default response",
7 | "1XX": "Informational",
8 | "103": "Early hints", // not in Node < 10
9 | "2XX": "Successful",
10 | "3XX": "Redirection",
11 | "4XX": "Client Error",
12 | "5XX": "Server Error",
13 | "7XX": "Developer Error" // April fools RFC
14 | };
15 |
16 | module.exports = {
17 | statusCodes: Object.assign({},ours,http.STATUS_CODES)
18 | };
19 |
20 |
--------------------------------------------------------------------------------
/test/resolver/speccy420/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.2
2 | info:
3 | title: api
4 | description: |
5 | description!
6 | contact:
7 | name: 'team'
8 | url: 'https://test.com/'
9 | email: 'test@test.com'
10 | version: 0.0.1
11 | servers:
12 | - url: https://test.com
13 | paths: {}
14 | components:
15 | responses:
16 | Request:
17 | description: request
18 | content:
19 | application/json:
20 | schema:
21 | $ref: temp.json#/definitions/person
22 | tags: []
23 |
24 |
--------------------------------------------------------------------------------
/test/resolver/issue196/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: Resolve Test
4 | version: 1.0.0
5 | paths:
6 | /pets:
7 | get:
8 | parameters:
9 | - $ref: "./Parameters.yaml#/parameter_colour"
10 | - $ref: "./Parameters.yaml#/parameter_size"
11 | responses:
12 | '200':
13 | description: OK
14 | components:
15 | parameters:
16 | $ref: './Parameters.yaml'
17 | schemas:
18 | Cat:
19 | $ref: './SchemaAnimal.yaml'
20 | Dog:
21 | $ref: './SchemaAnimal.yaml'
22 |
--------------------------------------------------------------------------------
/test/resolver/speccy420/temp.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-07/schema#",
3 | "definitions": {
4 | "person": {
5 | "type": "object",
6 | "properties": {
7 | "name": { "type": "string" },
8 | "children": {
9 | "type": "array",
10 | "items": { "$ref": "#/definitions/person" },
11 | "default": []
12 | }
13 | }
14 | }
15 | },
16 | "type": "object",
17 | "properties": {
18 | "person": { "$ref": "#/definitions/person" }
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/test/s2o-test/issue130-allOf/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths:
6 | '/':
7 | get:
8 | parameters:
9 | - $ref: '#/components/parameters/c'
10 | responses:
11 | default:
12 | description: OK
13 | components:
14 | schemas:
15 | a:
16 | allOf:
17 | - $ref: '#/components/schemas/b'
18 | - description: a
19 | b:
20 | type: integer
21 | parameters:
22 | c:
23 | name: c
24 | in: query
25 | schema:
26 | type: string
27 |
--------------------------------------------------------------------------------
/test/s2o-test/issue201/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | description: |
6 | This call returns all payment accounts that are relevant the PSU on behalf of whom the AISP is connected.
7 | Thanks to HYPERMEDIA, each account is returned with the links aiming to ease access to the relevant transactions and balances.
8 | The result may be subject to pagination (i.e. retrieving a partial result in case of having too many results) through a set of pages by the ASPSP. Thereafter, the AISP may ask for the first, next, previous or last page of results.
9 | paths: {}
10 |
--------------------------------------------------------------------------------
/test/s2o-test/issue201/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | title: API
4 | version: 1.0.0
5 | description: |
6 | This call returns all payment accounts that are relevant the PSU on behalf of whom the AISP is connected.
7 | Thanks to HYPERMEDIA, each account is returned with the links aiming to ease access to the relevant transactions and balances.
8 | The result may be subject to pagination (i.e. retrieving a partial result in case of having too many results) through a set of pages by the ASPSP. Thereafter, the AISP may ask for the first, next, previous or last page of results.
9 | paths: {}
10 |
--------------------------------------------------------------------------------
/packages/reftools/lib/findObj.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const recurse = require('./recurse.js').recurse;
4 |
5 | function findObj(container,obj) {
6 | if (container === obj) {
7 | return { found: true, path: '#/', parent: null };
8 | }
9 | let result = { found: false, path: null, parent: null };
10 | recurse(container,{},function(o,key,state){
11 | if ((o[key] === obj) && (!result.found)) {
12 | result = { found: true, path: state.path, parent: o };
13 | }
14 | });
15 | return result;
16 | }
17 |
18 | module.exports = {
19 | findObj: findObj
20 | };
21 |
22 |
--------------------------------------------------------------------------------
/webpack.reftools.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const webpack = require('webpack');
4 |
5 | module.exports = {
6 | mode: 'production',
7 | plugins: [
8 | ],
9 | resolve: {
10 | fallback: {
11 | fs: false
12 | }
13 | },
14 | entry: {
15 | recurse: './packages/reftools/lib/recurse.js',
16 | clone: './packages/reftools/lib/clone.js',
17 | deref: './packages/reftools/lib/dereference.js',
18 | reref: './packages/reftools/lib/reref.js'
19 | },
20 | output: {
21 | filename: '[name].min.js',
22 | libraryTarget: 'umd'
23 | }
24 | };
25 |
--------------------------------------------------------------------------------
/test/resolver/issue152/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | tags:
6 | - name: test
7 | description: a test tag
8 | paths:
9 | /foo:
10 | post:
11 | operationId: postFoo
12 | summary: Super post op
13 | tags:
14 | - test
15 | responses:
16 | '201':
17 | $ref: 'responses.yaml#/components/responses/Post201'
18 | /bar:
19 | post:
20 | operationId: postBar
21 | summary: Super post op
22 | tags:
23 | - test
24 | responses:
25 | '201':
26 | $ref: 'responses.yaml#/components/responses/Post201'
27 |
--------------------------------------------------------------------------------
/test/s2o-test/issue202/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: API
4 | version: 1.0.0
5 | description: |
6 | ### Description
7 | This call returns all payment accounts that are relevant the PSU on behalf of whom the AISP is connected.
8 | Thanks to HYPERMEDIA, each account is returned with the links aiming to ease access to the relevant transactions and balances.
9 | The result may be subject to pagination (i.e. retrieving a partial result in case of having too many results) through a set of pages by the ASPSP. Thereafter, the AISP may ask for the first, next, previous or last page of results.
10 | paths: {}
11 |
--------------------------------------------------------------------------------
/test/s2o-test/issue202/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | title: API
4 | version: 1.0.0
5 | description: |
6 | ### Description
7 | This call returns all payment accounts that are relevant the PSU on behalf of whom the AISP is connected.
8 | Thanks to HYPERMEDIA, each account is returned with the links aiming to ease access to the relevant transactions and balances.
9 | The result may be subject to pagination (i.e. retrieving a partial result in case of having too many results) through a set of pages by the ASPSP. Thereafter, the AISP may ask for the first, next, previous or last page of results.
10 | paths: {}
11 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51c/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | paths:
6 | "/test":
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | schema:
12 | type: object
13 | properties:
14 | default:
15 | title: Check
16 | type: object
17 | properties:
18 | message:
19 | type: string
20 | description: bla
21 | database:
22 | "$ref": "#/paths/~1test/get/responses/200/schema/properties/default"
23 |
--------------------------------------------------------------------------------
/test/s2o-test/!issue79/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | '/v3/companies/{company_id}/seats/{uuid}':
7 | parameters:
8 | - name: company_id
9 | in: path
10 | description: Company UUID
11 | example: 6bc8bb80-1e32-0136-eb32-0242ac11530c
12 | type: string
13 | format: UUID
14 | required: true
15 | - name: uuid
16 | in: query
17 | description: User UUID
18 | example: '123456'
19 | type: string
20 | format: uuid
21 | required: true
22 | get:
23 | responses:
24 | '200':
25 | description: OK
26 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51d/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | produces:
6 | - application/json
7 | - text/xml
8 | paths:
9 | "/test":
10 | get:
11 | responses:
12 | '200':
13 | description: OK
14 | schema:
15 | type: object
16 | properties:
17 | default:
18 | title: Check
19 | type: object
20 | properties:
21 | message:
22 | type: string
23 | description: bla
24 | database:
25 | "$ref": "#/paths/~1test/get/responses/200/schema/properties/default"
26 |
--------------------------------------------------------------------------------
/test/s2o-test/!issue79/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | paths:
6 | '/v3/companies/{company_id}/seats/{uuid}':
7 | parameters:
8 | - name: company_id
9 | in: path
10 | description: Company UUID
11 | example: 6bc8bb80-1e32-0136-eb32-0242ac11530c
12 | schema:
13 | type: string
14 | format: UUID
15 | required: true
16 | - name: uuid
17 | in: query
18 | description: User UUID
19 | example: '123456'
20 | schema:
21 | type: string
22 | format: uuid
23 | required: true
24 | get:
25 | responses:
26 | '200':
27 | description: OK
28 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51b/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | paths:
6 | /health/all.json:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | '*/*':
13 | schema:
14 | $ref: '#/components/schemas/health'
15 | components:
16 | schemas:
17 | health:
18 | type: object
19 | properties:
20 | default:
21 | title: Check
22 | type: object
23 | properties:
24 | message:
25 | type: string
26 | description: bla
27 | database:
28 | $ref: '#/components/schemas/health/properties/default'
29 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51c/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | paths:
6 | /test:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | '*/*':
13 | schema:
14 | type: object
15 | properties:
16 | default:
17 | $ref: '#/components/schemas/schema1'
18 | database:
19 | $ref: '#/components/schemas/schema1'
20 | components:
21 | schemas:
22 | schema1:
23 | title: Check
24 | type: object
25 | properties:
26 | message:
27 | type: string
28 | description: bla
29 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51a/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | paths:
6 | /health/all.json:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | '*/*':
13 | schema:
14 | type: object
15 | properties:
16 | default:
17 | $ref: '#/components/schemas/Check'
18 | database:
19 | $ref: '#/components/schemas/Check'
20 | components:
21 | schemas:
22 | Check:
23 | title: Check
24 | type: object
25 | properties:
26 | message:
27 | type: string
28 | description: bla
29 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## swagger2openapi v7.0 and oas-validator v5.0
4 |
5 | * remove use of `ajv` for fallback schema validation
6 |
7 | ## swagger2openapi v6.1.0 and oas-resolver v2.4.0
8 |
9 | New properties on the `options` object:
10 |
11 | * `fetch` - to override the built-in `fetch` function
12 | * `fetchOptions` - additional options to be passed to the `fetch` function
13 |
14 | ## swagger2openapi v6.0.0 and oas-validator v4.0.0
15 |
16 | * Converter will now error out if passed in input containing YAML anchors/aliases. To bypass this check, pass the `--anchors` option or set `options.anchors` to `true`.
17 | * Validator method `validateSync` has now been renamed `validateInner` as it (still) returns a Promise or calls a given callback.
18 |
--------------------------------------------------------------------------------
/packages/oas-kit-common/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-kit-common",
3 | "version": "1.0.8",
4 | "description": "Common utility functions for oas-kit",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [
10 | "openapi",
11 | "swagger",
12 | "oas",
13 | "utility"
14 | ],
15 | "author": "Mike Ralphson",
16 | "dependencies": {
17 | "fast-safe-stringify": "^2.0.7"
18 | },
19 | "license": "BSD-3-Clause",
20 | "repository": {
21 | "type": "git",
22 | "url": "https://github.com/Mermade/oas-kit.git"
23 | },
24 | "bugs": {
25 | "url": "https://github.com/mermade/oas-kit/issues"
26 | },
27 | "gitHead": "da527220c78530e836c33f77178493aab93d385c"
28 | }
29 |
--------------------------------------------------------------------------------
/packages/oas-schema-walker/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-schema-walker",
3 | "version": "1.1.5",
4 | "description": "Library to walk OAS 3 schema objects and call a callback",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "funding": "https://github.com/Mermade/oas-kit?sponsor=1",
10 | "keywords": [
11 | "openapi",
12 | "swagger",
13 | "oas",
14 | "schema",
15 | "json-schema"
16 | ],
17 | "author": "Mike Ralphson",
18 | "license": "BSD-3-Clause",
19 | "repository": {
20 | "type": "git",
21 | "url": "https://github.com/Mermade/oas-kit.git"
22 | },
23 | "bugs": {
24 | "url": "https://github.com/mermade/oas-kit/issues"
25 | },
26 | "gitHead": "da527220c78530e836c33f77178493aab93d385c"
27 | }
28 |
--------------------------------------------------------------------------------
/packages/oas-linter/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-linter",
3 | "version": "3.2.2",
4 | "description": "Default linter plugin for oas-validator",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "funding": "https://github.com/Mermade/oas-kit?sponsor=1",
10 | "keywords": [
11 | "openapi",
12 | "oas",
13 | "lint",
14 | "linter"
15 | ],
16 | "author": "Mike Ralphson",
17 | "license": "BSD-3-Clause",
18 | "dependencies": {
19 | "@exodus/schemasafe": "^1.0.0-rc.2",
20 | "should": "^13.2.1",
21 | "yaml": "^1.10.0"
22 | },
23 | "repository": {
24 | "type": "git",
25 | "url": "https://github.com/Mermade/oas-kit.git"
26 | },
27 | "bugs": {
28 | "url": "https://github.com/mermade/oas-kit/issues"
29 | },
30 | "gitHead": "da527220c78530e836c33f77178493aab93d385c"
31 | }
32 |
--------------------------------------------------------------------------------
/docs/default-rules.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | # OAS-Kit Default Linter Rules
4 |
5 |
6 |
7 |
8 | | Name |
9 | OpenAPI Object |
10 | Description |
11 |
12 |
13 |
14 | {% for rule in site.data.defaultrules.default %}
15 |
16 | |
17 | {{ rule.name }}
18 | |
19 |
20 | {% if rule.object == "*" %}
21 | everything
22 | {% else %}
23 | {{ rule.object }}
24 | {% endif %}
25 | |
26 | {{ rule.description }} |
27 |
28 |
31 | {% endfor %}
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/test/s2o-test/issue41/openapi.yaml:
--------------------------------------------------------------------------------
1 | {
2 | "openapi": "3.0.0",
3 | "info": {
4 | "title": "Test",
5 | "version": ""
6 | },
7 | "paths": {
8 | "/test": {
9 | "get": {
10 | "responses": {
11 | "200": {
12 | "description": "OK",
13 | "content": {
14 | "*/*": {
15 | "schema": {
16 | "$ref": "#/components/schemas/Def_with_space"
17 | }
18 | }
19 | }
20 | }
21 | }
22 | }
23 | }
24 | },
25 | "components": {
26 | "schemas": {
27 | "Def_with_space": {
28 | "type": "string"
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/packages/oas-validator/README.md:
--------------------------------------------------------------------------------
1 | # oas-validator
2 |
3 | Usage:
4 |
5 | ```javascript
6 | const validator = require('oas-validator');
7 | const options = {};
8 | validator.validate(openapi, options)
9 | .then(function(options){
10 | // options.valid contains the result of the validation, true in this branch
11 | })
12 | .catch(function(err){
13 | console.warn(err.message);
14 | if (options.context) console.warn('Location',options.context.pop());
15 | });
16 | ```
17 |
18 | If a third `callback` argument to `validate` is provided, the callback will be called instead of a Promise being returned.
19 |
20 | `oas-validator` is an assertion-based validator, which stops on the first error, as structural errors may otherwise cause further (spurious) errors to be reported. If the `lint` option is set, multiple `warnings` may be reported.
21 |
22 | See here for complete [documentation](/docs/options.md) of the `options` object.
23 |
--------------------------------------------------------------------------------
/packages/reftools/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reftools",
3 | "version": "1.1.9",
4 | "description": "Utility functions to deal with references in objects",
5 | "main": "lib/recurse.js",
6 | "scripts": {},
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/Mermade/oas-kit.git"
10 | },
11 | "funding": "https://github.com/Mermade/oas-kit?sponsor=1",
12 | "keywords": [
13 | "json-reference",
14 | "json-pointer",
15 | "object",
16 | "objects",
17 | "circular",
18 | "reference",
19 | "dereference",
20 | "clone",
21 | "flatten",
22 | "recurse",
23 | "recursion",
24 | "iterate",
25 | "iteration",
26 | "traverse",
27 | "traversal",
28 | "visitor"
29 | ],
30 | "author": "Mike Ralphson",
31 | "license": "BSD-3-Clause",
32 | "bugs": {
33 | "url": "https://github.com/mermade/oas-kit/issues"
34 | },
35 | "homepage": "https://github.com/mermade/oas-kit#readme"
36 | }
37 |
--------------------------------------------------------------------------------
/test/s2o-test/issue189/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | title: Sample with query parameter without collectionFormat
4 | version: '1.0'
5 | host: haible.de
6 | basePath: /bruno/ibm
7 | schemes:
8 | - https
9 | consumes:
10 | - application/json
11 | produces:
12 | - application/json
13 | paths:
14 | /system/group_membership:
15 | get:
16 | summary: Invoke the foo.
17 | operationId: getFoo
18 | produces:
19 | - application/json
20 | parameters:
21 | - name: users
22 | in: query
23 | description: foo
24 | required: true
25 | type: array
26 | items:
27 | type: string
28 | responses:
29 | '202':
30 | description: foo
31 | schema:
32 | type: object
33 | properties:
34 | description:
35 | type: string
36 | description: Details about the accepted request.
37 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | # Author: @MikeRalphson
4 | # Issue : n/a
5 | # Desc : This workflow runs a simple lint and test for a node.js project
6 |
7 | # run this on push to any branch and creation of pull-requests
8 | on: [push, pull_request]
9 |
10 | jobs:
11 | ci:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v1 # checkout repo content
15 | - uses: actions/setup-node@v1 # setup Node.js
16 | with:
17 | node-version: '14.x'
18 | - name: Audit top-level package-lock.json
19 | run: npx package-lock-audit ./package-lock.json
20 | - name: Audit package package-lock.json
21 | run: find packages -maxdepth 2 -name package-lock.json | xargs npx package-lock-audit
22 | - name: Install deps
23 | run: npm i
24 | - name: Lerna bootstrap
25 | run: npx lerna bootstrap --no-ci
26 | - name: Run lint
27 | run: npm run lint
28 | - name: Run tests
29 | run: npm run test
30 |
--------------------------------------------------------------------------------
/packages/swagger2openapi/.gitignore:
--------------------------------------------------------------------------------
1 | build.sh
2 | schemas/*gnostic*
3 | schemas/*diff*
4 | schemadev/
5 | .coveralls.yml
6 | *.txt
7 | *.out
8 | *.yaml
9 | *test.sh
10 | utils/
11 | in/
12 | out/
13 | dev/
14 | t/
15 |
16 | test/_*/
17 |
18 | # Logs
19 | logs
20 | *.log
21 | npm-debug.log*
22 |
23 | # Runtime data
24 | pids
25 | *.pid
26 | *.seed
27 |
28 | # Directory for instrumented libs generated by jscoverage/JSCover
29 | lib-cov
30 |
31 | # Coverage directory used by tools like istanbul
32 | coverage
33 |
34 | # nyc test coverage
35 | .nyc_output
36 |
37 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
38 | .grunt
39 |
40 | # node-waf configuration
41 | .lock-wscript
42 |
43 | # Compiled binary addons (http://nodejs.org/api/addons.html)
44 | build/Release
45 |
46 | # Dependency directories
47 | node_modules
48 | jspm_packages
49 |
50 | # Optional npm cache directory
51 | .npm
52 |
53 | # Optional REPL history
54 | .node_repl_history
55 |
--------------------------------------------------------------------------------
/test/resolver/issue152/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: 1.0.0
4 | title: API
5 | tags:
6 | - name: test
7 | description: a test tag
8 | paths:
9 | /foo:
10 | post:
11 | operationId: postFoo
12 | summary: Super post op
13 | tags:
14 | - test
15 | responses:
16 | '201':
17 | description: Success post
18 | content:
19 | application/json:
20 | schema:
21 | title: XYZ
22 | description: this is xyz
23 | type: object
24 | properties:
25 | id:
26 | description: the local identifier (not necessarily globally unique)
27 | type: string
28 | /bar:
29 | post:
30 | operationId: postBar
31 | summary: Super post op
32 | tags:
33 | - test
34 | responses:
35 | '201':
36 | $ref: '#/paths/~1foo/post/responses/201'
37 |
--------------------------------------------------------------------------------
/test/s2o-test/issue189/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: Sample with query parameter without collectionFormat
4 | version: "1.0"
5 | paths:
6 | /system/group_membership:
7 | get:
8 | summary: Invoke the foo.
9 | operationId: getFoo
10 | parameters:
11 | - name: users
12 | in: query
13 | description: foo
14 | required: true
15 | style: form
16 | explode: false
17 | schema:
18 | type: array
19 | items:
20 | type: string
21 | responses:
22 | "202":
23 | description: foo
24 | content:
25 | application/json:
26 | schema:
27 | type: object
28 | properties:
29 | description:
30 | type: string
31 | description: Details about the accepted request.
32 | servers:
33 | - url: https://haible.de/bruno/ibm
34 |
--------------------------------------------------------------------------------
/test/testreref.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | const util = require('util');
3 |
4 | const should = require('should');
5 | const reref = require('../packages/reftools/lib/reref.js').reref;
6 |
7 | const input = JSON.parse(`
8 | {
9 | "usage": {
10 | "one": {},
11 | "two": {}
12 | },
13 | "definitions": {
14 | "shared": {
15 | "container": "value"
16 | }
17 | }
18 | }
19 | `);
20 | input.usage.one = input.definitions.shared;
21 | input.usage.two = input.definitions.shared;
22 |
23 | describe('reref',function(){
24 | describe('simple',function(){
25 | it('should re-reference an object with identities',function(){
26 | let output = reref(input,{verbose:true});
27 | output.usage.one.container.should.equal('value');
28 | output.usage.two.should.have.property('$ref');
29 | output.usage.two.$ref.should.equal('#/usage/one');
30 | output.definitions.shared.$ref.should.equal('#/usage/one');
31 | });
32 | });
33 | });
34 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ### Checklist
4 |
5 |
6 |
7 | - [ ] Conversion: I have checked my source definition is valid OpenAPI 2.0
8 | - [ ] Conversion: On valid OpenAPI 2.0 input, the conversion looks wrong
9 | - [ ] Validation: I believe my source definition is valid OpenAPI 3.0.x but the validator complains
10 | - [ ] Validation: I believe my source definition is invalid OpenAPI 3.0.x but the validator does not complain
11 | - [ ] Linting issue
12 | - [ ] Resolver issue
13 |
14 |
17 |
18 | ### Detailed Description
19 |
20 |
21 |
22 | #### Other stuff
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/test/s2o-test/issue51d/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | version: '1.0'
4 | title: Demo API
5 | paths:
6 | /test:
7 | get:
8 | responses:
9 | '200':
10 | description: OK
11 | content:
12 | application/json:
13 | schema:
14 | type: object
15 | properties:
16 | default:
17 | $ref: '#/components/schemas/schema1'
18 | database:
19 | $ref: '#/components/schemas/schema1'
20 | text/xml:
21 | schema:
22 | type: object
23 | properties:
24 | default:
25 | $ref: '#/components/schemas/schema1'
26 | database:
27 | $ref: '#/components/schemas/schema1'
28 | components:
29 | schemas:
30 | schema1:
31 | title: Check
32 | type: object
33 | properties:
34 | message:
35 | type: string
36 | description: bla
37 |
--------------------------------------------------------------------------------
/packages/oas-validator/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-validator",
3 | "version": "5.0.8",
4 | "description": "Parser/validator for OpenAPI 3.x definitions",
5 | "main": "index.js",
6 | "funding": "https://github.com/Mermade/oas-kit?sponsor=1",
7 | "scripts": {
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [
11 | "openapi",
12 | "oas",
13 | "parser",
14 | "validator",
15 | "validation"
16 | ],
17 | "author": "Mike Ralphson",
18 | "license": "BSD-3-Clause",
19 | "dependencies": {
20 | "call-me-maybe": "^1.0.1",
21 | "oas-kit-common": "^1.0.8",
22 | "oas-linter": "^3.2.2",
23 | "oas-resolver": "^2.5.6",
24 | "oas-schema-walker": "^1.1.5",
25 | "reftools": "^1.1.9",
26 | "should": "^13.2.1",
27 | "yaml": "^1.10.0"
28 | },
29 | "repository": {
30 | "type": "git",
31 | "url": "https://github.com/Mermade/oas-kit.git"
32 | },
33 | "bugs": {
34 | "url": "https://github.com/mermade/oas-kit/issues"
35 | },
36 | "gitHead": "5cbeab49334ebe18c117764d086e1cfe7d708e97"
37 | }
38 |
--------------------------------------------------------------------------------
/docs/handlers.md:
--------------------------------------------------------------------------------
1 | # Protocol/Scheme handlers
2 |
3 | You can create your own protocol/[scheme](https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml)
4 | handlers for external references. You can also override the default `http:`, `https:` and `file:` handlers if necessary.
5 |
6 | Examples of custom scheme handlers might be `root:` or `parent:` for accessing the referring
7 | parts of the definition, or a `ssh:` handler for secure retrieval.
8 |
9 | ## Example
10 |
11 | ```javascript
12 | const util = require('util');
13 | const converter = require('./index.js');
14 |
15 | function cache(base,pointer,fragment,options) {
16 | if (options.verbose) console.log('Cache handler called',base,pointer,fragment);
17 | return new Promise(function(res,rej){
18 | res(...);
19 | });
20 | }
21 |
22 | converter.convertFile('./test.yaml',{
23 | handlers: { 'cache:': cache },
24 | resolve: true,
25 | source: './',
26 | verbose: true}, function(err,options){
27 | if (err) console.warn(util.inspect(err))
28 | else console.log(util.inspect(options.openapi));
29 | });
30 | ```
31 |
--------------------------------------------------------------------------------
/packages/oas-resolver/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "oas-resolver",
3 | "version": "2.5.6",
4 | "description": "Resolve external $refs in OpenAPI (swagger) 2.0 / 3.x definitions",
5 | "main": "index.js",
6 | "bin": {
7 | "resolve": "resolve.js"
8 | },
9 | "scripts": {
10 | "test": "echo \"Error: no test specified\" && exit 1"
11 | },
12 | "funding": "https://github.com/Mermade/oas-kit?sponsor=1",
13 | "keywords": [
14 | "openapi",
15 | "swagger",
16 | "oas",
17 | "resolver",
18 | "resolution",
19 | "ref",
20 | "json-pointer",
21 | "json-ref"
22 | ],
23 | "author": "Mike Ralphson",
24 | "license": "BSD-3-Clause",
25 | "dependencies": {
26 | "node-fetch-h2": "^2.3.0",
27 | "oas-kit-common": "^1.0.8",
28 | "reftools": "^1.1.9",
29 | "yaml": "^1.10.0",
30 | "yargs": "^17.0.1"
31 | },
32 | "repository": {
33 | "type": "git",
34 | "url": "https://github.com/Mermade/oas-kit.git"
35 | },
36 | "bugs": {
37 | "url": "https://github.com/mermade/oas-kit/issues"
38 | },
39 | "gitHead": "da527220c78530e836c33f77178493aab93d385c"
40 | }
41 |
--------------------------------------------------------------------------------
/test/resolver/speccy420/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.2
2 | info:
3 | title: api
4 | description: |
5 | description!
6 | contact:
7 | name: team
8 | url: https://test.com/
9 | email: test@test.com
10 | version: 0.0.1
11 | servers:
12 | - url: https://test.com
13 | paths: {}
14 | components:
15 | responses:
16 | Request:
17 | description: request
18 | content:
19 | application/json:
20 | schema:
21 | type: object
22 | properties:
23 | name:
24 | type: string
25 | children:
26 | type: array
27 | items:
28 | type: object
29 | properties:
30 | name:
31 | type: string
32 | children:
33 | type: array
34 | items:
35 | $ref: "#/components/responses/Request/content/application~1json/schema/properti\
36 | es/children/items"
37 | default: []
38 | default: []
39 | tags: []
40 |
--------------------------------------------------------------------------------
/test/s2o-test/issue76/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | title: API
4 | version: 1.0.0
5 | paths:
6 | /{p4}:
7 | get:
8 | parameters:
9 | - name: p1
10 | in: query
11 | type: array
12 | items:
13 | type: string
14 | collectionFormat: csv
15 | - name: p2
16 | in: query
17 | type: array
18 | items:
19 | type: string
20 | collectionFormat: multi
21 | - name: p3
22 | in: header
23 | type: array
24 | items:
25 | type: string
26 | collectionFormat: csv
27 | - name: p4
28 | in: path
29 | required: true
30 | type: array
31 | items:
32 | type: string
33 | collectionFormat: csv
34 | - name: p5
35 | in: query
36 | type: array
37 | items:
38 | type: string
39 | collectionFormat: ssv
40 | - name: p6
41 | in: query
42 | type: array
43 | items:
44 | type: string
45 | collectionFormat: pipes
46 | responses:
47 | default:
48 | description: OK
49 |
--------------------------------------------------------------------------------
/test/validator/issue418/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: A linting bug
4 | version: 1.0.0
5 | contact:
6 | name: vk342
7 | email: vk342@example.com
8 | url: https://example.com
9 | tags:
10 | - name: transactions
11 | description: Endpoints related to transactions
12 | paths:
13 | /transaction/{transactionId}:
14 | parameters:
15 | - $ref: '#/components/parameters/transactionIdParam'
16 | put:
17 | operationId: putTransaction
18 | description: Update a transaction...
19 | tags:
20 | - transactions
21 | requestBody:
22 | content:
23 | application/json:
24 | schema:
25 | #type: object
26 | properties:
27 | txnId:
28 | type: string
29 | description: Unique transactionID.
30 | responses:
31 | '201':
32 | description: Created
33 | components:
34 | parameters:
35 | transactionIdParam:
36 | name: transactionId
37 | in: path
38 | required: true
39 | description: An ID for the transaction
40 | schema:
41 | type: string
42 |
--------------------------------------------------------------------------------
/test/localhost.cert:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDCTCCAfGgAwIBAgIUXKBIJ3EHp2KNdRZa9sAt5g12kBYwDQYJKoZIhvcNAQEL
3 | BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTE5MDIxMTA5MTc1OFoXDTI5MDIw
4 | ODA5MTc1OFowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF
5 | AAOCAQ8AMIIBCgKCAQEAnP3gcvLdMBlamuZEn/zqWJKdhZBNzHHm8U8z+OJ7COBa
6 | GaeGEmJCjhYAIw/PvC4wYjkGVxnNyzqXayPxt9Ntg8Uayb9JY3BMnPi4pyMiwPTN
7 | 4J2s7gvP4P21c4+ldNYLik0y104EVEGQbC2BERtBnDUTlRW8QoZHzGCYD62CxPSx
8 | ODHyVPcY3a9E40E2Ec15OsTb7BVAvt8feuCeNrBBBJh4oZPlNh+1QaPi3vT8YD5p
9 | I6ZYPy+o9t9eBAsEAAq0Nky7I/6EG42M76kh9AlcS8tk/GJdP4M9PcZUdO/LaBxW
10 | Z2V6OoW03Xq+xQ+ESFCPpc9StEci2hnTXHhs4DG3EQIDAQABo1MwUTAdBgNVHQ4E
11 | FgQUcOdbMiFm9j+8DSnUHhuH3yOatlEwHwYDVR0jBBgwFoAUcOdbMiFm9j+8DSnU
12 | HhuH3yOatlEwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEATKk9
13 | j0RLX1nQPysdCQFlQPc9dzLkEl441tBKdUS/Uvj+dZIQegGyb4e3uLdt3JEpXNvS
14 | 690NQ502HDRrCW/KXLXbKpxQzY7Fhb2CR7pfsqoxVSn0lWOhDTdYIZ1x6sYtUGS5
15 | Aq+qEWotTGGRkfwybH1uzv2BKNDtKBXs4ajo85+sKL+GVxLMkKHqscO7E6hVL79u
16 | xPG5LfGprbleIUZn43AK8a2SkB+O2d/Z88JYlactfcDkRypqkhCWoHqwzoRq+kgo
17 | +em19N1Q3OkDHZhKoeZuoNX5qZpFkARX6j3f3V64hX3DDmiLc6oLAWAcP8qVo26q
18 | 05k9mdnFu7VhIVUxfA==
19 | -----END CERTIFICATE-----
20 |
--------------------------------------------------------------------------------
/test/resolver/issue196/output.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: Resolve Test
4 | version: 1.0.0
5 | paths:
6 | /pets:
7 | get:
8 | parameters:
9 | - name: parameter_colour
10 | description: Colour
11 | in: query
12 | required: true
13 | schema:
14 | type: string
15 | - name: parameter_size
16 | in: query
17 | description: Size
18 | required: true
19 | schema:
20 | type: string
21 | responses:
22 | '200':
23 | description: OK
24 | components:
25 | parameters:
26 | parameter_colour:
27 | name: parameter_colour
28 | description: Colour
29 | in: query
30 | required: true
31 | schema:
32 | type: string
33 | parameter_size:
34 | name: parameter_size
35 | in: query
36 | description: Size
37 | required: true
38 | schema:
39 | type: string
40 | schemas:
41 | Cat:
42 | type: object
43 | properties:
44 | size:
45 | type: string
46 | colour:
47 | type: string
48 | Dog:
49 | $ref: '#/components/schemas/Cat'
50 |
--------------------------------------------------------------------------------
/packages/reftools/lib/flatten.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const recurse = require('./recurse.js').recurse;
4 |
5 | /**
6 | * flattens an object into an array of properties
7 | * @param obj the object to flatten
8 | * @param callback a function which can mutate or filter the entries (by returning null)
9 | * @return the flattened object as an array of properties
10 | */
11 | function flatten(obj,callback) {
12 | let arr = [];
13 | let iDepth, oDepth = 0;
14 | let state = {identityDetection:true};
15 | recurse(obj,state,function(obj,key,state){
16 | let entry = {};
17 | entry.name = key;
18 | entry.value = obj[key];
19 | entry.path = state.path;
20 | entry.parent = obj;
21 | entry.key = key;
22 | if (callback) entry = callback(entry);
23 | if (entry) {
24 | if (state.depth > iDepth) {
25 | oDepth++;
26 | }
27 | else if (state.depth < iDepth) {
28 | oDepth--;
29 | }
30 | entry.depth = oDepth;
31 | iDepth = state.depth;
32 | arr.push(entry);
33 | }
34 | });
35 | return arr;
36 | }
37 |
38 | module.exports = {
39 | flatten : flatten
40 | };
41 |
42 |
--------------------------------------------------------------------------------
/test/s2o-test/issue215/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | info:
3 | version: '1.0'
4 | title: API
5 | paths:
6 | /post:
7 | post:
8 | parameters:
9 | - name: body
10 | description: Random body.
11 | in: body
12 | schema:
13 | $ref: '#/definitions/Random~1Request'
14 | required: true
15 | responses:
16 | 204:
17 | description: No Content.
18 | 400:
19 | description: Bad request.
20 | schema:
21 | $ref: '#/definitions/Error~1400'
22 | definitions:
23 | Random/Request:
24 | type: object
25 | properties:
26 | random_phone_number:
27 | description: Some string number.
28 | type: string
29 | example: "0681924019"
30 | other_random_phone_number:
31 | description: Some string number.
32 | type: string
33 | example: "681924019"
34 | required: [random_phone_number]
35 | Error/400:
36 | type: object
37 | properties:
38 | code:
39 | type: string
40 | example: "400"
41 | label:
42 | type: string
43 | example: Bad Request
44 | description:
45 | type: string
46 | example: Property "random_date" is required
47 |
--------------------------------------------------------------------------------
/packages/reftools/lib/reref.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const recurse = require('./recurse.js').recurse;
4 | const jptr = require('./jptr.js').jptr;
5 |
6 | /**
7 | * Simply modifies an object to have no self-references by replacing them
8 | * with $ref pointers
9 | * @param obj the object to re-reference
10 | * @param options may contain a prefix property for the generated refs
11 | * @return the re-referenced object (mutated)
12 | */
13 |
14 | function reref(obj,options) {
15 | let master = obj;
16 | recurse(obj,{identityDetection:true},function(obj,key,state){
17 | if (state.identity) {
18 | let replacement = jptr(master,state.identityPath);
19 | // ensure it's still there and we've not reffed it away
20 | let newRef = state.identityPath;
21 | if (state.identityPath !== state.path) {
22 | if (options && options.prefix) newRef = newRef.replace('#/',options.prefix);
23 | if (replacement !== false) obj[key] = { $ref: newRef }
24 | else if (options && options.verbose) console.warn(state.identityPath,'gone away at',state.path);
25 | }
26 | }
27 | });
28 | return obj;
29 | }
30 |
31 | module.exports = {
32 | reref : reref
33 | };
34 |
35 |
--------------------------------------------------------------------------------
/packages/oas-schema-walker/README.md:
--------------------------------------------------------------------------------
1 | # OAS-Schema-Walker
2 | ## Functions
3 |
4 |
5 | - getDefaultState() ⇒
6 | obtains the default starting state for the state object used
7 | by walkSchema
8 |
9 | - walkSchema(parent, state, callback,) ⇒
10 | begins the walk of a schema object, or the state object used
11 | by walkSchema
12 |
13 |
14 |
15 |
16 |
17 | ## getDefaultState() ⇒
18 | obtains the default starting state for the `state` object used
19 | by walkSchema
20 |
21 | **Kind**: global function
22 | **Returns**: the state object suitable for use in walkSchema
23 |
24 |
25 | ## walkSchema(parent, state, callback,) ⇒
26 | begins the walk of a schema object, or the `state` object used
27 | by walkSchema
28 |
29 | **Kind**: global function
30 | **Returns**: the schema object
31 |
32 | | Param | Description |
33 | | --- | --- |
34 | | parent | the parent schema, if any. Use empty object if none |
35 | | state | the initial starting state of the walker, usually obtained from `getDefaultState` |
36 | | callback, | a function taking a schema, parent and state to be called on this and all subschemas |
37 |
38 |
--------------------------------------------------------------------------------
/test/testisref.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const should = require('should');
4 | const isRef = require('../packages/reftools/lib/isref.js').isRef;
5 |
6 | const simple = { '$ref': '#/' };
7 | const extended = { '$ref': '#/', description: 'desc' };
8 | const wrongType = { '$ref': true };
9 |
10 | describe('isref',function(){
11 | describe('basic tests',function(){
12 | it('should match an object with a $ref',function(){
13 | isRef(simple,'$ref').should.be.exactly(true);
14 | });
15 | it('should match an object with a $ref and other properties',function(){
16 | isRef(extended,'$ref').should.be.exactly(true);
17 | });
18 | it('should not match a missing key',function(){
19 | isRef(simple,'description').should.be.exactly(false);
20 | });
21 | it('should not match a key not called $ref',function(){
22 | isRef(extended,'description').should.be.exactly(false);
23 | });
24 | it('should not match a key which is not a string',function(){
25 | isRef(wrongType,'$ref').should.be.exactly(false);
26 | });
27 | it('should not match when object is undefined',function(){
28 | isRef(undefined,'$ref').should.be.exactly(false);
29 | });
30 | });
31 | });
32 |
33 |
--------------------------------------------------------------------------------
/webpack.converter.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const webpack = require('webpack');
4 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5 |
6 | module.exports = {
7 | mode: 'production',
8 | performance: { hints: false },
9 | plugins: [
10 | new BundleAnalyzerPlugin(),
11 | new webpack.NormalModuleReplacementPlugin(/node_modules.yaml/, resource => {
12 | const components = resource.request.split('/');
13 | for (let i=0;i {
11 | return fs.statSync(path.join(__dirname, 'validator', file)).isDirectory() && file !== 'include';
12 | });
13 |
14 | describe('Validator tests', () => {
15 | tests.forEach((test) => {
16 | describe(test, () => {
17 | it('should validate correctly', (done) => {
18 | const inputSpec = path.join(__dirname, 'validator', test, 'openapi.yaml');
19 | const input = yaml.parse(fs.readFileSync(inputSpec,'utf8'),{schema:'core'});
20 |
21 | let options = { resolve: true, preserveMiro: false, source: inputSpec };
22 | try {
23 | options = Object.assign({},options,yaml.parse(fs.readFileSync(path.join(__dirname, 'validator', test, 'options.yaml'),'utf8'),{schema:'core'}));
24 | }
25 | catch (ex) {}
26 |
27 | validator.validate(input, options)
28 | .then(function(options){
29 | assert(options.valid === !options.expectFailure,'options.valid should be true');
30 | return done();
31 | })
32 | .catch(function(err){
33 | return done(options.expectFailure ? undefined : err);
34 | });
35 | });
36 | });
37 | });
38 | });
39 |
--------------------------------------------------------------------------------
/test/s2o-test/issue145/swagger.yaml:
--------------------------------------------------------------------------------
1 | swagger: '2.0'
2 | basePath: /issue145/api
3 | info:
4 | version: '1.0'
5 | title: 'Issue 145 Test v1'
6 | description: 'This is a testcase re: a referenced form param which is a string array.'
7 | paths:
8 | /v1/formtest1:
9 | post:
10 | operationId: formTest1
11 | summary: 'Form parameter test 1'
12 | description: 'Form param is a referenced parameter.'
13 | consumes:
14 | - multipart/form-data
15 | parameters:
16 | - $ref: '#/parameters/StringArrayFormParam'
17 | responses:
18 | '201':
19 | description: 'Successful request.'
20 | '400':
21 | description: 'Invalid request.'
22 | /v1/formtest2:
23 | post:
24 | operationId: formTest2
25 | summary: 'Form parameter test 2'
26 | description: 'Form param is defined inline'
27 | consumes:
28 | - multipart/form-data
29 | parameters:
30 | - name: inline_form_param
31 | in: formData
32 | description: 'Inline form param.'
33 | required: true
34 | type: array
35 | items:
36 | type: string
37 | responses:
38 | '201':
39 | description: 'Successful request.'
40 | '400':
41 | description: 'Invalid request.'
42 | parameters:
43 | StringArrayFormParam:
44 | name: referenced_form_param
45 | in: formData
46 | description: 'Referenced form param'
47 | required: true
48 | type: array
49 | items:
50 | type: string
51 |
--------------------------------------------------------------------------------
/docs/browser.md:
--------------------------------------------------------------------------------
1 | # Browser support
2 |
3 | ## Webpack v4
4 |
5 | Many thanks to @RomanGotsiy for getting these sizes down somewhat.
6 | Further size reductions were made by replacing `js-yaml` with `yaml` and
7 | forcing `webpack` to deduplicate across packages, inspired by @mrin9.
8 |
9 | ```shell
10 | $ npm run webpack
11 | $ ls -lh dist
12 | total 564K
13 | -rw-r--r-- 1 mike mike 42K Jan 7 10:09 converter.min.js
14 | -rw-r--r-- 1 mike mike 5.0K Jan 7 10:09 linter.min.js
15 | -rw-r--r-- 1 mike mike 406K Jan 7 10:09 oas-lib.min.js
16 | -rw-r--r-- 1 mike mike 13K Jan 7 10:09 resolver.min.js
17 | -rw-r--r-- 1 mike mike 82K Jan 7 10:09 validator.min.js
18 | -rw-r--r-- 1 mike mike 2.5K Jan 7 10:09 walker.min.js
19 | ```
20 |
21 | The whole suite is therefore around 149K gzipped.
22 |
23 | The converter only is:
24 |
25 | ```shell
26 | -rw-r--r-- 1 mike mike 172K Jan 7 09:41 dist/converter-lib.min.js
27 | -rw-r--r-- 1 mike mike 42K Jan 7 09:41 dist/converterOnly.min.js
28 | ```
29 |
30 | And the validator only is:
31 |
32 | ```shell
33 | -rw-r--r-- 1 mike mike 359K Jan 7 09:40 dist/validator-lib.min.js
34 | -rw-r--r-- 1 mike mike 82K Jan 7 09:40 dist/validatorOnly.min.js
35 | ```
36 |
37 | You can also build key parts of `reftools` into browser libraries by using `npm run webpack-reftools`.
38 |
39 | ## Browserify
40 |
41 | Please see [api-spec-converter](https://github.com/LucyBot-Inc/api-spec-converter/) for setup or to use this [bundle](https://github.com/LucyBot-Inc/api-spec-converter/blob/master/dist/api-spec-converter.js).
42 |
43 | Size: 8.45M
44 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # OAS-Kit
2 |
3 | This is the documentation site for OAS-Kit, a collection of packages which comprise an OpenAPI 2.0 to 3.0.x converter, a resolver, a validator, a schema-walker and a linter.
4 |
5 | ## Project READMEs
6 |
7 | * [main README](https://github.com/Mermade/oas-kit/blob/master/README.md)
8 | * [swagger2openapi README](https://github.com/Mermade/oas-kit/blob/master/packages/swagger2openapi/README.md)
9 | * [oas-validator README](https://github.com/Mermade/oas-kit/blob/master/packages/oas-validator/README.md)
10 | * [oas-resolver README](https://github.com/Mermade/oas-kit/blob/master/packages/oas-resolver/README.md)
11 | * [oas-linter README](https://github.com/Mermade/oas-kit/blob/master/packages/oas-linter/README.md)
12 | * [oas-schema-walker README](https://github.com/Mermade/oas-kit/blob/master/packages/oas-schema-walker/README.md)
13 | * [reftools README](https://github.com/Mermade/oas-kit/blob/master/packages/reftools/README.md)
14 |
15 | ## Implementation documentation
16 |
17 | * [Use in the browser](browser.md)
18 | * [Specification extensions supported](extensions.md)
19 | * [Details on de-resolution information](externals.md)
20 | * [Details on custom protocol/scheme handlers](handlers.md)
21 | * [Linter default rule descriptions](default-rules.md)
22 | * [Linter rule DSL documentation](linter-rules.md)
23 | * [The options object](options.md)
24 |
25 | ## OAS-Kit Wiki
26 |
27 | * [Including contributed Linter rules](https://github.com/Mermade/oas-kit/wiki)
28 |
29 | ## TODO (help wanted)
30 |
31 | * Documentation/example of custom resource filters
32 |
--------------------------------------------------------------------------------
/test/s2o-test/issue169/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.0
2 | info:
3 | title: Random title
4 | description: Random description
5 | version: 0.0.1
6 | contact:
7 | email: qvidal@random.com
8 | paths:
9 | /random:
10 | post:
11 | summary: Random summary.
12 | requestBody:
13 | content:
14 | application/json:
15 | schema:
16 | $ref: "#/components/schemas/RandomRequest"
17 | description: Random body.
18 | required: true
19 | responses:
20 | "204":
21 | description: No Content.
22 | "400":
23 | description: Bad request.
24 | content:
25 | "*/*":
26 | schema:
27 | $ref: "#/components/schemas/Error400"
28 | servers:
29 | - url: https://www.random.com
30 | components:
31 | schemas:
32 | RandomRequest:
33 | type: object
34 | properties:
35 | random_phone_number:
36 | description: Some string number.
37 | type: string
38 | example: "0681924019"
39 | other_random_phone_number:
40 | description: Some string number.
41 | type: string
42 | example: "681924019"
43 | required:
44 | - random_phone_number
45 | Error400:
46 | type: object
47 | properties:
48 | code:
49 | type: string
50 | example: "400"
51 | label:
52 | type: string
53 | example: Bad Request
54 | description:
55 | type: string
56 | example: Property "random_date" is required
57 |
--------------------------------------------------------------------------------
/test/resolver.test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const fs = require('fs');
4 | const path = require('path');
5 | const assert = require('assert');
6 | const yaml = require('yaml');
7 |
8 | const resolver = require('../packages/oas-resolver');
9 |
10 | const tests = fs.readdirSync(path.join(__dirname,'resolver')).filter(file => {
11 | return fs.statSync(path.join(__dirname, 'resolver', file)).isDirectory() && file !== 'include';
12 | });
13 |
14 | describe('Resolver tests', () => {
15 | tests.forEach((test) => {
16 | describe(test, () => {
17 | it('should match expected output', (done) => {
18 | const inputSpec = path.join(__dirname, 'resolver', test, 'input.yaml');
19 | const input = yaml.parse(fs.readFileSync(inputSpec,'utf8'),{schema:'core'});
20 | const output = yaml.parse(fs.readFileSync(path.join(__dirname, 'resolver', test, 'output.yaml'),'utf8'),{schema:'core'});
21 |
22 | let options = { resolve: true, preserveMiro: false, source: inputSpec };
23 | try {
24 | options = Object.assign({},options,yaml.parse(fs.readFileSync(path.join(__dirname, 'resolver', test, 'options.yaml'),'utf8'),{schema:'core'}));
25 | }
26 | catch (ex) {}
27 |
28 | resolver.resolve(input, options.source, options)
29 | .then(function(result){
30 | assert.deepStrictEqual(result.openapi, output);
31 | return done();
32 | })
33 | .catch(function(err){
34 | return done(err);
35 | });
36 | });
37 | });
38 | });
39 | });
40 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/reftools/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2017, Mike Ralphson
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/oas-kit-common/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/oas-linter/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/oas-resolver/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/oas-validator/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/oas-schema-walker/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/packages/swagger2openapi/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2016, Mermade Software
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "license": "BSD-3-Clause",
3 | "devDependencies": {
4 | "@babel/runtime": "^7.12.5",
5 | "babel-preset-env": "^1.7.0",
6 | "eslint": "^7.8.1",
7 | "jsdoc-to-markdown": "^7.0.1",
8 | "lerna": "^4.0.0",
9 | "mocha": "^9.0.0",
10 | "should": "^13.2.1",
11 | "webpack": "^5.6.0",
12 | "webpack-bundle-analyzer": "^4.4.2",
13 | "webpack-cli": "^4.2.0",
14 | "yaml": "^1.10.0"
15 | },
16 | "name": "oas-kit",
17 | "description": "This is the mono-repo for swagger2openapi and related projects",
18 | "version": "5.3.0",
19 | "main": "index.js",
20 | "directories": {
21 | "test": "test"
22 | },
23 | "funding": "https://www.linode.com/?r=5734be467cc501b23267cf66d451bc339042ddfa",
24 | "scripts": {
25 | "test": "npx mocha",
26 | "lint": "npx eslint packages/*/*.js test/*.js",
27 | "webpack": "npx webpack",
28 | "webpack-converter": "npx webpack --config webpack.converter.js",
29 | "webpack-validator": "npx webpack --config webpack.validator.js",
30 | "webpack-reftools": "npx webpack --config webpack.reftools.js",
31 | "audits": "npx lerna exec --no-bail npm audit",
32 | "outdated": "npx lerna exec --no-bail npm outdated",
33 | "rescue": "npx lerna publish from-package"
34 | },
35 | "repository": {
36 | "type": "git",
37 | "url": "git+https://github.com/mermade/oas-kit.git"
38 | },
39 | "author": "Mike Ralphson",
40 | "bugs": {
41 | "url": "https://github.com/mermade/oas-kit/issues"
42 | },
43 | "homepage": "https://github.com/mermade/oas-kit#readme",
44 | "keywords": [
45 | "openapi",
46 | "oas",
47 | "swagger"
48 | ],
49 | "dependencies": {}
50 | }
51 |
--------------------------------------------------------------------------------
/test/resolver/issue282/input.yaml:
--------------------------------------------------------------------------------
1 | openapi: "3.0.0"
2 | info:
3 | version: 1.0.0
4 | title: Swagger Petstore
5 | license:
6 | name: MIT
7 | servers:
8 | - url: http://petstore.swagger.io/v1
9 | paths:
10 | /pets:
11 | get:
12 | summary: List all pets
13 | operationId: listPets
14 | tags:
15 | - pets
16 | parameters:
17 | - name: limit
18 | in: query
19 | description: How many items to return at one time (max 100)
20 | required: false
21 | schema:
22 | type: integer
23 | format: int32
24 | responses:
25 | '200':
26 | description: An paged array of pets
27 | headers:
28 | x-next:
29 | description: A link to the next page of responses
30 | schema:
31 | type: string
32 | content:
33 | application/json:
34 | schema:
35 | $ref: "pet.yaml"
36 | post:
37 | summary: Create pet
38 | tags:
39 | - pets
40 | parameters:
41 | - name: limit
42 | in: query
43 | description: How many items to return at one time (max 100)
44 | required: false
45 | schema:
46 | type: integer
47 | format: int32
48 | responses:
49 | '200':
50 | description: An paged array of pets
51 | content:
52 | application/json:
53 | schema:
54 | $ref: "./pet.yaml"
55 | '400':
56 | content:
57 | application/json:
58 | schema:
59 | $ref: "incorrect-ref.yaml"
60 |
--------------------------------------------------------------------------------
/packages/swagger2openapi/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "swagger2openapi",
3 | "version": "7.0.8",
4 | "description": "Convert Swagger 2.0 definitions to OpenApi 3.0 and validate",
5 | "main": "index.js",
6 | "bin": {
7 | "swagger2openapi": "./swagger2openapi.js",
8 | "oas-validate": "./oas-validate.js",
9 | "boast": "./boast.js"
10 | },
11 | "funding": "https://github.com/Mermade/oas-kit?sponsor=1",
12 | "scripts": {
13 | "test": "mocha"
14 | },
15 | "browserify": {
16 | "transform": [
17 | [
18 | "babelify",
19 | {
20 | "presets": [
21 | "es2015"
22 | ]
23 | }
24 | ]
25 | ]
26 | },
27 | "repository": {
28 | "url": "https://github.com/Mermade/oas-kit.git",
29 | "type": "git"
30 | },
31 | "bugs": {
32 | "url": "https://github.com/mermade/oas-kit/issues"
33 | },
34 | "author": "Mike Ralphson ",
35 | "license": "BSD-3-Clause",
36 | "dependencies": {
37 | "call-me-maybe": "^1.0.1",
38 | "node-fetch": "^2.6.1",
39 | "node-fetch-h2": "^2.3.0",
40 | "node-readfiles": "^0.2.0",
41 | "oas-kit-common": "^1.0.8",
42 | "oas-resolver": "^2.5.6",
43 | "oas-schema-walker": "^1.1.5",
44 | "oas-validator": "^5.0.8",
45 | "reftools": "^1.1.9",
46 | "yaml": "^1.10.0",
47 | "yargs": "^17.0.1"
48 | },
49 | "keywords": [
50 | "swagger",
51 | "openapi",
52 | "openapi2",
53 | "openapi3",
54 | "converter",
55 | "conversion",
56 | "validator",
57 | "validation",
58 | "resolver",
59 | "lint",
60 | "linter"
61 | ],
62 | "gitHead": "5cbeab49334ebe18c117764d086e1cfe7d708e97"
63 | }
64 |
--------------------------------------------------------------------------------
/webpack.validator.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const webpack = require('webpack');
4 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5 |
6 | module.exports = {
7 | mode: 'production',
8 | performance: { hints: false },
9 | plugins: [
10 | new BundleAnalyzerPlugin(),
11 | new webpack.NormalModuleReplacementPlugin(/node_modules.should/, resource => {
12 | const components = resource.request.split('/');
13 | for (let i=0;i {
21 | const components = resource.request.split('/');
22 | for (let i=0;i {
13 | return fs.statSync(path.join(__dirname, 's2o-test', file)).isDirectory() && file !== 'include' && (!file.startsWith('_') || doPrivate);
14 | });
15 |
16 | describe('Converter tests', () => {
17 | tests.forEach((test) => {
18 | describe(test, () => {
19 | it('should match expected output', (done) => {
20 | const swagger = yaml.parse(fs.readFileSync(path.join(__dirname, 's2o-test', test, 'swagger.yaml'),'utf8'),{schema:'core'});
21 | const openapi = yaml.parse(fs.readFileSync(path.join(__dirname, 's2o-test', test, 'openapi.yaml'),'utf8'),{schema:'core'});
22 |
23 | let options = {};
24 | options.source = path.join(__dirname, 's2o-test', test, 'swagger.yaml');
25 | try {
26 | options = Object.assign({},options,yaml.parse(fs.readFileSync(path.join(__dirname, 's2o-test', test, 'options.yaml'),'utf8'),{schema:'core'}));
27 | }
28 | catch (ex) {}
29 |
30 | swagger2openapi.convertObj(swagger, options, (err, result) => {
31 | if (err && !options.throws) return done(err);
32 | if (!err && options.throws) return done(new Error('Test should have thrown an exception'));
33 |
34 | if (!options.throws) assert.deepStrictEqual(result.openapi, openapi);
35 |
36 | return done();
37 | });
38 | });
39 | });
40 | });
41 | });
42 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const webpack = require('webpack');
4 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5 |
6 | module.exports = {
7 | mode: 'production',
8 | performance: { hints: false },
9 | plugins: [
10 | new BundleAnalyzerPlugin(),
11 | new webpack.NormalModuleReplacementPlugin(/node_modules.should/, resource => {
12 | const components = resource.request.split('/');
13 | for (let i=0;i {
21 | const components = resource.request.split('/');
22 | for (let i=0;i {
14 | return fs.statSync(path.join(__dirname, 'http2', file)).isDirectory() && file !== 'include';
15 | });
16 |
17 | const {
18 | HTTP2_HEADER_PATH,
19 | HTTP2_HEADER_METHOD,
20 | HTTP_STATUS_NOT_FOUND,
21 | HTTP_STATUS_INTERNAL_SERVER_ERROR
22 | } = http2.constants;
23 |
24 | const serverOptions = {
25 | key: fs.readFileSync(path.join(__dirname,'localhost.key')),
26 | cert: fs.readFileSync(path.join(__dirname,'localhost.cert'))
27 | };
28 | const server = http2.createSecureServer(serverOptions);
29 | const serverRoot = path.join(__dirname,'http2');
30 |
31 | const agent = new https.Agent({
32 | rejectUnauthorized: false
33 | });
34 |
35 | function respondToStreamError(err, stream) {
36 | console.warn(err);
37 | if (err.code === 'ENOENT') {
38 | stream.respond({ ":status": HTTP_STATUS_NOT_FOUND });
39 | } else {
40 | stream.respond({ ":status": HTTP_STATUS_INTERNAL_SERVER_ERROR });
41 | }
42 | stream.end();
43 | }
44 |
45 | server.on('stream', (stream, headers) => {
46 | const reqPath = headers[HTTP2_HEADER_PATH];
47 | const reqMethod = headers[HTTP2_HEADER_METHOD];
48 |
49 | const fullPath = path.join(serverRoot, reqPath);
50 | const responseMimeType = mime.lookup(fullPath);
51 |
52 | stream.respondWithFile(fullPath, {
53 | 'content-type': responseMimeType
54 | }, {
55 | onError: (err) => respondToStreamError(err, stream)
56 | });
57 | });
58 |
59 | describe('HTTP2 tests', () => {
60 |
61 | before(function () {
62 | server.listen(8321);
63 | });
64 |
65 | after(function () {
66 | server.close();
67 | });
68 |
69 | tests.forEach((test) => {
70 | describe(test, () => {
71 | it('should match expected output', (done) => {
72 | const inputSpec = path.join(__dirname, 'http2', test, 'input.yaml');
73 | const input = yaml.parse(fs.readFileSync(inputSpec,'utf8'),{schema:'core'});
74 | const output = yaml.parse(fs.readFileSync(path.join(__dirname, 'http2', test, 'output.yaml'),'utf8'),{schema:'core'});
75 |
76 | let options = { resolve: true, preserveMiro: false, source: inputSpec, agent, verbose: true };
77 | try {
78 | options = Object.assign({},options,yaml.parse(fs.readFileSync(path.join(__dirname, 'http2', test, 'options.yaml'),'utf8'),{schema:'core'}));
79 | }
80 | catch (ex) {}
81 |
82 | resolver.resolve(input, options.source, options)
83 | .then(function(result){
84 | assert.deepStrictEqual(result.openapi, output);
85 | return done();
86 | })
87 | .catch(function(err){
88 | return done(err);
89 | });
90 | });
91 | });
92 | });
93 | });
94 |
--------------------------------------------------------------------------------
/test/testflatten.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | const should = require('should');
3 | const flatten = require('../packages/reftools/lib/flatten.js').flatten;
4 |
5 | const input = { container: { child: { value: true } }, sibling: { value: false } };
6 |
7 | //depth,path,parent.pkey
8 |
9 | describe('flatten',function(){
10 | describe('simple',function(){
11 | it('should flatten a simple nested object',function(){
12 | let output = flatten(input);
13 |
14 | output.should.be.an.Array();
15 | should(output.length).equal(5);
16 |
17 | output[0].name.should.equal('container');
18 | output[0].value.should.equal(input.container);
19 | output[0].depth.should.equal(0);
20 | output[0].path.should.equal('#/container');
21 | output[0].parent.should.equal(input);
22 |
23 | output[1].name.should.equal('child');
24 | output[1].value.should.equal(input.container.child);
25 | output[1].depth.should.equal(1);
26 | output[1].path.should.equal('#/container/child');
27 | output[1].parent.should.equal(input.container);
28 |
29 | output[2].name.should.equal('value');
30 | output[2].value.should.equal(true);
31 | output[2].depth.should.equal(2);
32 | output[2].path.should.equal('#/container/child/value');
33 | output[2].parent.should.equal(input.container.child);
34 |
35 | output[3].name.should.equal('sibling');
36 | output[3].value.should.equal(input.sibling);
37 | output[3].depth.should.equal(1);
38 | output[3].path.should.equal('#/sibling');
39 | output[3].parent.should.equal(input);
40 |
41 | output[4].name.should.equal('value');
42 | output[4].value.should.equal(false);
43 | output[4].depth.should.equal(2);
44 | output[4].path.should.equal('#/sibling/value');
45 | output[4].parent.should.equal(input.sibling);
46 | });
47 | });
48 | describe('filtered',function(){
49 | it('should flatten a simple nested object, filtering a property',function(){
50 | let output = flatten(input,function(entry){
51 | if ((entry.name !== 'child') && (entry.name !== 'sibling')) return entry;
52 | });
53 |
54 | output.should.be.an.Array();
55 | should(output.length).equal(3);
56 |
57 | output[0].name.should.equal('container');
58 | output[0].value.should.equal(input.container);
59 | output[0].depth.should.equal(0);
60 | output[0].path.should.equal('#/container');
61 | output[0].parent.should.equal(input);
62 |
63 | output[1].name.should.equal('value');
64 | output[1].value.should.equal(true);
65 | output[1].depth.should.equal(1);
66 | output[1].path.should.equal('#/container/child/value');
67 | output[1].parent.should.equal(input.container.child);
68 |
69 | output[2].name.should.equal('value');
70 | output[2].value.should.equal(false);
71 | output[2].depth.should.equal(0);
72 | output[2].path.should.equal('#/sibling/value');
73 | output[2].parent.should.equal(input.sibling);
74 | });
75 | });
76 | });
77 |
--------------------------------------------------------------------------------
/packages/reftools/lib/clone.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | * a collection of cloning functions
5 | */
6 |
7 | /**
8 | * a no-op placeholder which returns the given object unchanged
9 | * useful for when a clone function needs to be passed but cloning is not
10 | * required
11 | * @param obj the input object
12 | * @return the input object, unchanged
13 | */
14 | function nop(obj) {
15 | return obj;
16 | }
17 |
18 | /**
19 | * clones the given object using JSON.parse and JSON.stringify
20 | * @param obj the object to clone
21 | * @return the cloned object
22 | */
23 | function clone(obj) {
24 | return JSON.parse(JSON.stringify(obj));
25 | }
26 |
27 | /**
28 | * clones the given object's properties shallowly, ignores properties from prototype
29 | * @param obj the object to clone
30 | * @return the cloned object
31 | */
32 | function shallowClone(obj) {
33 | let result = {};
34 | for (let p in obj) {
35 | if (obj.hasOwnProperty(p)) {
36 | result[p] = obj[p];
37 | }
38 | }
39 | return result;
40 | }
41 |
42 | /**
43 | * clones the given object's properties deeply, ignores properties from prototype
44 | * @param obj the object to clone
45 | * @return the cloned object
46 | */
47 | function deepClone(obj) {
48 | let result = Array.isArray(obj) ? [] : {};
49 | for (let p in obj) {
50 | if (obj.hasOwnProperty(p) || Array.isArray(obj)) {
51 | result[p] = (typeof obj[p] === 'object') ? deepClone(obj[p]) : obj[p];
52 | }
53 | }
54 | return result;
55 | }
56 |
57 | /**
58 | * clones the given object's properties shallowly, using Object.assign
59 | * @param obj the object to clone
60 | * @return the cloned object
61 | */
62 | function fastClone(obj) {
63 | return Object.assign({},obj);
64 | }
65 |
66 | /**
67 | * Source: stackoverflow http://bit.ly/2A1Kha6
68 | */
69 |
70 | function circularClone(obj, hash) {
71 | if (!hash) hash = new WeakMap();
72 | // Do not try to clone primitives or functions
73 | if (Object(obj) !== obj || obj instanceof Function) return obj;
74 | if (hash.has(obj)) return hash.get(obj); // Cyclic reference
75 | try { // Try to run constructor (without arguments, as we don't know them)
76 | var result = new obj.constructor();
77 | } catch(e) { // Constructor failed, create object without running the constructor
78 | result = Object.create(Object.getPrototypeOf(obj));
79 | }
80 | // Optional: support for some standard constructors (extend as desired)
81 | /*if (obj instanceof Map)
82 | Array.from(obj, ([key, val]) => result.set(circularClone(key, hash),
83 | circularClone(val, hash)) );
84 | else if (obj instanceof Set)
85 | Array.from(obj, (key) => result.add(circularClone(key, hash)) );
86 | */
87 | // Register in hash
88 | hash.set(obj, result);
89 | // Clone and assign enumerable own properties recursively
90 | return Object.assign(result, ...Object.keys(obj).map (
91 | key => ({ [key]: circularClone(obj[key], hash) }) ));
92 | }
93 |
94 | module.exports = {
95 | nop : nop,
96 | clone : clone,
97 | shallowClone : shallowClone,
98 | deepClone : deepClone,
99 | fastClone : fastClone,
100 | circularClone : circularClone
101 | };
102 |
103 |
--------------------------------------------------------------------------------
/docs/externals.md:
--------------------------------------------------------------------------------
1 | # Externals structure documentation
2 |
3 | `options.externals` is an array of Objects containing the following properties:
4 |
5 | Name|Type|Description
6 | |---|---|---|
7 | context|String|A JSON Pointer containing the path to the containing property which was resolved
8 | $ref|String|The original `$ref` property
9 | original|Object|The original Swagger 2.0 version of the resolved reference
10 | updated|Object|The OpenAPI 3.0 version of the resolved reference
11 | source|String|The resolved source of the external `$ref`
12 |
13 | ## Example
14 |
15 | ````json
16 | [
17 | {
18 | "context": "#/paths/~1subscriptions~1{subscriptionId}~1providers~1Microsoft.Commerce~1RateCard/get/x-ms-examples/GetRateCard",
19 | "$ref": "../examples/GetRatecard.json",
20 | "source": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/2fb9a0b3b902335ff0b0033711c234431931ec9d/specification/commerce/resource-manager/Microsoft.Commerce/2015-06-01-preview/examples/GetRatecard.json",
21 | "original": {
22 | "title": "Get RateCard",
23 | "parameters": {
24 | "subscriptionId": "6d61cc05-8f8f-4916-b1b9-f1d9c25aae27",
25 | "api-version": "2015-06-01-preview",
26 | "$filter": "OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"
27 | },
28 | "responses": {
29 | "200": {
30 | "body": {
31 | "OfferTerms": [],
32 | "Meters": [
33 | {
34 | "EffectiveDate": "2017-09-01T00:00:00Z",
35 | "IncludedQuantity": 0,
36 | "MeterCategory": "Test Category",
37 | "MeterId": "1d7518e5-bc2f-4a93-9057-1b3047856645",
38 | "MeterName": "Test Meter",
39 | "MeterRates": {
40 | "0": 1.99,
41 | "100": 0.99
42 | },
43 | "MeterRegion": "US West",
44 | "MeterSubCategory": "Test Subcategory",
45 | "MeterTags": [
46 | "Third Party"
47 | ],
48 | "Unit": "Hours"
49 | }
50 | ]
51 | }
52 | }
53 | }
54 | },
55 | "updated": {
56 | "title": "Get RateCard",
57 | "parameters": {
58 | "subscriptionId": "6d61cc05-8f8f-4916-b1b9-f1d9c25aae27",
59 | "api-version": "2015-06-01-preview",
60 | "$filter": "OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"
61 | },
62 | "responses": {
63 | "200": {
64 | "body": {
65 | "OfferTerms": [],
66 | "Meters": [
67 | {
68 | "EffectiveDate": "2017-09-01T00:00:00Z",
69 | "IncludedQuantity": 0,
70 | "MeterCategory": "Test Category",
71 | "MeterId": "1d7518e5-bc2f-4a93-9057-1b3047856645",
72 | "MeterName": "Test Meter",
73 | "MeterRates": {
74 | "0": 1.99,
75 | "100": 0.99
76 | },
77 | "MeterRegion": "US West",
78 | "MeterSubCategory": "Test Subcategory",
79 | "MeterTags": [
80 | "Third Party"
81 | ],
82 | "Unit": "Hours"
83 | }
84 | ]
85 | }
86 | }
87 | }
88 | }
89 | }
90 | ]
91 | ````
92 |
--------------------------------------------------------------------------------
/packages/reftools/lib/jptr.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | * escapes JSON Pointer using ~0 for ~ and ~1 for /
5 | * @param s the string to escape
6 | * @return the escaped string
7 | */
8 | function jpescape(s) {
9 | return s.replace(/\~/g, '~0').replace(/\//g, '~1');
10 | }
11 |
12 | /**
13 | * unescapes JSON Pointer using ~0 for ~ and ~1 for /
14 | * @param s the string to unescape
15 | * @return the unescaped string
16 | */
17 | function jpunescape(s) {
18 | return s.replace(/\~1/g, '/').replace(/~0/g, '~');
19 | }
20 |
21 | // JSON Pointer specification: http://tools.ietf.org/html/rfc6901
22 |
23 | /**
24 | * from obj, return the property with a JSON Pointer prop, optionally setting it
25 | * to newValue
26 | * @param obj the object to point into
27 | * @param prop the JSON Pointer or JSON Reference
28 | * @param newValue optional value to set the property to
29 | * @return the found property, or false
30 | */
31 | function jptr(obj, prop, newValue) {
32 | if (typeof obj === 'undefined') return false;
33 | if (!prop || typeof prop !== 'string' || (prop === '#')) return (typeof newValue !== 'undefined' ? newValue : obj);
34 |
35 | if (prop.indexOf('#')>=0) {
36 | let parts = prop.split('#');
37 | let uri = parts[0];
38 | if (uri) return false; // we do internal resolution only
39 | prop = parts[1];
40 | prop = decodeURIComponent(prop.slice(1).split('+').join(' '));
41 | }
42 | if (prop.startsWith('/')) prop = prop.slice(1);
43 |
44 | let components = prop.split('/');
45 | for (let i=0;i 0) ? components[i-1] : ''; // backtrack to indexed property name
56 | }
57 |
58 | if ((index != -1) || (obj && obj.hasOwnProperty(components[i]))) {
59 | if (index >= 0) {
60 | if (setAndLast) {
61 | obj[index] = newValue;
62 | }
63 | obj = obj[index];
64 | }
65 | else if (index === -2) {
66 | if (setAndLast) {
67 | if (Array.isArray(obj)) {
68 | obj.push(newValue);
69 | }
70 | return newValue;
71 | }
72 | else return undefined;
73 | }
74 | else {
75 | if (setAndLast) {
76 | obj[components[i]] = newValue;
77 | }
78 | obj = obj[components[i]];
79 | }
80 | }
81 | else {
82 | if ((typeof newValue !== 'undefined') && (typeof obj === 'object') &&
83 | (!Array.isArray(obj))) {
84 | obj[components[i]] = (setAndLast ? newValue : ((components[i+1] === '0' || components[i+1] === '-') ? [] : {}));
85 | obj = obj[components[i]];
86 | }
87 | else return false;
88 | }
89 | }
90 | return obj;
91 | }
92 |
93 | module.exports = {
94 | jptr : jptr,
95 | jpescape : jpescape,
96 | jpunescape : jpunescape
97 | };
98 |
--------------------------------------------------------------------------------
/docs/linter-rules.md:
--------------------------------------------------------------------------------
1 | # Linter rules format
2 |
3 | ## Rules file format
4 |
5 | A rules file is a YAML (or JSON) formatted file, containing an object, with a `rules` property, which is an array of `rule` objects.
6 |
7 | There is a `require` property (type `string`) at the top level, which is used for rule-set chaining.
8 |
9 | The `url` property can be used as the base for looking up rule documentation, the `rule-name` value should be appended as a fragment-id. The `url` property may be overridden for individual rules.
10 |
11 | ### Example
12 |
13 | ```yaml
14 | rules:
15 | - name: parameter-description
16 | object: parameter
17 | description: parameter objects should have a description
18 | truthy: description
19 | - name: parameter-name-regex
20 | object: parameter
21 | description: parameter names should match RFC6570
22 | pattern:
23 | property: name
24 | value: '^[A-Za-z0-9?_()]+$'
25 | ```
26 |
27 | ## Rule object format
28 |
29 | |Property|Type|Required|Description|
30 | |---|---|---|---|
31 | |name|string|yes|The name/slug of the rule. Use hyphens. Used as the unique key. You can namespace your rules with any prefix and delimiter you wish, to avoid clashes with other people's and the built-in rules|
32 | |description|string|recommended|An optional description for the rule|
33 | |disabled|boolean|no|Set to `true` to temporarily disable a rule|
34 | |enabled|boolean|deprecated|No longer used by `oas-linter`|
35 | |object|string\|array|no|The object(s) to act upon, may be `*` for all objects. E.g. `parameter`|
36 | |schema|o bject|no|A JSON Schema object used to validate the input object|
37 | |truthy|string\|array|no|A property or list of properties which must be truthy (present with a non-false, non-null, non-empty value). Empty arrays are not considered truthy|
38 | |alphabetical|object|no|Structure: `{ properties: string, keyedBy: string }`|
39 | |if|object|no|An object containing a `property` key. If this is present, the property within `then.property` must be present with the value in the `then.value`. An optional `else.property` and `else.value` may be supplied|
40 | |or|array|no|An array of property names, one or more of which must be present|
41 | |maxLength|object|no|An object containing a `property` string name, and a `value` (integer). The length of the `property` value must not be longer than `value`|
42 | |notContain|object|no|An object containing a `properties` array and a `value` or `pattern`. None of the `properties` must contain the `value` or match the `pattern`. Used with strings|
43 | |notEndWith|object|no|An object containing a `property`, an optional `omit` prefix and a `value` string. The given `property` (once `omit` is removed) must not end with the given `value`. Used with strings|
44 | |pattern|object|no|An object containing a `property` name, an optional `split` string which is used to split the value being tested into individual components, an optional `omit` string (which is chopped off the front of each component being tested), and a `value` regex property which is used to test all components of the property value being tested. If `startsWith` is present, the property must start with that string or the rule is skipped|
45 | |properties|integer|no|The exact number of non-extension properties which must be present on the target object|
46 | |skip|string|no|The name of a property in the `options` object. If this property is truthy, then the rule is skipped. E.g. `isCallback` can be used to skip rules for `operation` objects within `callback` objects, while still applying to top-level `operation` objects|
47 | |url|string|no|An optional override of the top-level `url` property, just for this rule
48 | |xor|array|no|An array of property names, only one of which must be present|
49 |
--------------------------------------------------------------------------------
/packages/oas-kit-common/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const sjs = require('fast-safe-stringify');
4 |
5 | const colour = process.env.NODE_DISABLE_COLORS ?
6 | { red: '', yellow: '', green: '', normal: '' } :
7 | { red: '\x1b[31m', yellow: '\x1b[33;1m', green: '\x1b[32m', normal: '\x1b[0m' };
8 |
9 | function uniqueOnly(value, index, self) {
10 | return self.indexOf(value) === index;
11 | }
12 |
13 | function hasDuplicates(array) {
14 | return (new Set(array)).size !== array.length;
15 | }
16 |
17 | function allSame(array) {
18 | return (new Set(array)).size <= 1;
19 | }
20 |
21 | function deepEquals(obj1, obj2) {
22 | function _equals(obj1, obj2) {
23 | return sjs.stringify(obj1) === sjs.stringify(Object.assign({}, obj1, obj2));
24 | }
25 | return _equals(obj1, obj2) && _equals(obj2, obj1);
26 | }
27 |
28 | function compressArray(arr) {
29 | let result = [];
30 | for (let candidate of arr) {
31 | let dupe = result.find(function(e,i,a){
32 | return deepEquals(e,candidate);
33 | });
34 | if (!dupe) result.push(candidate);
35 | }
36 | return result;
37 | }
38 |
39 | function distinctArray(arr) {
40 | return (arr.length === compressArray(arr).length);
41 | }
42 |
43 | function firstDupe(arr) {
44 | return arr.find(function(e,i,a){
45 | return arr.indexOf(e) tags
68 | notContain:
69 | properties:
70 | - description
71 | value: