├── .babelrc ├── .eslintrc.json ├── .github ├── dependabot.yml └── workflows │ └── tests.yml ├── .gitignore ├── LICENSE ├── MAINTAINING.md ├── README.md ├── docs └── examples │ ├── index.md │ └── update-info-description.md ├── index.js ├── package.json ├── src └── overlay.js └── test ├── actual └── .gitignore ├── expected ├── empty.yaml ├── immutable.yaml ├── not-jsonpath.yaml ├── not-overlay.yaml ├── one-less-server.yaml ├── output1.yaml ├── remove-responses.yaml ├── town-building-description.yaml ├── town-remove-descriptions.yaml ├── town-remove-example.yaml ├── town-remove-properties.yaml └── town-root-updated.yaml ├── openapi ├── empty.yaml ├── immutable.yaml ├── not-jsonpath.yaml ├── not-overlay.yaml ├── openapi-with-servers.yaml ├── petstore.yaml ├── responses.yaml └── town.yaml ├── overlay.test.js └── overlays ├── building-description.yaml ├── empty.yaml ├── immutable.yaml ├── not-jsonpath.yaml ├── not-overlay.yaml ├── overlay.yaml ├── remove-descriptions.yaml ├── remove-example.yaml ├── remove-properties.yaml ├── remove-responses.yaml ├── remove-server.yaml └── update-root.yaml /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | 5 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true, 5 | "mocha": true, 6 | "jest": true 7 | }, 8 | "extends": "standard", 9 | "parserOptions": { 10 | "ecmaVersion": "latest", 11 | "sourceType": "module" 12 | }, 13 | "rules": { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Node.js CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | node-version: [16.x, 18.x, 20.x] 17 | 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Use Node.js ${{ matrix.node-version }} 21 | uses: actions/setup-node@v3 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | - run: npm install 25 | - run: npm run lint 26 | - run: npm test 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MAINTAINING.md: -------------------------------------------------------------------------------- 1 | The maintainers file is instructions for maintainers on operating the project. 2 | Especially useful for things that don't need to be done often! 3 | 4 | ## Releasing a package version 5 | 6 | 1. Update `package.json` with the new version number, and merge this change to the main branch. 7 | 8 | 2. Tag the main branch with the new version `git tag -a v0.1.0 -m "Release version 0.1.0"`. 9 | 10 | 3. Push the tag to the repo: `git push origin v0.1.0`. 11 | 12 | 4. Publish to npm: `npm publish`. 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overlays for OpenAPI 2 | 3 | This NodeJS library is an implementation of the in-progress [OpenAPI Overlays Specification](https://github.com/OAI/Overlay-Specification/blob/main/versions/1.0.0.md). 4 | 5 | ## About Overlays 6 | 7 | Overlays are a way to extend or enhance an existing [OpenAPI description](https://www.openapis.org/) by adding, updating or removing fields. For example: 8 | 9 | * The OpenAPI description lives in the codebase, but your tech writers need to add examples and information before documentation is produced. 10 | * Your organisation uses OpenAPI but it's generated from code, and needs amendments or additions to be useful to users. 11 | * You're using other tools such as API client generators, that can make use of additional context added to the API description, such as tags to remove certain endpoints, which aren't in the main API description file. 12 | 13 | **By using Overlays to describe and apply the changes, when the API description is updated, the same changes can instantly be re-applied.** 14 | 15 | ## Installation 16 | 17 | Install the `overlayjs` command from [npm](https://npmjs.com) with the following command: 18 | 19 | ```text 20 | npm install -g openapi-overlays-js 21 | ``` 22 | 23 | The `-g` switch installs it globally so you can use the command from anywhere on your system. 24 | 25 | > **Pro-tip:** use `node index.js` from the root of the project if you're using the bleeding edge of the project or working on a branch. 26 | 27 | ## Usage 28 | 29 | Example: `overlayjs --openapi openapi.yml --overlay add-sparkle.yaml` 30 | 31 | Use `overlayjs --help` to see the usage information. 32 | 33 | See [docs/examples](https://github.com/lornajane/openapi-overlays-js/blob/main/docs/examples/index.md) for more examples. 34 | 35 | ## Project status 36 | 37 | :warning: Project status: alpha 38 | 39 | This project is very much at an alpha stage but feedback, comments and questions are all very welcome as issues on this repository - and pull requests are also gratefully received. It would be excellent to hear what problem this tool can solve, and how you get on with it. Bonus points if you can share examples (working or broken) of what you tried. 40 | -------------------------------------------------------------------------------- /docs/examples/index.md: -------------------------------------------------------------------------------- 1 | # Overlays examples 2 | 3 | - [Update `info.description`](./update-info-description.md) 4 | 5 | ## About examples 6 | 7 | These are examples of common tasks. 8 | Issues to request/suggest more example use cases, or pull requests to add your own examples, are all gratefully received. 9 | -------------------------------------------------------------------------------- /docs/examples/update-info-description.md: -------------------------------------------------------------------------------- 1 | # Update `info.description` 2 | 3 | A common task, to update a description in an OpenAPI document. 4 | This is useful to add a meaningful description to a generated OpenAPI file, or to adjust a description to match a transformed OpenAPI document (perhaps after doing some overlay-powered surgery). 5 | 6 | > [!TIP] 7 | > Overlays operate on objects, not single primitive fields such as strings. 8 | > So to update the `info.description`, target `info` and update `description` within it. 9 | 10 | ## Overlay 11 | 12 | An overlay that targets the `info` section and updates it with a new multiline Markdown `description` field. 13 | 14 | ```yaml 15 | overlay: 1.0.0 16 | info: 17 | title: Overlay to update the description 18 | version: 0.1.0 19 | actions: 20 | - target: $.info 21 | update: 22 | description: >- 23 | A meaningful description for your API helps users to understand how to 24 | get started with your platform. Description fields support Markdown and 25 | the `>-` notation at the start makes this multiline Markdown. 26 | 27 | You can link to your [project README](https://github.com/lornajane/openapi-overlays-js) 28 | or other resources from here as well. 29 | ``` 30 | 31 | ## OpenAPI 32 | 33 | Simplest OpenAPI file I can think of: 34 | 35 | ```yaml 36 | openapi: 3.1.0 37 | info: 38 | title: Example API 39 | version: 1.0.0 40 | paths: 41 | /example: 42 | get: 43 | responses: 44 | '200': 45 | description: A simple example response 46 | content: 47 | application/json: 48 | schema: 49 | type: object 50 | properties: 51 | message: 52 | type: string 53 | ``` 54 | 55 | ## Updated OpenAPI 56 | 57 | After overlaying: 58 | 59 | ```yaml 60 | openapi: 3.1.0 61 | info: 62 | title: Example API 63 | version: 1.0.0 64 | description: >- 65 | A meaningful description for your API helps users to understand how to get 66 | started with your platform. Description fields support Markdown and the `>-` 67 | notation at the start makes this multiline Markdown. 68 | 69 | You can link to your [project 70 | README](https://github.com/lornajane/openapi-overlays-js) or other resources 71 | from here as well. 72 | paths: 73 | /example: 74 | get: 75 | responses: 76 | '200': 77 | description: A simple example response 78 | content: 79 | application/json: 80 | schema: 81 | type: object 82 | properties: 83 | message: 84 | type: string 85 | ``` 86 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import arg from 'arg' 3 | import fs from 'fs' 4 | import { overlayFiles } from './src/overlay.js' 5 | 6 | function showHelp () { 7 | console.log('Usage: overlayjs --openapi FILEPATH --overlay FILEPATH') 8 | console.log(' use --help to see this help') 9 | } 10 | 11 | // Function to read the version from package.json 12 | function showVersion () { 13 | const packageJsonPath = './package.json' 14 | const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) 15 | console.log(packageJson.version) 16 | } 17 | 18 | try { 19 | const args = arg({ 20 | '--openapi': String, 21 | '--overlay': String, 22 | '--version': Boolean, 23 | '--help': Boolean 24 | }) 25 | 26 | if (args['--version']) { 27 | showVersion() 28 | process.exit(0) 29 | } 30 | 31 | if (args['--overlay'] && args['--openapi']) { 32 | const openapiFile = args['--openapi'] 33 | const overlayFile = args['--overlay'] 34 | const spec = overlayFiles(openapiFile, overlayFile) 35 | console.log(spec) 36 | } else { 37 | showHelp() 38 | } 39 | } catch (err) { 40 | if (err.code === 'ARG_UNKNOWN_OPTION') { 41 | console.warn(err.message) 42 | showHelp() 43 | } else { 44 | throw err 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openapi-overlays-js", 3 | "version": "0.2.0", 4 | "description": "Tool to apply OpenAPI overlays, built in NodeJS with a command line interface (CLI).", 5 | "main": "index.js", 6 | "bin": { 7 | "overlayjs": "./index.js" 8 | }, 9 | "scripts": { 10 | "test": "node_modules/.bin/jest", 11 | "lint": "eslint . --config .eslintrc.json", 12 | "fmt": "eslint . --config .eslintrc.json --fix" 13 | }, 14 | "type": "module", 15 | "author": "Lorna Mitchell ", 16 | "homepage": "https://github.com/lornajane/openapi-overlays-js#readme", 17 | "bugs": "https://github.com/lornajane/openapi-overlays-js/issues", 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/lornajane/openapi-overlays-js.git" 21 | }, 22 | "license": "Apache2", 23 | "dependencies": { 24 | "@stoplight/yaml": "^4.2.3", 25 | "arg": "^5.0.2", 26 | "jsonpath": "^1.1.1", 27 | "mergician": "^1.0.3", 28 | "openapi-format": "^1.13.0" 29 | }, 30 | "devDependencies": { 31 | "@babel/core": "^7.20.12", 32 | "@babel/preset-env": "^7.20.2", 33 | "babel-jest": "^29.4.1", 34 | "eslint": "^8.57.0", 35 | "eslint-config-standard": "^17.1.0", 36 | "eslint-plugin-import": "^2.29.1", 37 | "eslint-plugin-n": "^16.6.2", 38 | "eslint-plugin-promise": "^6.1.1", 39 | "jest": "^29.4.1" 40 | }, 41 | "jest": { 42 | "transform": { 43 | "^.+\\.js$": "babel-jest" 44 | }, 45 | "testEnvironment": "node" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/overlay.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import jsonpath from 'jsonpath' 3 | import { safeStringify, parseWithPointers } from '@stoplight/yaml' 4 | import mergician from 'mergician' 5 | 6 | function applyOverlayToOpenAPI (spec, overlay) { 7 | // Use jsonpath.apply to do the changes 8 | if (overlay.actions && overlay.actions.length >= 1) { 9 | overlay.actions.forEach((a) => { 10 | // Is it a remove? 11 | if (Object.prototype.hasOwnProperty.call(a, 'remove')) { 12 | while (true) { 13 | const path = jsonpath.paths(spec, a.target) 14 | if (path.length === 0) { 15 | break 16 | } 17 | const parent = jsonpath.parent(spec, a.target) 18 | const thingToRemove = path[0][path[0].length - 1] 19 | if (Array.isArray(parent)) { 20 | parent.splice(thingToRemove, 1) 21 | } else { 22 | delete parent[thingToRemove] 23 | } 24 | } 25 | } else { 26 | try { 27 | // It must be an update 28 | if (a.target === '$') { 29 | spec = merger(a.update)(spec) 30 | } else { 31 | jsonpath.apply(spec, a.target, merger(a.update)) 32 | } 33 | } catch (ex) { 34 | process.stderr.write(`Error applying overlay: ${ex.message}\n`) 35 | // return chunk 36 | } 37 | } 38 | }) 39 | } 40 | 41 | return spec 42 | } 43 | 44 | // Deep merge using a module (built-in spread operator is only shallow) 45 | function merger (obj) { 46 | return (chunk) => { 47 | return mergician({ appendArrays: true })(chunk, obj) 48 | } 49 | } 50 | 51 | function sortOpenAPIFields (field1, field2) { 52 | const orderedKeys = ['info', 'servers', 'summary', 'operationId', 'tags', 'paths', 'components', 'description', 'parameters', 'responses'] 53 | 54 | const index1 = orderedKeys.indexOf(field1) 55 | const index2 = orderedKeys.indexOf(field2) 56 | 57 | if (index1 === -1 || index2 === -1) { 58 | return 0 59 | } else if (index1 > index2) { 60 | return 1 61 | } else { 62 | return -1 63 | } 64 | } 65 | 66 | export function applyOverlay (definition, overlay) { 67 | return applyOverlayToOpenAPI(definition, overlay) 68 | } 69 | 70 | export function overlayFiles (openapiFile, overlayFile) { 71 | // Parse the "input" OpenAPI document 72 | const specraw = fs.readFileSync(openapiFile, 'utf8') 73 | let spec = parseWithPointers(specraw).data 74 | 75 | // Parse the "overlay" document 76 | const overlayraw = fs.readFileSync(overlayFile, 'utf8') 77 | const overlay = parseWithPointers(overlayraw).data 78 | 79 | spec = applyOverlayToOpenAPI(spec, overlay) 80 | 81 | // Return the new spec 82 | return safeStringify(spec, { sortKeys: sortOpenAPIFields }) 83 | } 84 | -------------------------------------------------------------------------------- /test/actual/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lornajane/openapi-overlays-js/d33380593aaf78aabff11a7946fd18b7bcfe91e5/test/actual/.gitignore -------------------------------------------------------------------------------- /test/expected/empty.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | tags: 6 | - name: Things 7 | paths: {} 8 | -------------------------------------------------------------------------------- /test/expected/immutable.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | paths: {} 6 | -------------------------------------------------------------------------------- /test/expected/not-jsonpath.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | tags: 6 | - name: Things 7 | paths: {} 8 | -------------------------------------------------------------------------------- /test/expected/not-overlay.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | tags: 6 | - name: Things 7 | paths: {} 8 | -------------------------------------------------------------------------------- /test/expected/one-less-server.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | title: API servers 4 | version: 1.0.0 5 | servers: 6 | - url: 'https://api.example.com' 7 | description: Production 8 | paths: {} 9 | -------------------------------------------------------------------------------- /test/expected/output1.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 | operationId: listPets 13 | tags: 14 | - pets 15 | - wildcard-done 16 | - overlayed 17 | parameters: 18 | - name: limit 19 | in: query 20 | description: How many items to return at one time (max 100) 21 | required: false 22 | schema: 23 | type: integer 24 | maximum: 100 25 | format: int32 26 | responses: 27 | '200': 28 | description: A paged array of pets 29 | headers: 30 | x-next: 31 | description: A link to the next page of responses 32 | schema: 33 | type: string 34 | content: 35 | application/json: 36 | schema: 37 | $ref: '#/components/schemas/Pets' 38 | default: 39 | description: unexpected error 40 | content: 41 | application/json: 42 | schema: 43 | $ref: '#/components/schemas/Error' 44 | x-info: 45 | x-overlay-applied: structured-overlay 46 | description: This is an added description 47 | post: 48 | foo: 49 | bar: hello 50 | '/pets/{petId}': 51 | get: 52 | summary: Info for a specific pet 53 | operationId: showPetById 54 | tags: 55 | - pets 56 | - wildcard-done 57 | parameters: 58 | - name: petId 59 | in: path 60 | required: true 61 | description: The id of the pet to retrieve 62 | schema: 63 | type: string 64 | responses: 65 | '200': 66 | description: Expected response to a valid request 67 | content: 68 | application/json: 69 | schema: 70 | $ref: '#/components/schemas/Pet' 71 | default: 72 | description: unexpected error 73 | content: 74 | application/json: 75 | schema: 76 | $ref: '#/components/schemas/Error' 77 | post: 78 | foo: 79 | bar: hello 80 | components: 81 | schemas: 82 | Pet: 83 | type: object 84 | required: 85 | - id 86 | - name 87 | properties: 88 | id: 89 | type: integer 90 | format: int64 91 | name: 92 | type: string 93 | tag: 94 | type: string 95 | Pets: 96 | type: array 97 | maxItems: 100 98 | items: 99 | $ref: '#/components/schemas/Pet' 100 | Error: 101 | type: object 102 | required: 103 | - code 104 | - message 105 | properties: 106 | code: 107 | type: integer 108 | format: int32 109 | message: 110 | type: string 111 | -------------------------------------------------------------------------------- /test/expected/remove-responses.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | title: Responses 4 | version: 1.0.0 5 | paths: 6 | /foo: 7 | get: 8 | responses: 9 | '200': 10 | description: OK 11 | /bar: 12 | post: 13 | responses: 14 | '201': 15 | description: Created 16 | /baa: 17 | post: 18 | responses: 19 | '201': 20 | description: Shouted 21 | -------------------------------------------------------------------------------- /test/expected/town-building-description.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: Imaginary town 5 | servers: 6 | - url: 'https://example.com' 7 | description: Example server 8 | paths: 9 | /buildings: 10 | get: 11 | summary: All of the available buildings 12 | operationId: buildingsList 13 | description: This is the summary of getting the buildings 14 | responses: 15 | '200': 16 | description: Return all known buildings 17 | content: 18 | application/json: 19 | schema: 20 | type: array 21 | items: 22 | $ref: '#/components/schemas/Building' 23 | '/buildings/{buildingId}': 24 | get: 25 | summary: Specific building 26 | operationId: buildingById 27 | parameters: 28 | - name: buildingId 29 | in: path 30 | required: true 31 | description: Which building to return 32 | schema: 33 | type: string 34 | responses: 35 | '200': 36 | description: Return a building 37 | content: 38 | application/json: 39 | schema: 40 | $ref: '#/components/schemas/Building' 41 | /locations: 42 | get: 43 | summary: All locations 44 | operationId: locationList 45 | responses: 46 | '200': 47 | description: Returns all locations 48 | content: 49 | application/json: 50 | schema: 51 | type: array 52 | items: 53 | type: object 54 | properties: 55 | location_id: 56 | type: integer 57 | example: 44 58 | name: 59 | type: string 60 | example: North Village 61 | components: 62 | schemas: 63 | Building: 64 | type: object 65 | properties: 66 | building: 67 | type: string 68 | example: house 69 | location_id: 70 | type: integer 71 | example: 44 72 | -------------------------------------------------------------------------------- /test/expected/town-remove-descriptions.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: Imaginary town 5 | servers: 6 | - url: 'https://example.com' 7 | paths: 8 | /buildings: 9 | get: 10 | summary: All buildings 11 | operationId: buildingsList 12 | responses: 13 | '200': 14 | content: 15 | application/json: 16 | schema: 17 | type: array 18 | items: 19 | $ref: '#/components/schemas/Building' 20 | '/buildings/{buildingId}': 21 | get: 22 | summary: Specific building 23 | operationId: buildingById 24 | parameters: 25 | - name: buildingId 26 | in: path 27 | required: true 28 | schema: 29 | type: string 30 | responses: 31 | '200': 32 | content: 33 | application/json: 34 | schema: 35 | $ref: '#/components/schemas/Building' 36 | /locations: 37 | get: 38 | summary: All locations 39 | operationId: locationList 40 | responses: 41 | '200': 42 | content: 43 | application/json: 44 | schema: 45 | type: array 46 | items: 47 | type: object 48 | properties: 49 | location_id: 50 | type: integer 51 | example: 44 52 | name: 53 | type: string 54 | example: North Village 55 | components: 56 | schemas: 57 | Building: 58 | type: object 59 | properties: 60 | building: 61 | type: string 62 | example: house 63 | location_id: 64 | type: integer 65 | example: 44 66 | -------------------------------------------------------------------------------- /test/expected/town-remove-example.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: Imaginary town 5 | servers: 6 | - url: 'https://example.com' 7 | description: Example server 8 | paths: 9 | /buildings: 10 | get: 11 | summary: All buildings 12 | operationId: buildingsList 13 | responses: 14 | '200': 15 | description: Return all known buildings 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | $ref: '#/components/schemas/Building' 22 | '/buildings/{buildingId}': 23 | get: 24 | summary: Specific building 25 | operationId: buildingById 26 | parameters: 27 | - name: buildingId 28 | in: path 29 | required: true 30 | description: Which building to return 31 | schema: 32 | type: string 33 | responses: 34 | '200': 35 | description: Return a building 36 | content: 37 | application/json: 38 | schema: 39 | $ref: '#/components/schemas/Building' 40 | /locations: 41 | get: 42 | summary: All locations 43 | operationId: locationList 44 | responses: 45 | '200': 46 | description: Returns all locations 47 | content: 48 | application/json: 49 | schema: 50 | type: array 51 | items: 52 | type: object 53 | properties: 54 | location_id: 55 | type: integer 56 | example: 44 57 | name: 58 | type: string 59 | example: North Village 60 | components: 61 | schemas: 62 | Building: 63 | type: object 64 | properties: 65 | building: 66 | type: string 67 | location_id: 68 | type: integer 69 | example: 44 70 | -------------------------------------------------------------------------------- /test/expected/town-remove-properties.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: Imaginary town 5 | servers: 6 | - url: 'https://example.com' 7 | description: Example server 8 | paths: 9 | /buildings: 10 | get: 11 | summary: All buildings 12 | operationId: buildingsList 13 | responses: 14 | '200': 15 | description: Return all known buildings 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | $ref: '#/components/schemas/Building' 22 | '/buildings/{buildingId}': 23 | get: 24 | summary: Specific building 25 | operationId: buildingById 26 | parameters: 27 | - name: buildingId 28 | in: path 29 | required: true 30 | description: Which building to return 31 | schema: 32 | type: string 33 | responses: 34 | '200': 35 | description: Return a building 36 | content: 37 | application/json: 38 | schema: 39 | $ref: '#/components/schemas/Building' 40 | /locations: 41 | get: 42 | summary: All locations 43 | operationId: locationList 44 | responses: 45 | '200': 46 | description: Returns all locations 47 | content: 48 | application/json: 49 | schema: 50 | type: array 51 | items: 52 | type: object 53 | properties: 54 | location_id: 55 | type: integer 56 | example: 44 57 | components: 58 | schemas: 59 | Building: 60 | type: object 61 | properties: 62 | building: 63 | type: string 64 | example: house 65 | location_id: 66 | type: integer 67 | example: 44 68 | -------------------------------------------------------------------------------- /test/expected/town-root-updated.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: Imaginary town 5 | x-overlaid: true 6 | servers: 7 | - url: 'https://example.com' 8 | description: Example server 9 | paths: 10 | /buildings: 11 | get: 12 | summary: All buildings 13 | operationId: buildingsList 14 | responses: 15 | '200': 16 | description: Return all known buildings 17 | content: 18 | application/json: 19 | schema: 20 | type: array 21 | items: 22 | $ref: '#/components/schemas/Building' 23 | '/buildings/{buildingId}': 24 | get: 25 | summary: Specific building 26 | operationId: buildingById 27 | parameters: 28 | - name: buildingId 29 | in: path 30 | required: true 31 | description: Which building to return 32 | schema: 33 | type: string 34 | responses: 35 | '200': 36 | description: Return a building 37 | content: 38 | application/json: 39 | schema: 40 | $ref: '#/components/schemas/Building' 41 | /locations: 42 | get: 43 | summary: All locations 44 | operationId: locationList 45 | responses: 46 | '200': 47 | description: Returns all locations 48 | content: 49 | application/json: 50 | schema: 51 | type: array 52 | items: 53 | type: object 54 | properties: 55 | location_id: 56 | type: integer 57 | example: 44 58 | name: 59 | type: string 60 | example: North Village 61 | components: 62 | schemas: 63 | Building: 64 | type: object 65 | properties: 66 | building: 67 | type: string 68 | example: house 69 | location_id: 70 | type: integer 71 | example: 44 72 | -------------------------------------------------------------------------------- /test/openapi/empty.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | tags: 6 | - name: Things 7 | paths: {} 8 | -------------------------------------------------------------------------------- /test/openapi/immutable.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | paths: {} 6 | -------------------------------------------------------------------------------- /test/openapi/not-jsonpath.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | tags: 6 | - name: Things 7 | paths: {} 8 | -------------------------------------------------------------------------------- /test/openapi/not-overlay.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | version: 1.0.0 4 | title: API 5 | tags: 6 | - name: Things 7 | paths: {} 8 | -------------------------------------------------------------------------------- /test/openapi/openapi-with-servers.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | title: API servers 4 | version: 1.0.0 5 | servers: 6 | - url: 'https://api.dev.example.com' 7 | description: Dev 8 | - url: 'https://api.example.com' 9 | description: Production 10 | paths: {} 11 | -------------------------------------------------------------------------------- /test/openapi/petstore.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 | maximum: 100 24 | format: int32 25 | responses: 26 | '200': 27 | description: A paged array of pets 28 | headers: 29 | x-next: 30 | description: A link to the next page of responses 31 | schema: 32 | type: string 33 | content: 34 | application/json: 35 | schema: 36 | $ref: "#/components/schemas/Pets" 37 | default: 38 | description: unexpected error 39 | content: 40 | application/json: 41 | schema: 42 | $ref: "#/components/schemas/Error" 43 | /pets/{petId}: 44 | get: 45 | summary: Info for a specific pet 46 | operationId: showPetById 47 | tags: 48 | - pets 49 | parameters: 50 | - name: petId 51 | in: path 52 | required: true 53 | description: The id of the pet to retrieve 54 | schema: 55 | type: string 56 | responses: 57 | '200': 58 | description: Expected response to a valid request 59 | content: 60 | application/json: 61 | schema: 62 | $ref: "#/components/schemas/Pet" 63 | default: 64 | description: unexpected error 65 | content: 66 | application/json: 67 | schema: 68 | $ref: "#/components/schemas/Error" 69 | components: 70 | schemas: 71 | Pet: 72 | type: object 73 | required: 74 | - id 75 | - name 76 | properties: 77 | id: 78 | type: integer 79 | format: int64 80 | name: 81 | type: string 82 | tag: 83 | type: string 84 | Pets: 85 | type: array 86 | maxItems: 100 87 | items: 88 | $ref: "#/components/schemas/Pet" 89 | Error: 90 | type: object 91 | required: 92 | - code 93 | - message 94 | properties: 95 | code: 96 | type: integer 97 | format: int32 98 | message: 99 | type: string 100 | -------------------------------------------------------------------------------- /test/openapi/responses.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.1.0 2 | info: 3 | title: Responses 4 | version: 1.0.0 5 | paths: 6 | /foo: 7 | get: 8 | responses: 9 | '200': 10 | description: OK 11 | '500': 12 | description: oops 13 | /bar: 14 | post: 15 | responses: 16 | '201': 17 | description: Created 18 | '500': 19 | description: oops 20 | default: 21 | description: something 22 | /baa: 23 | post: 24 | responses: 25 | '201': 26 | description: Shouted 27 | '500': 28 | description: oops 29 | default: 30 | description: something 31 | -------------------------------------------------------------------------------- /test/openapi/town.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.1.0" 2 | info: 3 | version: 1.0.0 4 | title: Imaginary town 5 | servers: 6 | - url: https://example.com 7 | description: Example server 8 | paths: 9 | '/buildings': 10 | get: 11 | summary: All buildings 12 | operationId: buildingsList 13 | responses: 14 | '200': 15 | description: Return all known buildings 16 | content: 17 | application/json: 18 | schema: 19 | type: array 20 | items: 21 | $ref: "#/components/schemas/Building" 22 | 23 | '/buildings/{buildingId}': 24 | get: 25 | summary: Specific building 26 | operationId: buildingById 27 | parameters: 28 | - name: buildingId 29 | in: path 30 | required: true 31 | description: Which building to return 32 | schema: 33 | type: string 34 | responses: 35 | '200': 36 | description: Return a building 37 | content: 38 | application/json: 39 | schema: 40 | $ref: "#/components/schemas/Building" 41 | 42 | '/locations': 43 | get: 44 | summary: All locations 45 | operationId: locationList 46 | responses: 47 | '200': 48 | description: Returns all locations 49 | content: 50 | application/json: 51 | schema: 52 | type: array 53 | items: 54 | type: object 55 | properties: 56 | location_id: 57 | type: integer 58 | example: 44 59 | name: 60 | type: string 61 | example: "North Village" 62 | 63 | components: 64 | schemas: 65 | Building: 66 | type: object 67 | properties: 68 | building: 69 | type: string 70 | example: "house" 71 | location_id: 72 | type: integer 73 | example: 44 74 | -------------------------------------------------------------------------------- /test/overlay.test.js: -------------------------------------------------------------------------------- 1 | import { overlayFiles } from '../src/overlay.js' 2 | import fs from 'fs' 3 | 4 | test('apply an overlay and check the output', () => { 5 | const openapiFile = 'test/openapi/petstore.yaml' 6 | const overlayFile = 'test/overlays/overlay.yaml' 7 | const expectedFile = 'test/expected/output1.yaml' 8 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 9 | 10 | const result = overlayFiles(openapiFile, overlayFile) 11 | 12 | expect(result).toEqual(expectedOutput) 13 | }) 14 | 15 | test('add a description and update the summary', () => { 16 | const openapiFile = 'test/openapi/town.yaml' 17 | const overlayFile = 'test/overlays/building-description.yaml' 18 | const expectedFile = 'test/expected/town-building-description.yaml' 19 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 20 | 21 | const result = overlayFiles(openapiFile, overlayFile) 22 | 23 | expect(result).toEqual(expectedOutput) 24 | }) 25 | 26 | test('apply an overlay to the root object', () => { 27 | const openapiFile = 'test/openapi/town.yaml' 28 | const overlayFile = 'test/overlays/update-root.yaml' 29 | const expectedFile = 'test/expected/town-root-updated.yaml' 30 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 31 | 32 | const result = overlayFiles(openapiFile, overlayFile) 33 | 34 | expect(result).toEqual(expectedOutput) 35 | }) 36 | 37 | test('remove an example', () => { 38 | const openapiFile = 'test/openapi/town.yaml' 39 | const overlayFile = 'test/overlays/remove-example.yaml' 40 | const expectedFile = 'test/expected/town-remove-example.yaml' 41 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 42 | 43 | const result = overlayFiles(openapiFile, overlayFile) 44 | 45 | expect(result).toEqual(expectedOutput) 46 | }) 47 | 48 | test('remove a property', () => { 49 | const openapiFile = 'test/openapi/town.yaml' 50 | const overlayFile = 'test/overlays/remove-properties.yaml' 51 | const expectedFile = 'test/expected/town-remove-properties.yaml' 52 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 53 | 54 | const result = overlayFiles(openapiFile, overlayFile) 55 | 56 | expect(result).toEqual(expectedOutput) 57 | }) 58 | 59 | test('remove all description fields', () => { 60 | const openapiFile = 'test/openapi/town.yaml' 61 | const overlayFile = 'test/overlays/remove-descriptions.yaml' 62 | const expectedFile = 'test/expected/town-remove-descriptions.yaml' 63 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 64 | 65 | const result = overlayFiles(openapiFile, overlayFile) 66 | 67 | expect(result).toEqual(expectedOutput) 68 | }) 69 | 70 | test('remove a server array entry', () => { 71 | const openapiFile = 'test/openapi/openapi-with-servers.yaml' 72 | const overlayFile = 'test/overlays/remove-server.yaml' 73 | const expectedFile = 'test/expected/one-less-server.yaml' 74 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 75 | 76 | const result = overlayFiles(openapiFile, overlayFile) 77 | 78 | expect(result).toEqual(expectedOutput) 79 | }) 80 | 81 | test('fail to update a primitive string type', () => { 82 | const openapiFile = 'test/openapi/immutable.yaml' 83 | const overlayFile = 'test/overlays/immutable.yaml' 84 | const expectedFile = 'test/expected/immutable.yaml' 85 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 86 | 87 | const result = overlayFiles(openapiFile, overlayFile) 88 | 89 | expect(result).toEqual(expectedOutput) 90 | }) 91 | 92 | test('fail to parse invalid jsonpath expression', () => { 93 | const openapiFile = 'test/openapi/not-jsonpath.yaml' 94 | const overlayFile = 'test/overlays/not-jsonpath.yaml' 95 | const expectedFile = 'test/expected/not-jsonpath.yaml' 96 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 97 | 98 | const result = overlayFiles(openapiFile, overlayFile) 99 | 100 | expect(result).toEqual(expectedOutput) 101 | }) 102 | 103 | test('fail to parse invalid overlay document', () => { 104 | const openapiFile = 'test/openapi/not-overlay.yaml' 105 | const overlayFile = 'test/overlays/not-overlay.yaml' 106 | const expectedFile = 'test/expected/not-overlay.yaml' 107 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 108 | 109 | const result = overlayFiles(openapiFile, overlayFile) 110 | 111 | expect(result).toEqual(expectedOutput) 112 | }) 113 | 114 | test('overlay document with empty actions is a nop', () => { 115 | const openapiFile = 'test/openapi/not-overlay.yaml' 116 | const overlayFile = 'test/overlays/not-overlay.yaml' 117 | const expectedFile = 'test/expected/not-overlay.yaml' 118 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 119 | 120 | const result = overlayFiles(openapiFile, overlayFile) 121 | 122 | expect(result).toEqual(expectedOutput) 123 | }) 124 | 125 | test('remove all matching responses', () => { 126 | const openapiFile = 'test/openapi/responses.yaml' 127 | const overlayFile = 'test/overlays/remove-responses.yaml' 128 | const expectedFile = 'test/expected/remove-responses.yaml' 129 | const expectedOutput = fs.readFileSync(expectedFile, 'utf8') 130 | 131 | const result = overlayFiles(openapiFile, overlayFile) 132 | 133 | expect(result).toEqual(expectedOutput) 134 | }) 135 | -------------------------------------------------------------------------------- /test/overlays/building-description.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Add a building endpoint description 4 | version: 1.0.0 5 | actions: 6 | - target: $.paths['/buildings'].get 7 | update: 8 | description: This is the summary of getting the buildings 9 | summary: All of the available buildings 10 | 11 | -------------------------------------------------------------------------------- /test/overlays/empty.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Expected to fail as actions omitted or empty 4 | version: 1.0.0 5 | actions: [] 6 | -------------------------------------------------------------------------------- /test/overlays/immutable.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | actions: 3 | - target: info.version 4 | update: 1.1.0 5 | -------------------------------------------------------------------------------- /test/overlays/not-jsonpath.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Expected to fail on unparseable target expression 4 | version: 1.0.0 5 | actions: 6 | - target: £ 7 | add: 8 | name: foo 9 | -------------------------------------------------------------------------------- /test/overlays/not-overlay.yaml: -------------------------------------------------------------------------------- 1 | openapi: 1.0.0 2 | info: 3 | title: Expected to fail as not an overlay document 4 | version: 1.0.0 5 | paths: {} 6 | -------------------------------------------------------------------------------- /test/overlays/overlay.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Structured Overlay 4 | version: 1.0.0 5 | actions: 6 | - target: $.paths['/pets'].get.summary 7 | remove: true 8 | - target: $.paths.*.get 9 | update: 10 | tags: 11 | - wildcard-done 12 | - target: $.paths['/pets'].get 13 | update: 14 | x-info: 15 | x-overlay-applied: structured-overlay 16 | description: This is an added description 17 | tags: 18 | - overlayed 19 | - target: $.paths.* 20 | update: 21 | post: 22 | foo: 23 | bar: hello 24 | -------------------------------------------------------------------------------- /test/overlays/remove-descriptions.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Remove an example 4 | version: 1.0.0 5 | actions: 6 | - target: $..description 7 | remove: true 8 | -------------------------------------------------------------------------------- /test/overlays/remove-example.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Remove an example 4 | version: 1.0.0 5 | actions: 6 | - target: $.components.schemas.Building.properties['building'].example 7 | remove: true 8 | -------------------------------------------------------------------------------- /test/overlays/remove-properties.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Remove an example 4 | version: 1.0.0 5 | actions: 6 | - target: $.paths['/locations'].get.responses['200']..properties[?(@.type == 'string')] 7 | remove: true 8 | 9 | -------------------------------------------------------------------------------- /test/overlays/remove-responses.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Response code removal test 4 | version: 1.0.0 5 | 6 | extends: response-codes.yaml 7 | 8 | actions: 9 | - target: $.paths..responses['500'] 10 | remove: true 11 | 12 | - target: $.paths..responses['default'] 13 | remove: true 14 | -------------------------------------------------------------------------------- /test/overlays/remove-server.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Remove dev server 4 | version: 1.0.0 5 | extends: openapi-with-servers.yaml 6 | 7 | actions: 8 | - target: $.servers[?( @.description == 'Dev' )] 9 | remove: true 10 | -------------------------------------------------------------------------------- /test/overlays/update-root.yaml: -------------------------------------------------------------------------------- 1 | overlay: 1.0.0 2 | info: 3 | title: Structured Overlay 4 | version: 1.0.0 5 | actions: 6 | - target: "$" # Root of document 7 | update: 8 | info: 9 | x-overlaid: true 10 | --------------------------------------------------------------------------------