├── .editorconfig ├── .eslintrc.yml ├── .gitattributes ├── .github └── workflows │ └── CI-CD.yaml ├── .gitignore ├── .mocharc.yml ├── .nycrc.yml ├── .vscode ├── launch.json └── tasks.json ├── 404.md ├── CHANGELOG.md ├── LICENSE ├── README.md ├── _config.yml ├── dist ├── index.d.ts ├── index.js └── package.json ├── package-lock.json ├── package.json ├── src ├── index.ts └── json-schema.ts ├── test └── specs │ ├── exports.spec.js │ └── hashes.spec.js └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor config 2 | # http://EditorConfig.org 3 | 4 | # This EditorConfig overrides any parent EditorConfigs 5 | root = true 6 | 7 | # Default rules applied to all file types 8 | [*] 9 | 10 | # No trailing spaces, newline at EOF 11 | charset = utf-8 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | end_of_line = lf 15 | 16 | # 2 space indentation 17 | indent_style = space 18 | indent_size = 2 19 | 20 | # JavaScript-specific settings 21 | [*.{js,ts}] 22 | quote_type = double 23 | continuation_indent_size = 2 24 | curly_bracket_next_line = false 25 | indent_brace_style = BSD 26 | spaces_around_operators = true 27 | spaces_around_brackets = none 28 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | # ESLint config 2 | # http://eslint.org/docs/user-guide/configuring 3 | # https://jstools.dev/eslint-config/ 4 | 5 | root: true 6 | extends: "@jsdevtools" 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Git attributes 2 | # https://git-scm.com/docs/gitattributes 3 | # https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes 4 | 5 | # Normalize line endings for all files that git determines to be text. 6 | # https://git-scm.com/docs/gitattributes#gitattributes-Settostringvalueauto 7 | * text=auto 8 | 9 | # Normalize line endings to LF on checkin, and do NOT convert to CRLF when checking-out on Windows. 10 | # https://git-scm.com/docs/gitattributes#gitattributes-Settostringvaluelf 11 | *.txt text eol=lf 12 | *.html text eol=lf 13 | *.md text eol=lf 14 | *.css text eol=lf 15 | *.scss text eol=lf 16 | *.map text eol=lf 17 | *.js text eol=lf 18 | *.jsx text eol=lf 19 | *.ts text eol=lf 20 | *.tsx text eol=lf 21 | *.json text eol=lf 22 | *.yml text eol=lf 23 | *.yaml text eol=lf 24 | *.xml text eol=lf 25 | *.svg text eol=lf 26 | -------------------------------------------------------------------------------- /.github/workflows/CI-CD.yaml: -------------------------------------------------------------------------------- 1 | # GitHub Actions workflow 2 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions 3 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions 4 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions 5 | 6 | name: CI-CD 7 | 8 | on: 9 | push: 10 | branches: 11 | - "*" 12 | tags-ignore: 13 | - "*" 14 | 15 | schedule: 16 | - cron: "0 0 1 * *" 17 | 18 | jobs: 19 | test: 20 | name: Node ${{ matrix.node }} on ${{ matrix.os }} 21 | runs-on: ${{ matrix.os }} 22 | timeout-minutes: 10 23 | strategy: 24 | fail-fast: true 25 | matrix: 26 | os: 27 | - ubuntu-latest 28 | - macos-latest 29 | - windows-latest 30 | node: 31 | - 12 32 | - 14 33 | - 16 34 | 35 | steps: 36 | - name: Checkout source 37 | uses: actions/checkout@v2 38 | 39 | - name: Install Node ${{ matrix.node }} 40 | uses: actions/setup-node@v1 41 | with: 42 | node-version: ${{ matrix.node }} 43 | 44 | - name: Install dependencies 45 | run: npm ci 46 | 47 | - name: Run linters 48 | run: npm run lint 49 | 50 | - name: Build the code 51 | run: npm run build 52 | 53 | - name: Run tests 54 | run: npm run coverage 55 | 56 | - name: Send code coverage results to Coveralls 57 | uses: coverallsapp/github-action@v1.1.0 58 | with: 59 | github-token: ${{ secrets.GITHUB_TOKEN }} 60 | parallel: true 61 | 62 | coverage: 63 | name: Code Coverage 64 | runs-on: ubuntu-latest 65 | timeout-minutes: 10 66 | needs: test 67 | steps: 68 | - name: Let Coveralls know that all tests have finished 69 | uses: coverallsapp/github-action@v1.1.0 70 | with: 71 | github-token: ${{ secrets.GITHUB_TOKEN }} 72 | parallel-finished: true 73 | 74 | deploy: 75 | name: Publish to NPM 76 | if: github.ref == 'refs/heads/master' 77 | runs-on: ubuntu-latest 78 | timeout-minutes: 10 79 | needs: test 80 | 81 | steps: 82 | - name: Checkout source 83 | uses: actions/checkout@v2 84 | 85 | - name: Install Node 86 | uses: actions/setup-node@v1 87 | 88 | - name: Install dependencies 89 | run: npm ci 90 | 91 | - name: Build the code 92 | run: npm run build 93 | 94 | - name: Publish to NPM 95 | uses: JS-DevTools/npm-publish@v1 96 | with: 97 | token: ${{ secrets.NPM_TOKEN }} 98 | 99 | - name: Prepare the non-scoped packaged 100 | run: | 101 | cp LICENSE *.md dist 102 | VERSION=$(node -e "console.log(require('./package.json').version)") 103 | sed -i "s/X.X.X/${VERSION}/g" dist/package.json 104 | 105 | - name: Publish the non-scoped package to NPM 106 | uses: JS-DevTools/npm-publish@v1 107 | with: 108 | token: ${{ secrets.NPM_TOKEN }} 109 | package: dist/package.json 110 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Git ignore 2 | # https://git-scm.com/docs/gitignore 3 | 4 | # Miscellaneous 5 | *~ 6 | *# 7 | .DS_STORE 8 | Thumbs.db 9 | .netbeans 10 | nbproject 11 | .node_history 12 | 13 | # IDEs & Text Editors 14 | .idea 15 | .sublime-* 16 | .vscode/settings.json 17 | .netbeans 18 | nbproject 19 | 20 | # Temporary files 21 | .tmp 22 | .temp 23 | .grunt 24 | .lock-wscript 25 | 26 | # Logs 27 | /logs 28 | *.log 29 | 30 | # Runtime data 31 | pids 32 | *.pid 33 | *.seed 34 | 35 | # Dependencies 36 | /node_modules 37 | /schemas 38 | 39 | # Build output 40 | /lib 41 | 42 | # Test output 43 | /.nyc_output 44 | /coverage 45 | -------------------------------------------------------------------------------- /.mocharc.yml: -------------------------------------------------------------------------------- 1 | # Mocha options 2 | # https://mochajs.org/#configuring-mocha-nodejs 3 | # https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.yml 4 | 5 | spec: 6 | # Test fixtures 7 | - test/fixtures/**/*.js 8 | 9 | # Test specs 10 | - test/specs/**/*.spec.js 11 | 12 | bail: true 13 | recursive: true 14 | -------------------------------------------------------------------------------- /.nycrc.yml: -------------------------------------------------------------------------------- 1 | # NYC config 2 | # https://github.com/istanbuljs/nyc#configuration-files 3 | 4 | extension: 5 | - .js 6 | - .ts 7 | 8 | reporter: 9 | - text 10 | - lcov 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // VSCode Launch Configuration 2 | // https://code.visualstudio.com/docs/editor/debugging#_launch-configurations 3 | 4 | // Available variables which can be used inside of strings. 5 | // ${workspaceRoot}: the root folder of the team 6 | // ${file}: the current opened file 7 | // ${fileBasename}: the current opened file's basename 8 | // ${fileDirname}: the current opened file's dirname 9 | // ${fileExtname}: the current opened file's extension 10 | // ${cwd}: the current working directory of the spawned process 11 | 12 | { 13 | "version": "0.2.0", 14 | "configurations": [ 15 | { 16 | "type": "node", 17 | "request": "launch", 18 | "name": "Run Mocha", 19 | "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", 20 | "args": [ 21 | "--timeout=60000", 22 | "--retries=0", 23 | ], 24 | "outFiles": [ 25 | "${workspaceFolder}/lib/**/*.js" 26 | ], 27 | "smartStep": true, 28 | "skipFiles": [ 29 | "/**/*.js" 30 | ], 31 | }, 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // VSCode Tasks 2 | // https://code.visualstudio.com/docs/editor/tasks 3 | 4 | // Available variables which can be used inside of strings. 5 | // ${workspaceRoot}: the root folder of the team 6 | // ${file}: the current opened file 7 | // ${fileBasename}: the current opened file's basename 8 | // ${fileDirname}: the current opened file's dirname 9 | // ${fileExtname}: the current opened file's extension 10 | // ${cwd}: the current working directory of the spawned process 11 | 12 | { 13 | "version": "2.0.0", 14 | "command": "npm", 15 | "tasks": [ 16 | { 17 | "type": "npm", 18 | "script": "build:typescript", 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true 22 | }, 23 | "problemMatcher": "$tsc" 24 | }, 25 | 26 | 27 | { 28 | "type": "npm", 29 | "script": "test", 30 | "group": { 31 | "kind": "test", 32 | "isDefault": true 33 | }, 34 | }, 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /404.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: 404 3 | --- 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ==================================================================================================== 3 | All notable changes will be documented in this file. 4 | OpenAPI Schemas adheres to [Semantic Versioning](http://semver.org/). 5 | 6 | 7 | [v2.0.0](https://github.com/APIDevTools/openapi-schemas/tree/v2.0.0) (2020-03-10) 8 | ---------------------------------------------------------------------------------------------------- 9 | 10 | - Moved OpenAPI Schemas to the [@APIDevTools scope](https://www.npmjs.com/org/apidevtools) on NPM 11 | 12 | - The "openapi-schemas" NPM package is now just a wrapper around the scoped "@apidevtools/openapi-schemas" package 13 | 14 | [Full Changelog](https://github.com/APIDevTools/openapi-schemas/compare/v1.0.3...v2.0.0) 15 | 16 | 17 | [v1.0.0](https://github.com/APIDevTools/openapi-schemas/tree/v1.0.0) (2019-06-22) 18 | ---------------------------------------------------------------------------------------------------- 19 | 20 | Initial release 🎉 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 James Messinger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenAPI Specification Schemas 2 | 3 | [![Cross-Platform Compatibility](https://apitools.dev/img/badges/os-badges.svg)](https://github.com/APIDevTools/openapi-schemas/actions) 4 | [![Build Status](https://github.com/APIDevTools/openapi-schemas/workflows/CI-CD/badge.svg?branch=master)](https://github.com/APIDevTools/openapi-schemas/actions) 5 | 6 | [![Coverage Status](https://coveralls.io/repos/github/APIDevTools/openapi-schemas/badge.svg?branch=master)](https://coveralls.io/github/APIDevTools/openapi-schemas) 7 | [![Dependencies](https://david-dm.org/APIDevTools/openapi-schemas.svg)](https://david-dm.org/APIDevTools/openapi-schemas) 8 | 9 | [![npm](https://img.shields.io/npm/v/@apidevtools/openapi-schemas.svg)](https://www.npmjs.com/package/@apidevtools/openapi-schemas) 10 | [![License](https://img.shields.io/npm/l/@apidevtools/openapi-schemas.svg)](LICENSE) 11 | [![Buy us a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen)](https://plant.treeware.earth/APIDevTools/openapi-schemas) 12 | 13 | 14 | 15 | This package contains [**the official JSON Schemas**](https://github.com/OAI/OpenAPI-Specification/tree/master/schemas) for every version of Swagger/OpenAPI Specification: 16 | 17 | | Version | Schema | Docs 18 | |---------|--------|------- 19 | | Swagger 1.2 | [v1.2 schema](https://github.com/OAI/OpenAPI-Specification/tree/master/schemas/v1.2) | [v1.2 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/1.2.md) 20 | | Swagger 2.0 | [v2.0 schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json) | [v2.0 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) 21 | | OpenAPI 3.0.x | [v3.0.x schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json) | [v3.0.3 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) 22 | | OpenAPI 3.1.x | [v3.1.x schema](https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.1/schema.json) | [v3.1.0 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md) 23 | 24 | 25 | All schemas are kept up-to-date with the latest official definitions via an automated CI/CD job. 🤖📦 26 | 27 | 28 | 29 | Installation 30 | -------------------------- 31 | You can install OpenAPI Schemas via [npm](https://docs.npmjs.com/about-npm/). 32 | 33 | ```bash 34 | npm install @apidevtools/openapi-schemas 35 | ``` 36 | 37 | 38 | 39 | Usage 40 | -------------------------- 41 | 42 | The default export contains all OpenAPI Specification versions: 43 | 44 | ```javascript 45 | const openapi = require("@apidevtools/openapi-schemas"); 46 | 47 | console.log(openapi.v1); // { $schema, id, properties, definitions, ... } 48 | console.log(openapi.v2); // { $schema, id, properties, definitions, ... } 49 | console.log(openapi.v3); // { $schema, id, properties, definitions, ... } 50 | console.log(openapi.v31); // { $schema, id, properties, definitions, ... } 51 | ``` 52 | 53 | Or you can import the specific version(s) that you need: 54 | 55 | ```javascript 56 | const { openapiV1, openapiV2, openapiV3, openapiV31 } = require("@apidevtools/openapi-schemas"); 57 | 58 | console.log(openapiV1); // { $schema, id, properties, definitions, ... } 59 | console.log(openapiV2); // { $schema, id, properties, definitions, ... } 60 | console.log(openapiV3); // { $schema, id, properties, definitions, ... } 61 | console.log(openapiV31); // { $schema, id, properties, definitions, ... } 62 | ``` 63 | 64 | You can use a JSON Schema validator such as [Z-Schema](https://www.npmjs.com/package/z-schema) or [AJV](https://www.npmjs.com/package/ajv) to validate OpenAPI definitions against the specification. 65 | 66 | ```javascript 67 | const { openapiV31 } = require("@apidevtools/openapi-schemas"); 68 | const ZSchema = require("z-schema"); 69 | 70 | // Create a ZSchema validator 71 | let validator = new ZSchema(); 72 | 73 | // Validate an OpenAPI definition against the OpenAPI v3.0 specification 74 | validator.validate(openapiDefinition, openapiV31); 75 | ``` 76 | 77 | 78 | 79 | Contributing 80 | -------------------------- 81 | Contributions, enhancements, and bug-fixes are welcome! [Open an issue](https://github.com/APIDevTools/openapi-schemas/issues) on GitHub and [submit a pull request](https://github.com/APIDevTools/openapi-schemas/pulls). 82 | 83 | #### Building 84 | To build the project locally on your computer: 85 | 86 | 1. __Clone this repo__
87 | `git clone https://github.com/APIDevTools/openapi-schemas.git` 88 | 89 | 2. __Install dependencies__
90 | `npm install` 91 | 92 | 3. __Build the code__
93 | `npm run build` 94 | 95 | 4. __Run the tests__
96 | `npm test` 97 | 98 | 99 | 100 | License 101 | -------------------------- 102 | OpenAPI Schemas is 100% free and open-source, under the [MIT license](LICENSE). Use it however you want. 103 | 104 | This package is [Treeware](http://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/APIDevTools/openapi-schemas) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats. 105 | 106 | 107 | 108 | Big Thanks To 109 | -------------------------- 110 | Thanks to these awesome companies for their support of Open Source developers ❤ 111 | 112 | [![GitHub](https://apitools.dev/img/badges/github.svg)](https://github.com/open-source) 113 | [![NPM](https://apitools.dev/img/badges/npm.svg)](https://www.npmjs.com/) 114 | [![Coveralls](https://apitools.dev/img/badges/coveralls.svg)](https://coveralls.io) 115 | [![Travis CI](https://apitools.dev/img/badges/travis-ci.svg)](https://travis-ci.com) 116 | [![SauceLabs](https://apitools.dev/img/badges/sauce-labs.svg)](https://saucelabs.com) 117 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: APIDevTools/gh-pages-theme 2 | 3 | title: OpenAPI Specification Schemas 4 | logo: https://apidevtools.com/img/logos/logo.png 5 | 6 | author: 7 | twitter: APIDevTools 8 | 9 | google_analytics: UA-68102273-2 10 | 11 | twitter: 12 | username: APIDevTools 13 | card: summary 14 | 15 | defaults: 16 | - scope: 17 | path: "" 18 | values: 19 | image: https://apidevtools.com/img/logos/card.png 20 | - scope: 21 | path: "test/**/*" 22 | values: 23 | sitemap: false 24 | 25 | plugins: 26 | - jekyll-sitemap 27 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import openapi from "@apidevtools/openapi-schemas"; 2 | export * from "@apidevtools/openapi-schemas"; 3 | export default openapi; 4 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | module.exports = require("@apidevtools/openapi-schemas"); 3 | -------------------------------------------------------------------------------- /dist/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openapi-schemas", 3 | "version": "X.X.X", 4 | "description": "JSON Schemas for every version of the OpenAPI Specification", 5 | "keywords": [ 6 | "openapi", 7 | "open-api", 8 | "swagger", 9 | "oas", 10 | "api", 11 | "rest", 12 | "json", 13 | "specification", 14 | "definition", 15 | "schema" 16 | ], 17 | "author": { 18 | "name": "James Messinger", 19 | "url": "https://jamesmessinger.com" 20 | }, 21 | "license": "MIT", 22 | "homepage": "https://apitools.dev/openapi-schemas", 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/APIDevTools/openapi-schemas.git" 26 | }, 27 | "main": "index.js", 28 | "types": "index.d.ts", 29 | "files": [ 30 | "index.js", 31 | "index.d.ts" 32 | ], 33 | "engines": { 34 | "node": ">=10" 35 | }, 36 | "dependencies": { 37 | "@apidevtools/openapi-schemas": "X.X.X" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@apidevtools/openapi-schemas", 3 | "version": "2.1.0", 4 | "description": "JSON Schemas for every version of the OpenAPI Specification", 5 | "keywords": [ 6 | "openapi", 7 | "open-api", 8 | "swagger", 9 | "oas", 10 | "api", 11 | "rest", 12 | "json", 13 | "specification", 14 | "definition", 15 | "schema" 16 | ], 17 | "author": { 18 | "name": "James Messinger", 19 | "url": "https://jamesmessinger.com" 20 | }, 21 | "license": "MIT", 22 | "homepage": "https://apitools.dev/openapi-schemas", 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/APIDevTools/openapi-schemas.git" 26 | }, 27 | "main": "lib/index.js", 28 | "types": "lib/index.d.ts", 29 | "files": [ 30 | "lib", 31 | "schemas" 32 | ], 33 | "scripts": { 34 | "clean": "shx rm -rf .nyc_output coverage lib .tmp schemas", 35 | "clone": "git clone https://github.com/OAI/OpenAPI-Specification.git .tmp", 36 | "copy": "shx cp -r .tmp/schemas schemas", 37 | "lint": "eslint src test", 38 | "build": "npm run build:schemas && npm run build:typescript", 39 | "build:schemas": "npm run clean && npm run clone && npm run copy", 40 | "build:typescript": "tsc", 41 | "watch": "tsc --watch", 42 | "test": "mocha && npm run lint", 43 | "coverage": "nyc node_modules/mocha/bin/mocha", 44 | "upgrade": "npm-check -u && npm audit fix", 45 | "bump": "bump --tag --push --all", 46 | "release": "npm run upgrade && npm run clean && npm run build && npm test && npm run bump" 47 | }, 48 | "engines": { 49 | "node": ">=10" 50 | }, 51 | "devDependencies": { 52 | "@jsdevtools/eslint-config": "^1.1.4", 53 | "@jsdevtools/version-bump-prompt": "^6.1.0", 54 | "@types/chai": "^4.2.17", 55 | "@types/command-line-args": "^5.0.0", 56 | "@types/mocha": "^8.2.2", 57 | "@types/node": "^15.0.1", 58 | "chai": "^4.3.4", 59 | "eslint": "^7.25.0", 60 | "mocha": "^8.3.2", 61 | "npm-check": "^5.9.2", 62 | "nyc": "^15.1.0", 63 | "shx": "^0.3.3", 64 | "typescript": "^4.2.4" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports */ 2 | import { JsonSchemaDraft4, JsonSchemaDraft202012 } from "./json-schema"; 3 | export { JsonSchemaDraft4, JsonSchemaDraft202012 }; 4 | 5 | /** 6 | * JSON Schema for OpenAPI Specification v1.2 7 | */ 8 | export const openapiV1 = require("../schemas/v1.2/apiDeclaration.json") as JsonSchemaDraft4; 9 | 10 | /** 11 | * JSON Schema for OpenAPI Specification v2.0 12 | */ 13 | export const openapiV2 = require("../schemas/v2.0/schema.json") as JsonSchemaDraft4; 14 | 15 | /** 16 | * JSON Schema for OpenAPI Specification v3.0 17 | */ 18 | export const openapiV3 = require("../schemas/v3.0/schema.json") as JsonSchemaDraft4; 19 | 20 | /** 21 | * JSON Schema for OpenAPI Specification v3.1 22 | */ 23 | export const openapiV31 = require("../schemas/v3.1/schema.json") as JsonSchemaDraft202012; 24 | 25 | /** 26 | * JSON Schemas for every version of the OpenAPI Specification 27 | */ 28 | export const openapi = { 29 | v1: openapiV1, 30 | v2: openapiV2, 31 | v3: openapiV3, 32 | v31: openapiV31, 33 | }; 34 | 35 | // Export `openapi` as the default export 36 | export default openapi; 37 | 38 | // CommonJS default export hack 39 | /* eslint-env commonjs */ 40 | if (typeof module === "object" && typeof module.exports === "object") { 41 | module.exports = Object.assign(module.exports.default, module.exports); 42 | } 43 | -------------------------------------------------------------------------------- /src/json-schema.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A JSON Schema 4.0 definition for an OpenAPI Specification 3 | */ 4 | export interface JsonSchemaDraft4 { 5 | id?: string; 6 | $schema?: string; 7 | title?: string; 8 | description?: string; 9 | multipleOf?: number; 10 | maximum?: number; 11 | exclusiveMaximum?: boolean; 12 | minimum?: number; 13 | exclusiveMinimum?: boolean; 14 | maxLength?: number; 15 | minLength?: number; 16 | pattern?: string; 17 | additionalItems?: boolean | JsonSchemaDraft4; 18 | items?: JsonSchemaDraft4 | JsonSchemaDraft4[]; 19 | maxItems?: number; 20 | minItems?: number; 21 | uniqueItems?: boolean; 22 | maxProperties?: number; 23 | minProperties?: number; 24 | required?: string[]; 25 | additionalProperties?: boolean | JsonSchemaDraft4; 26 | definitions?: { 27 | [name: string]: JsonSchemaDraft4; 28 | }; 29 | properties?: { 30 | [name: string]: JsonSchemaDraft4; 31 | }; 32 | patternProperties?: { 33 | [name: string]: JsonSchemaDraft4; 34 | }; 35 | dependencies?: { 36 | [name: string]: JsonSchemaDraft4 | string[]; 37 | }; 38 | enum?: string[]; 39 | type?: string | string[]; 40 | allOf?: JsonSchemaDraft4[]; 41 | anyOf?: JsonSchemaDraft4[]; 42 | oneOf?: JsonSchemaDraft4[]; 43 | not?: JsonSchemaDraft4; 44 | } 45 | 46 | /** 47 | * A JSON Schema 2020-12 definition for an OpenAPI Specification 48 | */ 49 | 50 | export interface JsonSchemaDraft202012 { 51 | $id?: string; 52 | $schema?: string; 53 | title?: string; 54 | description?: string; 55 | multipleOf?: number; 56 | maximum?: number; 57 | exclusiveMaximum?: boolean; 58 | minimum?: number; 59 | exclusiveMinimum?: boolean; 60 | maxLength?: number; 61 | minLength?: number; 62 | pattern?: string; 63 | additionalItems?: boolean | JsonSchemaDraft202012; 64 | items?: JsonSchemaDraft202012 | JsonSchemaDraft202012[]; 65 | maxItems?: number; 66 | minItems?: number; 67 | uniqueItems?: boolean; 68 | maxProperties?: number; 69 | minProperties?: number; 70 | required?: string[]; 71 | additionalProperties?: boolean | JsonSchemaDraft202012; 72 | $defs?: { 73 | [name: string]: JsonSchemaDraft202012; 74 | }; 75 | properties?: { 76 | [name: string]: JsonSchemaDraft202012; 77 | }; 78 | patternProperties?: { 79 | [name: string]: JsonSchemaDraft202012; 80 | }; 81 | dependencies?: { 82 | [name: string]: JsonSchemaDraft202012 | string[]; 83 | }; 84 | enum?: string[]; 85 | type?: string | string[]; 86 | allOf?: JsonSchemaDraft202012[]; 87 | anyOf?: JsonSchemaDraft202012[]; 88 | oneOf?: JsonSchemaDraft202012[]; 89 | not?: JsonSchemaDraft202012; 90 | } 91 | -------------------------------------------------------------------------------- /test/specs/exports.spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const commonJSExport = require("../../"); 4 | const { default: defaultExport, openapi: namedExport } = require("../../"); 5 | const { v1, v2, v3, v31, openapiV1, openapiV2, openapiV3, openapiV31 } = require("../../"); 6 | const { expect } = require("chai"); 7 | 8 | describe("openapi-schemas package exports", () => { 9 | 10 | const specVersions = ["v1", "v2", "v3", "v31", "openapiV1", "openapiV2", "openapiV3", "openapiV31"]; 11 | const exports = ["default", "openapi", ...specVersions]; 12 | 13 | /** 14 | * Asserts that the given object contains every verion of the OpenAPI Specification 15 | */ 16 | function isAllSpecs (obj) { 17 | expect(obj).to.be.an("object").and.have.keys(exports); 18 | expect(obj.default).to.equal(obj); 19 | expect(obj.openapi).to.equal(obj); 20 | expect(obj.v1).to.satisfy(isJsonSchemaDraft4); 21 | expect(obj.v2).to.satisfy(isJsonSchemaDraft4); 22 | expect(obj.v3).to.satisfy(isJsonSchemaDraft4); 23 | expect(obj.v31).to.satisfy(isJsonSchemaDraft202012); 24 | expect(obj.openapiV1).to.satisfy(isJsonSchemaDraft4); 25 | expect(obj.openapiV2).to.satisfy(isJsonSchemaDraft4); 26 | expect(obj.openapiV3).to.satisfy(isJsonSchemaDraft4); 27 | expect(obj.openapiV31).to.satisfy(isJsonSchemaDraft202012); 28 | return true; 29 | } 30 | 31 | /** 32 | * Assets that the given object is a JSON schema 33 | */ 34 | function isJsonSchemaDraft4 (obj) { 35 | expect(obj).to.be.an("object"); 36 | expect(obj).to.include.keys("id", "$schema", "properties", "definitions"); 37 | expect(obj).not.to.have.any.keys(exports); 38 | return true; 39 | } 40 | 41 | function isJsonSchemaDraft202012 (obj) { 42 | expect(obj).to.be.an("object"); 43 | expect(obj).to.include.keys("$id", "$schema", "properties", "$defs"); 44 | expect(obj).not.to.have.any.keys(exports); 45 | return true; 46 | } 47 | 48 | it("should export the openapi object as the default CommonJS export", () => { 49 | expect(commonJSExport).to.satisfy(isAllSpecs); 50 | }); 51 | 52 | it("should export the openapi object as the default ESM export", () => { 53 | expect(defaultExport).satisfy(isAllSpecs); 54 | }); 55 | 56 | it("should export the openapi object as a named export", () => { 57 | expect(namedExport).to.satisfy(isAllSpecs); 58 | }); 59 | 60 | it("should export the openapiV1 object as a named export", () => { 61 | expect(v1).to.satisfy(isJsonSchemaDraft4); 62 | expect(openapiV1).to.equal(v1); 63 | expect(v1.properties.swaggerVersion.enum).to.deep.equal(["1.2"]); 64 | }); 65 | 66 | it("should export the openapiV2 object as a named export", () => { 67 | expect(v2).to.satisfy(isJsonSchemaDraft4); 68 | expect(openapiV2).to.equal(v2); 69 | expect(v2.properties.swagger.enum).to.deep.equal(["2.0"]); 70 | }); 71 | 72 | it("should export the openapiV3 object as a named export", () => { 73 | expect(v3).to.satisfy(isJsonSchemaDraft4); 74 | expect(openapiV3).to.equal(v3); 75 | expect(v3.properties.openapi.pattern).to.equal("^3\\.0\\.\\d(-.+)?$"); 76 | }); 77 | 78 | it("should export the openapiV31 object as a named export", () => { 79 | expect(v31).to.satisfy(isJsonSchemaDraft202012); 80 | expect(openapiV31).to.equal(v31); 81 | expect(v31.properties.openapi.pattern).to.equal("^3\\.1\\.\\d+(-.+)?$"); 82 | }); 83 | 84 | }); 85 | -------------------------------------------------------------------------------- /test/specs/hashes.spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const { openapi } = require("../../lib"); 4 | const { expect } = require("chai"); 5 | const crypto = require("crypto"); 6 | 7 | describe("Schema hashes", () => { 8 | 9 | /** 10 | * These hashes match the versions that are currently published to NPM. 11 | * If the hashes ever change, then we want the build to fail so that we 12 | * have to publish the latest versions to NPM. 13 | */ 14 | const hashes = { 15 | openapiV1: "fedbb966f17e54afd8ddcb87cb12d4b42715fbb493a66581861cf2f8aa4d6b10", 16 | openapiV2: "220e4d47e8dbd8f72a612898429b970bfd652e663569f7202002ceb9767e033a", 17 | openapiV3: "12ba334b36afd9443f1a04cf7fccf09b4a8059d1b7f851faebe91cf60d01f633", 18 | openapiV31: "549386120954be0bdd3778c72ceb376becb83489b4143fe9c26b0b65ebe9891e", 19 | }; 20 | 21 | for (let [version, hash] of Object.entries(hashes)) { 22 | it(`should match the ${version} hash that's currently published to NPM`, () => { 23 | let json = JSON.stringify(openapi[version]); 24 | let sha256 = crypto.createHash("sha256").update(json).digest("hex"); 25 | 26 | try { 27 | expect(sha256).to.equal(hash); 28 | } 29 | catch (error) { 30 | console.error( 31 | "\n================================================================================" + 32 | `\nThe ${version} schema has changed!\n` + 33 | `\nThe hash that's currently published to NPM is: ${hash}` + 34 | `\nThe hash of the latest OpenAPI Specification is: ${sha256}` + 35 | "\n================================================================================\n" 36 | ); 37 | throw error; 38 | } 39 | }); 40 | } 41 | 42 | }); 43 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "resolveJsonModule": true, 7 | 8 | "outDir": "lib", 9 | "sourceMap": true, 10 | "declaration": true, 11 | 12 | "newLine": "LF", 13 | "forceConsistentCasingInFileNames": true, 14 | "noFallthroughCasesInSwitch": true, 15 | "noImplicitAny": true, 16 | "noImplicitThis": true, 17 | "strictBindCallApply": true, 18 | "strictNullChecks": true, 19 | "strictPropertyInitialization": true, 20 | "stripInternal": true, 21 | 22 | "typeRoots": [ 23 | "node_modules/@types", 24 | "src/typings" 25 | ] 26 | }, 27 | "include": [ 28 | "src/**/*.ts" 29 | ], 30 | "exclude": [ 31 | "node_modules" 32 | ] 33 | } 34 | --------------------------------------------------------------------------------