├── .editorconfig ├── .envrc ├── .eslintrc ├── .eslintrc.json ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ ├── build.yml │ └── release.yml ├── .gitignore ├── .husky └── commit-msg ├── .nvmrc ├── .prettierignore ├── .prettierrc ├── .releaserc ├── LICENSE ├── README.md ├── apps └── generator-cli │ ├── .eslintrc │ ├── jest.config.ts │ ├── project.json │ ├── src │ ├── README.md │ ├── app │ │ ├── .gitkeep │ │ ├── app.module.spec.ts │ │ ├── app.module.ts │ │ ├── constants │ │ │ └── index.ts │ │ ├── controllers │ │ │ ├── version-manager.controller.spec.ts │ │ │ └── version-manager.controller.ts │ │ ├── mocks │ │ │ └── command.mock.ts │ │ └── services │ │ │ ├── config.service.spec.ts │ │ │ ├── config.service.ts │ │ │ ├── generator.service.spec.ts │ │ │ ├── generator.service.ts │ │ │ ├── index.ts │ │ │ ├── pass-through.service.spec.ts │ │ │ ├── pass-through.service.ts │ │ │ ├── ui.service.ts │ │ │ ├── version-manager.service.spec.ts │ │ │ └── version-manager.service.ts │ ├── config.schema.json │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ └── main.ts │ ├── tsconfig.app.json │ ├── tsconfig.json │ ├── tsconfig.spec.json │ └── webpack.config.js ├── commitlint.config.js ├── examples ├── openapitools.json ├── package.json ├── v2.0 │ ├── json │ │ ├── api-with-examples.json │ │ ├── petstore-expanded.json │ │ ├── petstore-minimal.json │ │ ├── petstore-separate │ │ │ ├── common │ │ │ │ └── Error.json │ │ │ └── spec │ │ │ │ ├── NewPet.json │ │ │ │ ├── Pet.json │ │ │ │ ├── parameters.json │ │ │ │ └── swagger.json │ │ ├── petstore-simple.json │ │ ├── petstore-with-external-docs.json │ │ ├── petstore.json │ │ └── uber.json │ └── yaml │ │ ├── api-with-examples.yaml │ │ ├── petstore-expanded.yaml │ │ ├── petstore-minimal.yaml │ │ ├── petstore-separate │ │ ├── common │ │ │ └── Error.yaml │ │ └── spec │ │ │ ├── NewPet.yaml │ │ │ ├── Pet.yaml │ │ │ ├── parameters.yaml │ │ │ └── swagger.yaml │ │ ├── petstore-simple.yaml │ │ ├── petstore-with-external-docs.yaml │ │ ├── petstore.yaml │ │ └── uber.yaml └── v3.0 │ ├── api-with-examples.json │ ├── api-with-examples.yaml │ ├── callback-example.json │ ├── callback-example.yaml │ ├── link-example.json │ ├── link-example.yaml │ ├── petstore-expanded.json │ ├── petstore-expanded.yaml │ ├── petstore.json │ ├── petstore.yaml │ ├── uspto.json │ └── uspto.yaml ├── flake.lock ├── flake.nix ├── img └── vm.gif ├── jest.config.ts ├── jest.preset.js ├── lib └── index.js ├── libs └── .gitkeep ├── nx.json ├── package.json ├── renovate.json ├── tools ├── schematics │ └── .gitkeep └── tsconfig.tools.json ├── tsconfig.base.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | has nix && use flake 2 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 2018, 6 | "sourceType": "module", 7 | "project": "./tsconfig.*?.json" 8 | }, 9 | "ignorePatterns": ["**/*"], 10 | "plugins": ["@typescript-eslint", "@nx"], 11 | "extends": [ 12 | "eslint:recommended", 13 | "plugin:@typescript-eslint/eslint-recommended", 14 | "plugin:@typescript-eslint/recommended", 15 | "prettier" 16 | ], 17 | "rules": { 18 | "@typescript-eslint/explicit-member-accessibility": "off", 19 | "@typescript-eslint/explicit-function-return-type": "off", 20 | "@typescript-eslint/no-parameter-properties": "off", 21 | "@typescript-eslint/explicit-module-boundary-types": "off", 22 | "@nx/enforce-module-boundaries": [ 23 | "error", 24 | { 25 | "enforceBuildableLibDependency": true, 26 | "allow": [], 27 | "depConstraints": [ 28 | { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] } 29 | ] 30 | } 31 | ], 32 | "quote-props": ["error", "as-needed"] 33 | }, 34 | "overrides": [ 35 | { 36 | "files": ["*.tsx"], 37 | "rules": { 38 | "@typescript-eslint/no-unused-vars": "off" 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es2020": true 6 | }, 7 | "extends": "eslint:recommended", 8 | "parserOptions": { 9 | "ecmaVersion": 11 10 | }, 11 | "rules": { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: openapi_generator 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: kay-schecker 7 | 8 | --- 9 | 10 | # ⚠️ Important Notice 11 | 12 | ### Please differentiate the bug 13 | 14 | This repository is not responsible for the actual code generation. If you have problems with the code generation, please open the bug at [OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator). 15 | 16 | Please also check if the bug is already known before you open a new bug. 17 | 18 | ---------------------------------------------------------------------------- 19 | 20 | # 🐛 Bug Report: 21 | 22 | ### Describe the bug 23 | A clear and concise description of what the bug is. 24 | 25 | ### Steps to Reproduce 26 | Steps to reproduce the behavior: 27 | 1. Go to '...' 28 | 2. Click on '....' 29 | 3. Scroll down to '....' 30 | 4. See error 31 | 32 | ### Expected behavior 33 | A clear and concise description of what you expected to happen. 34 | 35 | ### Screenshots 36 | If applicable, add screenshots to help explain your problem. 37 | 38 | ### Operation System (please complete the following information): 39 | - OS: [e.g. Ubuntu ] 40 | - Version [e.g. 22] 41 | 42 | ### Package System (please complete the following information): 43 | - Version [e.g. 22] 44 | 45 | ### Additional context 46 | Add any other context about the problem here. 47 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | tags-ignore: 5 | - '*.*' 6 | branches-ignore: 7 | - master 8 | - renovate/** 9 | pull_request: 10 | types: [ assigned, opened, synchronize, reopened ] 11 | jobs: 12 | build: 13 | name: Build 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | node-version: [ 20.x ] 18 | 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | 23 | - name: Use Node.js ${{matrix.node-version }} 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: ${{matrix.node-version }} 27 | 28 | - name: Install 29 | run: yarn --frozen-lockfile 30 | 31 | - name: Lint 32 | run: yarn run lint 33 | 34 | - name: Unit Test 35 | run: yarn run test 36 | 37 | - name: Build 38 | run: yarn run build 39 | 40 | - name: Build Package 41 | run: | 42 | cd dist/apps/generator-cli 43 | yarn pack -f ../package.tgz 44 | 45 | - uses: actions/upload-artifact@v4 46 | with: 47 | name: package.tgz 48 | path: dist/apps/package.tgz 49 | 50 | e2e: 51 | name: "E2E local: (${{ matrix.os }})" 52 | needs: build 53 | runs-on: ${{ matrix.os }} 54 | strategy: 55 | matrix: 56 | os: [ubuntu-latest, macos-latest] 57 | node-version: [ 20.x ] 58 | 59 | steps: 60 | - name: Checkout 61 | uses: actions/checkout@v4 62 | 63 | - name: Use Node.js ${{matrix.node-version }} 64 | uses: actions/setup-node@v4 65 | with: 66 | node-version: ${{matrix.node-version }} 67 | 68 | - uses: actions/download-artifact@v4 69 | with: 70 | name: package.tgz 71 | 72 | - name: Test 73 | run: | 74 | cd ./examples 75 | yarn global add json && export PATH="$(yarn global bin):$PATH" 76 | yarn cache clean && yarn add $GITHUB_WORKSPACE/package.tgz 77 | npm run oa version 78 | npm run oa completion 79 | npm run oa help 80 | npm run oa help generate 81 | npm run oa version-manager help 82 | npm run oa generate -- -g ruby -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o $GITHUB_WORKSPACE/tmp/ruby-client 83 | (npm run oa version-manager set 3.0.0 && npm run oa version | grep -q '3.0.0') || exit 1 84 | (npm run oa version-manager set 4.0 && npm run oa version | grep -q '4.0.3') || exit 1 85 | (npm run oa version-manager set 4.3.1 && npm run oa version | grep -q '4.3.1') || exit 1 86 | (npm run oa version-manager set 4.3.1 && npm run oa version | grep -q '4.3.1') || exit 1 87 | (export OPENAPI_GENERATOR_CLI_SEARCH_URL=DEFAULT && npm run oa version-manager set 7.2.0 && npm run oa version | grep -q '7.2.0') || exit 1 88 | json -I -f openapitools.json -e 'this["generator-cli"]["storageDir"]="./my/storage/"' 89 | (npm run oa version-manager set 4.3.0 && npm run oa version | grep -q '4.3.0') || exit 1 90 | test -f ./my/storage/4.3.0.jar || exit 1 91 | json -I -f openapitools.json -e 'this["generator-cli"]["storageDir"]="~/my/storage/"' 92 | (npm run oa version-manager set 4.3.1 && npm run oa version | grep -q '4.3.1') || exit 1 93 | test -f ~/my/storage/4.3.1.jar || exit 1 94 | npm run oa:generate && mkdir ./foo && cd ./foo && npm run oa:generate 95 | 96 | # release: 97 | # if: github.event.pull_request.merged == 'true' 98 | # name: Release (Dry) 99 | # # needs: e2e # DONT FORGET TO ENABLE ME !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 100 | # runs-on: ubuntu-18.04 101 | # steps: 102 | # 103 | # - name: Checkout 104 | # uses: actions/checkout@v2 105 | # with: 106 | # fetch-depth: 0 107 | # 108 | # - name: Use Node.js ${{matrix.node-version }} 109 | # uses: actions/setup-node@v1 110 | # with: 111 | # node-version: ${{matrix.node-version }} 112 | # 113 | # - name: Install 114 | # run: yarn --frozen-lockfile 115 | # 116 | # - name: Release 117 | # env: 118 | # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 119 | # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 120 | # run: npx semantic-release -d 121 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | tags-ignore: 5 | - '*.*' 6 | branches: 7 | - master 8 | 9 | jobs: 10 | release: 11 | name: Release 12 | environment: PROD 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v4 18 | 19 | - name: Use Node.js ${{matrix.node-version }} 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: ${{matrix.node-version }} 23 | 24 | - name: Install 25 | run: yarn --frozen-lockfile 26 | 27 | - name: Unit Test 28 | run: yarn run test 29 | 30 | - name: Build 31 | run: yarn run build 32 | 33 | - name: Release 34 | env: 35 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 36 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 37 | run: npx semantic-release 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | /output 8 | 9 | # dependencies 10 | /node_modules 11 | 12 | # IDEs and editors 13 | /.idea 14 | .project 15 | .classpath 16 | .c9/ 17 | *.launch 18 | .settings/ 19 | *.sublime-workspace 20 | 21 | # IDE - VSCode 22 | .vscode/* 23 | !.vscode/settings.json 24 | !.vscode/tasks.json 25 | !.vscode/launch.json 26 | !.vscode/extensions.json 27 | 28 | # misc 29 | /.sass-cache 30 | /connect.lock 31 | /coverage 32 | /libpeerconnection.log 33 | npm-debug.log 34 | yarn-error.log 35 | testem.log 36 | /typings 37 | 38 | # System Files 39 | .DS_Store 40 | Thumbs.db 41 | 42 | /openapitools.json 43 | 44 | .nx/cache 45 | .nx/workspace-data 46 | 47 | # Direnv 48 | .direnv -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | yarn commitlint --edit $1 2 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | lts/* 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Add files here to ignore them from prettier formatting 2 | 3 | /dist 4 | /coverage 5 | 6 | /.nx/cache 7 | /.nx/workspace-data -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /.releaserc: -------------------------------------------------------------------------------- 1 | { 2 | "branches": ["master"], 3 | "plugins": [ 4 | "@semantic-release/commit-analyzer", 5 | "@semantic-release/release-notes-generator", 6 | ["@semantic-release/npm", { 7 | "npmPublish": true, 8 | "pkgRoot": "dist/apps/generator-cli", 9 | "tarballDir": "dist/apps" 10 | }], 11 | ["@semantic-release/github", { 12 | "assets": "dist/apps/*.tgz" 13 | }] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | apps/generator-cli/src/README.md -------------------------------------------------------------------------------- /apps/generator-cli/.eslintrc: -------------------------------------------------------------------------------- 1 | { "extends": "../../.eslintrc", "rules": {}, "ignorePatterns": ["!**/*"] } 2 | -------------------------------------------------------------------------------- /apps/generator-cli/jest.config.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | export default { 3 | displayName: 'generator-cli', 4 | preset: '../../jest.preset.js', 5 | testEnvironment: 'node', 6 | transform: { 7 | '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], 8 | }, 9 | moduleFileExtensions: ['ts', 'js', 'html'], 10 | coverageDirectory: '../../coverage/apps/generator-cli', 11 | // snapshotFormat: { escapeString: true, printBasicPrototype: true }, 12 | }; 13 | -------------------------------------------------------------------------------- /apps/generator-cli/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-cli", 3 | "$schema": "../../node_modules/nx/schemas/project-schema.json", 4 | "sourceRoot": "apps/generator-cli/src", 5 | "projectType": "application", 6 | "prefix": "generator-cli", 7 | "generators": {}, 8 | "targets": { 9 | "build": { 10 | "executor": "@nx/webpack:webpack", 11 | "outputs": ["{options.outputPath}"], 12 | "defaultConfiguration": "production", 13 | "options": { 14 | "target": "node", 15 | "compiler": "tsc", 16 | "outputPath": "dist/apps/generator-cli", 17 | "main": "apps/generator-cli/src/main.ts", 18 | "tsConfig": "apps/generator-cli/tsconfig.app.json", 19 | "assets": [ 20 | "apps/generator-cli/src/config.schema.json", 21 | "apps/generator-cli/src/README.md" 22 | ], 23 | "webpackConfig": "apps/generator-cli/webpack.config.js" 24 | }, 25 | "configurations": { 26 | "production": { 27 | "optimization": true, 28 | "extractLicenses": true, 29 | "inspect": false, 30 | "fileReplacements": [ 31 | { 32 | "replace": "apps/generator-cli/src/environments/environment.ts", 33 | "with": "apps/generator-cli/src/environments/environment.prod.ts" 34 | } 35 | ] 36 | } 37 | } 38 | }, 39 | "serve": { 40 | "executor": "@nx/js:node", 41 | "defaultConfiguration": "production", 42 | "options": { 43 | "buildTarget": "generator-cli:build" 44 | }, 45 | "configurations": { 46 | "production": { 47 | "buildTarget": "generator-cli:build:production" 48 | } 49 | } 50 | }, 51 | "lint": { 52 | "executor": "@nx/eslint:lint", 53 | "outputs": ["{options.outputFile}"] 54 | }, 55 | "test": { 56 | "executor": "@nx/jest:jest", 57 | "options": { 58 | "jestConfig": "apps/generator-cli/jest.config.ts" 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/623732ce18518724abe575c5cdd33cdc8ff072d5/apps/generator-cli/src/app/.gitkeep -------------------------------------------------------------------------------- /apps/generator-cli/src/app/app.module.spec.ts: -------------------------------------------------------------------------------- 1 | import {AppModule} from './app.module'; 2 | import {Test} from '@nestjs/testing'; 3 | import {PassThroughService, VersionManagerService} from './services'; 4 | import {of} from 'rxjs'; 5 | import {COMMANDER_PROGRAM} from './constants'; 6 | 7 | describe('AppModule', () => { 8 | 9 | let fixture: AppModule 10 | 11 | const programMock = { 12 | parse: jest.fn(), 13 | } 14 | 15 | const passThroughServiceMock = { 16 | init: jest.fn(), 17 | } 18 | 19 | const versionManagerServiceMock = { 20 | getSelectedVersion: jest.fn(), 21 | setSelectedVersion: jest.fn(), 22 | downloadIfNeeded: jest.fn(), 23 | search: jest.fn(), 24 | } 25 | 26 | beforeEach(async () => { 27 | 28 | [ 29 | ...Object.values(versionManagerServiceMock), 30 | ...Object.values(passThroughServiceMock), 31 | ...Object.values(programMock), 32 | ].forEach(spy => spy.mockReset()) 33 | 34 | const moduleRef = await Test.createTestingModule({ 35 | providers: [ 36 | {provide: COMMANDER_PROGRAM, useValue: programMock}, 37 | {provide: VersionManagerService, useValue: versionManagerServiceMock}, 38 | {provide: PassThroughService, useValue: passThroughServiceMock}, 39 | ] 40 | }).compile(); 41 | 42 | fixture = new AppModule( 43 | moduleRef.get(COMMANDER_PROGRAM), 44 | moduleRef.get(VersionManagerService), 45 | moduleRef.get(PassThroughService), 46 | ) 47 | }) 48 | 49 | describe('lifecycles', () => { 50 | 51 | describe('onApplicationBootstrap()', () => { 52 | 53 | beforeEach(() => { 54 | 55 | process.argv = ['foo', 'baz'] 56 | 57 | programMock.parse.mockImplementation(() => { 58 | expect(passThroughServiceMock.init).toBeCalledTimes(1) 59 | expect(versionManagerServiceMock.downloadIfNeeded).toBeCalledTimes(1) 60 | }) 61 | }) 62 | 63 | describe('the selected version is not set', () => { 64 | 65 | beforeEach(async () => { 66 | versionManagerServiceMock.getSelectedVersion.mockReturnValue(undefined) 67 | versionManagerServiceMock.search.mockReturnValue(of([{version: '4.5.6'}])) 68 | await fixture.onApplicationBootstrap() 69 | }) 70 | 71 | it('searches and selects the latest version ', () => { 72 | expect(versionManagerServiceMock.search).toHaveBeenNthCalledWith(1, ['latest']) 73 | expect(versionManagerServiceMock.setSelectedVersion).toHaveBeenNthCalledWith(1, '4.5.6') 74 | }) 75 | 76 | it('downloads the version, if needed', () => { 77 | expect(versionManagerServiceMock.downloadIfNeeded).toHaveBeenNthCalledWith(1, '4.5.6') 78 | }) 79 | 80 | it('parses the command', () => { 81 | expect(programMock.parse).toHaveBeenNthCalledWith(1, process.argv) 82 | }) 83 | 84 | }) 85 | 86 | describe('the selected version is set', () => { 87 | 88 | beforeEach(async () => { 89 | versionManagerServiceMock.getSelectedVersion.mockReturnValue('1.2.3') 90 | await fixture.onApplicationBootstrap() 91 | }) 92 | 93 | it('does not search for the latest version ', () => { 94 | expect(versionManagerServiceMock.search).toBeCalledTimes(0) 95 | }) 96 | 97 | it('does not set the selected version ', () => { 98 | expect(versionManagerServiceMock.setSelectedVersion).toBeCalledTimes(0) 99 | }) 100 | 101 | it('downloads the version, if needed', () => { 102 | expect(versionManagerServiceMock.downloadIfNeeded).toHaveBeenNthCalledWith(1, '1.2.3') 103 | }) 104 | 105 | it('parses the command', () => { 106 | expect(programMock.parse).toHaveBeenNthCalledWith(1, process.argv) 107 | }) 108 | 109 | }) 110 | 111 | }) 112 | 113 | }) 114 | 115 | }) 116 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Module, OnApplicationBootstrap } from '@nestjs/common'; 2 | import { HttpModule, HttpModuleOptions } from '@nestjs/axios'; 3 | import { Command } from 'commander'; 4 | import { ProxyAgent } from 'proxy-agent'; 5 | 6 | import { COMMANDER_PROGRAM, LOGGER } from './constants'; 7 | import { VersionManagerController } from './controllers/version-manager.controller'; 8 | import { 9 | ConfigService, 10 | GeneratorService, 11 | PassThroughService, 12 | UIService, 13 | VersionManagerService, 14 | } from './services'; 15 | 16 | const hasHttpProxyEnvs = process.env.HTTP_PROXY || process.env.http_proxy; 17 | const hasHttpsProxyEnvs = process.env.HTTPS_PROXY || process.env.https_proxy; 18 | const httpModuleConfig: HttpModuleOptions = {}; 19 | 20 | const proxyAgent = new ProxyAgent(); 21 | 22 | if (hasHttpProxyEnvs) { 23 | httpModuleConfig.proxy = false; 24 | httpModuleConfig.httpAgent = proxyAgent; 25 | } 26 | 27 | if (hasHttpsProxyEnvs) { 28 | httpModuleConfig.proxy = false; 29 | httpModuleConfig.httpsAgent = proxyAgent; 30 | } 31 | 32 | @Module({ 33 | imports: [ 34 | HttpModule.register({ 35 | ...httpModuleConfig, 36 | }), 37 | ], 38 | controllers: [VersionManagerController], 39 | providers: [ 40 | UIService, 41 | ConfigService, 42 | GeneratorService, 43 | PassThroughService, 44 | VersionManagerService, 45 | { 46 | provide: COMMANDER_PROGRAM, 47 | useValue: new Command('openapi-generator-cli') 48 | .helpOption(false) 49 | .usage(' []') 50 | .option( 51 | '--openapitools ', 52 | 'Use the specified openapi-generator-cli configuration file', 53 | ), 54 | }, 55 | { provide: LOGGER, useValue: console }, 56 | ], 57 | }) 58 | export class AppModule implements OnApplicationBootstrap { 59 | constructor( 60 | @Inject(COMMANDER_PROGRAM) private readonly program: Command, 61 | private readonly versionManager: VersionManagerService, 62 | private readonly passThroughService: PassThroughService, 63 | ) {} 64 | 65 | onApplicationBootstrap = async () => { 66 | let selectedVersion = this.versionManager.getSelectedVersion(); 67 | 68 | if (!selectedVersion) { 69 | const [{ version }] = await this.versionManager 70 | .search(['latest']) 71 | .toPromise(); 72 | await this.versionManager.setSelectedVersion(version); 73 | selectedVersion = version; 74 | } 75 | 76 | await this.versionManager.downloadIfNeeded(selectedVersion); 77 | await this.passThroughService.init(); 78 | this.program.parse(process.argv); 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/constants/index.ts: -------------------------------------------------------------------------------- 1 | export type LOGGER = typeof console 2 | export const LOGGER = Symbol('LOGGER') 3 | 4 | export const COMMANDER_PROGRAM = Symbol('COMMANDER_PROGRAM') 5 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/controllers/version-manager.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Inject } from '@nestjs/common'; 2 | import { COMMANDER_PROGRAM, LOGGER } from '../constants'; 3 | import { Command } from 'commander'; 4 | import chalk from 'chalk'; 5 | 6 | import { UIService, Version, VersionManagerService } from '../services'; 7 | 8 | @Controller() 9 | export class VersionManagerController { 10 | private readonly mainCommand = this.program 11 | .command('version-manager') 12 | .description('Manage used / installed generator version'); 13 | 14 | private readonly listCommand = this.mainCommand 15 | .command('list [versionTags...]') 16 | .description('lists all published versions') 17 | .option('-j, --json', 'print as json', false) 18 | .action((tags) => this.list(tags)); 19 | 20 | private readonly setCommand = this.mainCommand 21 | .command('set ') 22 | .description('set version to use') 23 | .action((tags) => this.set(tags)); 24 | 25 | constructor( 26 | @Inject(LOGGER) private readonly logger: LOGGER, 27 | @Inject(COMMANDER_PROGRAM) private readonly program: Command, 28 | private readonly ui: UIService, 29 | private readonly service: VersionManagerService 30 | ) {} 31 | 32 | private list = async (versionTags: string[]) => { 33 | const versions = await this.service.search(versionTags).toPromise(); 34 | 35 | if (this.listCommand.opts().json) { 36 | this.logger.log(JSON.stringify(versions, null, 2)); 37 | return; 38 | } 39 | 40 | if (versions.length < 1) { 41 | this.logger.log(chalk.red('No results for: ' + versionTags.join(' '))); 42 | return; 43 | } 44 | 45 | const { version, installed } = await this.table(versions); 46 | const isSelected = await this.service.isSelectedVersion(version); 47 | const choice = (name: string, cb = () => null, color = (v) => v) => ({ 48 | name: color(name), 49 | value: cb, 50 | }); 51 | 52 | const choices = [choice('exit')]; 53 | 54 | if (!installed) { 55 | choices.unshift( 56 | choice('download', () => this.service.download(version), chalk.yellow) 57 | ); 58 | } else if (!isSelected) { 59 | choices.unshift( 60 | choice('remove', () => this.service.remove(version), chalk.red) 61 | ); 62 | } 63 | 64 | if (!isSelected) { 65 | choices.unshift( 66 | choice( 67 | 'use', 68 | () => this.service.setSelectedVersion(version), 69 | chalk.green 70 | ) 71 | ); 72 | } 73 | 74 | await ( 75 | await this.ui.list({ name: 'next', message: 'Whats next?', choices }) 76 | )(); 77 | }; 78 | 79 | private set = async (versionTags: string[]) => { 80 | const versions = await this.service.search(versionTags).toPromise(); 81 | 82 | if (versions.length > 0) { 83 | await this.service.setSelectedVersion(versions[0].version); 84 | return; 85 | } 86 | 87 | this.logger.log( 88 | chalk.red( 89 | `Unable to find version matching criteria "${versionTags.join(' ')}"` 90 | ) 91 | ); 92 | }; 93 | 94 | private table = (versions: Version[]) => 95 | this.ui.table({ 96 | printColNum: false, 97 | message: 'The following releases are available:', 98 | name: 'version', 99 | rows: versions.map((version) => { 100 | const stable = version.versionTags.includes('stable'); 101 | const selected = this.service.isSelectedVersion(version.version); 102 | const versionTags = version.versionTags.map((t) => 103 | t === 'latest' ? chalk.green(t) : t 104 | ); 105 | 106 | return { 107 | value: version, 108 | short: version.version, 109 | row: { 110 | '☐': selected ? '☒' : '☐', 111 | releasedAt: version.releaseDate.toISOString().split('T')[0], 112 | version: stable 113 | ? chalk.yellow(version.version) 114 | : chalk.gray(version.version), 115 | installed: version.installed ? chalk.green('yes') : chalk.red('no'), 116 | versionTags: versionTags.join(' '), 117 | }, 118 | }; 119 | }), 120 | }); 121 | } 122 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/mocks/command.mock.ts: -------------------------------------------------------------------------------- 1 | import { get, set } from 'lodash'; 2 | 3 | export class CommandMock { 4 | 5 | commands: { 6 | [key: string]: { 7 | self: CommandMock, 8 | description: string 9 | allowUnknownOption: boolean 10 | action: (cmd) => unknown 11 | options: Array<{ 12 | flags: string 13 | description: string 14 | defaultValue: string 15 | }> 16 | } 17 | } = {}; 18 | 19 | refs: { 20 | [key: string]: CommandMock 21 | } = {}; 22 | 23 | private currentCommand: string; 24 | 25 | helpInformation = jest.fn().mockReturnValue('some help text'); 26 | 27 | action = jest.fn().mockImplementation(action => { 28 | set(this.commands, [this.currentCommand, 'action'], action); 29 | return this; 30 | }); 31 | 32 | option = jest.fn().mockImplementation((flags, description, defaultValue) => { 33 | const options = get(this.commands, [this.currentCommand, 'options'], []); 34 | 35 | set(this.commands, [this.currentCommand, 'options'], [ 36 | ...options, 37 | { 38 | flags, 39 | description, 40 | defaultValue 41 | } 42 | ]); 43 | return this; 44 | }); 45 | 46 | command = jest.fn().mockImplementation(cmd => { 47 | this.currentCommand = cmd; 48 | this.refs[cmd] = this; 49 | return this; 50 | }); 51 | 52 | allowUnknownOption = jest.fn().mockImplementation(() => { 53 | set(this.commands, [this.currentCommand, 'allowUnknownOption'], true); 54 | return this; 55 | }); 56 | 57 | description = jest.fn().mockImplementation(desc => { 58 | set(this.commands, [this.currentCommand, 'description'], desc); 59 | return this; 60 | }); 61 | 62 | opts = jest.fn(); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/config.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test } from '@nestjs/testing'; 2 | import { Command, createCommand } from 'commander'; 3 | import { ConfigService } from './config.service'; 4 | import { LOGGER, COMMANDER_PROGRAM } from '../constants'; 5 | 6 | jest.mock('fs-extra'); 7 | // eslint-disable-next-line @typescript-eslint/no-var-requires 8 | const fs = jest.mocked(require('fs-extra')); 9 | 10 | describe('ConfigService', () => { 11 | let fixture: ConfigService; 12 | let program: Command; 13 | 14 | const log = jest.fn(); 15 | 16 | beforeEach(async () => { 17 | program = createCommand(); 18 | jest.spyOn(program, 'helpInformation'); 19 | 20 | const moduleRef = await Test.createTestingModule({ 21 | providers: [ 22 | ConfigService, 23 | { provide: LOGGER, useValue: { log } }, 24 | { provide: COMMANDER_PROGRAM, useValue: program }, 25 | ], 26 | }).compile(); 27 | 28 | fixture = moduleRef.get(ConfigService); 29 | fs.writeJSONSync.mockReset(); 30 | fs.readJSONSync.mockReset(); 31 | fs.ensureFileSync.mockReset(); 32 | }); 33 | 34 | describe('API', () => { 35 | describe('get()', () => { 36 | describe.each([ 37 | ['the config is undefined', undefined], 38 | ['the config empty', {}], 39 | ])('%s', (_, config) => { 40 | beforeEach(() => { 41 | fs.readJSONSync.mockReturnValue(config); 42 | }); 43 | 44 | it.each([ 45 | [ 46 | '$schema', 47 | './node_modules/@openapitools/openapi-generator-cli/config.schema.json', 48 | ], 49 | ['spaces', 2], 50 | ['generator-cli', { version: undefined }], 51 | ])('the key "%s" returns %s as default', (key, expectedValue) => { 52 | expect(fixture.get(key)).toEqual(expectedValue); 53 | }); 54 | 55 | it('can return a default value', () => { 56 | expect(fixture.get('unknown', 'foo')).toEqual('foo'); 57 | }); 58 | }); 59 | 60 | describe('the config has values', () => { 61 | beforeEach(() => { 62 | fs.readJSONSync.mockReturnValue({ 63 | $schema: 'foo.json', 64 | spaces: 4, 65 | 'generator-cli': { 66 | version: '1.2.3', 67 | }, 68 | }); 69 | }); 70 | 71 | it('ensures the config file', () => { 72 | fixture.get('some-path'); 73 | expect(fs.ensureFileSync).toHaveBeenNthCalledWith( 74 | 1, 75 | fixture.configFile 76 | ); 77 | }); 78 | 79 | it.each([ 80 | ['$schema', 'foo.json'], 81 | ['spaces', 4], 82 | ['generator-cli', { version: '1.2.3' }], 83 | ['generator-cli.version', '1.2.3'], 84 | ])('"%s" returns %s as default', (key, expectedValue) => { 85 | expect(fixture.get(key)).toEqual(expectedValue); 86 | expect(fs.readJSONSync).toHaveBeenNthCalledWith( 87 | 1, 88 | fixture.configFile, 89 | { throws: false, encoding: 'utf8' } 90 | ); 91 | }); 92 | }); 93 | }); 94 | 95 | describe('has()', () => { 96 | beforeEach(() => { 97 | fs.readJSONSync.mockReturnValue({ 98 | propFalsy: false, 99 | propUndefined: undefined, 100 | propNull: null, 101 | }); 102 | }); 103 | 104 | it('returns true, if the prop is set', () => { 105 | expect(fixture.has('propFalsy')).toBeTruthy(); 106 | expect(fixture.has('propUndefined')).toBeTruthy(); 107 | expect(fixture.has('propNull')).toBeTruthy(); 108 | }); 109 | 110 | it('returns false, if the value is set', () => { 111 | expect(fixture.has('foo')).toBeFalsy(); 112 | }); 113 | }); 114 | 115 | describe('set()', () => { 116 | beforeEach(() => { 117 | fs.readJSONSync.mockReturnValue({ 118 | $schema: 'foo.json', 119 | spaces: 4, 120 | 'generator-cli': { 121 | version: '1.2.3', 122 | }, 123 | }); 124 | 125 | fixture.set('generator-cli.version', '4.5.6'); 126 | }); 127 | 128 | it('ensures the config file', () => { 129 | expect(fs.ensureFileSync).toHaveBeenNthCalledWith( 130 | 1, 131 | fixture.configFile 132 | ); 133 | }); 134 | 135 | it('saves the correct value', () => { 136 | expect(fs.writeJSONSync).toHaveBeenNthCalledWith( 137 | 1, 138 | fixture.configFile, 139 | { 140 | $schema: 'foo.json', 141 | spaces: 4, 142 | 'generator-cli': { 143 | version: '4.5.6', 144 | }, 145 | }, 146 | { 147 | encoding: 'utf8', 148 | spaces: 4, 149 | } 150 | ); 151 | }); 152 | }); 153 | 154 | describe('configFileOrDefault()', () => { 155 | describe('--openapitools set', () => { 156 | beforeEach(async () => { 157 | program = createCommand(); 158 | program.opts().openapitools = '/tmp/myopenapitools.json'; 159 | 160 | const moduleRef = await Test.createTestingModule({ 161 | providers: [ 162 | ConfigService, 163 | { provide: LOGGER, useValue: { log } }, 164 | { provide: COMMANDER_PROGRAM, useValue: program }, 165 | ], 166 | }).compile(); 167 | 168 | fixture = moduleRef.get(ConfigService); 169 | fs.writeJSONSync.mockReset(); 170 | fs.readJSONSync.mockReset(); 171 | fs.ensureFileSync.mockReset(); 172 | }); 173 | it('returns path set at cli, if openapitools argument provided', () => { 174 | expect(fixture.configFile).toEqual('/tmp/myopenapitools.json'); 175 | }); 176 | }); 177 | describe('--openapitools not set', () => { 178 | it('returns default path, if openapitools argument not provided', () => { 179 | expect( 180 | fixture.configFile.endsWith( 181 | 'openapi-generator-cli/openapitools.json' 182 | ) 183 | ).toBeTruthy(); 184 | }); 185 | }); 186 | }); 187 | }); 188 | }); 189 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/config.service.ts: -------------------------------------------------------------------------------- 1 | import {Inject, Injectable} from '@nestjs/common'; 2 | import * as path from 'path'; 3 | import {COMMANDER_PROGRAM, LOGGER} from '../constants'; 4 | import {set, get, has, merge} from 'lodash'; 5 | import * as fs from 'fs-extra'; 6 | import { Command } from 'commander'; 7 | 8 | @Injectable() 9 | export class ConfigService { 10 | 11 | public readonly cwd = process.env.PWD || process.env.INIT_CWD || process.cwd() 12 | public readonly configFile = this.configFileOrDefault(); 13 | 14 | private configFileOrDefault() { 15 | this.program.parseOptions(process.argv); 16 | const conf = this.program.opts().openapitools; 17 | 18 | if(!conf) { 19 | return path.resolve(this.cwd, 'openapitools.json'); 20 | } 21 | 22 | return path.isAbsolute(conf) ? conf : path.resolve(this.cwd, conf); 23 | } 24 | 25 | public get useDocker() { 26 | return this.get('generator-cli.useDocker', false); 27 | } 28 | 29 | public get dockerImageName() { 30 | return this.get('generator-cli.dockerImageName', 'openapitools/openapi-generator-cli'); 31 | } 32 | 33 | private readonly defaultConfig = { 34 | $schema: './node_modules/@openapitools/openapi-generator-cli/config.schema.json', 35 | spaces: 2, 36 | 'generator-cli': { 37 | version: undefined, 38 | }, 39 | } 40 | 41 | constructor( 42 | @Inject(LOGGER) private readonly logger: LOGGER, 43 | @Inject(COMMANDER_PROGRAM) private readonly program: Command, 44 | ) { 45 | } 46 | 47 | get(path: string, defaultValue?: T): T { 48 | return get(this.read(), path, defaultValue) 49 | } 50 | 51 | has(path) { 52 | return has(this.read(), path) 53 | } 54 | 55 | set(path: string, value: unknown) { 56 | this.write(set(this.read(), path, value)) 57 | return this 58 | } 59 | 60 | private read() { 61 | fs.ensureFileSync(this.configFile) 62 | 63 | return merge( 64 | this.defaultConfig, 65 | fs.readJSONSync(this.configFile, {throws: false, encoding: 'utf8'}), 66 | ) 67 | } 68 | 69 | private write(config) { 70 | fs.writeJSONSync(this.configFile, config, {encoding: 'utf8', spaces: config.spaces || 2}) 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/generator.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test } from '@nestjs/testing'; 2 | import { GeneratorService } from './generator.service'; 3 | import { LOGGER } from '../constants'; 4 | import { VersionManagerService } from './version-manager.service'; 5 | import { ConfigService } from './config.service'; 6 | 7 | jest.mock('fs-extra'); 8 | jest.mock('glob'); 9 | jest.mock('concurrently'); 10 | // eslint-disable-next-line @typescript-eslint/no-var-requires 11 | const fs = jest.mocked(require('fs-extra')); 12 | // eslint-disable-next-line @typescript-eslint/no-var-requires 13 | const glob = jest.mocked(require('glob')); 14 | // eslint-disable-next-line @typescript-eslint/no-var-requires 15 | const concurrently = jest.mocked(require('concurrently')); 16 | 17 | describe('GeneratorService', () => { 18 | let fixture: GeneratorService; 19 | 20 | const log = jest.fn(); 21 | const configGet = jest.fn(); 22 | const cwd = '/my/cwd'; 23 | 24 | beforeEach(async () => { 25 | const moduleRef = await Test.createTestingModule({ 26 | providers: [ 27 | GeneratorService, 28 | { provide: LOGGER, useValue: { log } }, 29 | { 30 | provide: VersionManagerService, 31 | useValue: { filePath: () => '/path/to/4.2.1.jar' }, 32 | }, 33 | { 34 | provide: ConfigService, 35 | useValue: { cwd, get: configGet, has: () => true }, 36 | }, 37 | ], 38 | }).compile(); 39 | 40 | fixture = moduleRef.get(GeneratorService); 41 | fs.existsSync.mockReset(); 42 | fs.readJSONSync.mockReset(); 43 | }); 44 | 45 | describe('API', () => { 46 | describe('generate()', () => { 47 | const config = { 48 | ['none.json']: undefined, 49 | ['also-none.json']: {}, 50 | ['foo.json']: { 51 | angular: { 52 | glob: 'abc/**/*.yaml', 53 | output: 54 | '#{cwd}/generated-sources/openapi/typescript-angular/#{name}', 55 | 'generator-name': 'typescript-angular', 56 | 'additional-properties': { 57 | fileNaming: 'kebab-case', 58 | apiModulePrefix: '#{Name}', 59 | npmName: '#{name}RestClient', 60 | supportsES6: true, 61 | withInterfaces: true, 62 | }, 63 | }, 64 | foo: { 65 | glob: 'disabled/**/*.yaml', 66 | output: 'disabled/', 67 | disabled: true, 68 | }, 69 | baz: { 70 | glob: 'def/**/*.{json,yaml}', 71 | name: '#{name}', 72 | nameUcFirst: '#{Name}', 73 | cwd: '#{cwd}', 74 | base: '#{base}', 75 | dir: '#{dir}', 76 | path: '#{path}', 77 | relDir: '#{relDir}', 78 | relPath: '#{relPath}', 79 | ext: '#{ext}', 80 | someBool: true, 81 | someInt: 1, 82 | }, 83 | }, 84 | ['bar.json']: { 85 | bar: { 86 | glob: 'bar/abc/**/*.yaml', 87 | output: 'bar/#{name}', 88 | someBool: false, 89 | }, 90 | }, 91 | ['no-glob.json']: { 92 | noGlob: { 93 | inputSpec: 'http://example.local/openapi.json', 94 | output: 'no-glob/#{name}', 95 | name: '#{name}', 96 | nameUcFirst: '#{Name}', 97 | cwd: '#{cwd}', 98 | base: '#{base}', 99 | dir: '#{dir}', 100 | path: '#{path}', 101 | relDir: '#{relDir}', 102 | relPath: '#{relPath}', 103 | ext: '#{ext}', 104 | }, 105 | }, 106 | }; 107 | 108 | const specFiles = { 109 | 'abc/**/*.yaml': ['abc/app/pet.yaml', 'abc/app/car.yaml'], 110 | 'def/**/*.{json,yaml}': ['def/app/pet.yaml', 'def/app/car.json'], 111 | 'bar/abc/**/*.yaml': ['api/cat.yaml', 'api/bird.json'], 112 | }; 113 | 114 | let executedCommands = []; 115 | let concurrentlyCfg = []; 116 | 117 | beforeEach(() => { 118 | executedCommands = []; 119 | fs.existsSync.mockImplementation((p) => !!config[p]); 120 | fs.readJSONSync.mockImplementation((p) => config[p]); 121 | glob.sync.mockImplementation((g) => specFiles[g]); 122 | concurrently.mockImplementation((ec, cfg) => { 123 | executedCommands = ec; 124 | concurrentlyCfg = cfg; 125 | return Promise.resolve(); 126 | }); 127 | }); 128 | 129 | const cmd = (name, appendix: string[]) => ({ 130 | name, 131 | command: `java -jar "/path/to/4.2.1.jar" generate ${appendix.join( 132 | ' ' 133 | )}`, 134 | }); 135 | 136 | const cmdWithCustomJar = ( 137 | name: string, 138 | customJar: string, 139 | appendix: string[] 140 | ) => ({ 141 | name, 142 | command: `java -cp "/path/to/4.2.1.jar:${customJar}" org.openapitools.codegen.OpenAPIGenerator generate ${appendix.join( 143 | ' ' 144 | )}`, 145 | }); 146 | 147 | describe.each([ 148 | [ 149 | 'foo.json', 150 | [ 151 | cmd('[angular] abc/app/pet.yaml', [ 152 | `--input-spec="${cwd}/abc/app/pet.yaml"`, 153 | `--output="${cwd}/generated-sources/openapi/typescript-angular/pet"`, 154 | `--generator-name="typescript-angular"`, 155 | `--additional-properties="fileNaming=kebab-case,apiModulePrefix=Pet,npmName=petRestClient,supportsES6=true,withInterfaces=true"`, 156 | ]), 157 | cmd('[angular] abc/app/car.yaml', [ 158 | `--input-spec="${cwd}/abc/app/car.yaml"`, 159 | `--output="${cwd}/generated-sources/openapi/typescript-angular/car"`, 160 | `--generator-name="typescript-angular"`, 161 | `--additional-properties="fileNaming=kebab-case,apiModulePrefix=Car,npmName=carRestClient,supportsES6=true,withInterfaces=true"`, 162 | ]), 163 | cmd('[baz] def/app/pet.yaml', [ 164 | `--input-spec="${cwd}/def/app/pet.yaml"`, 165 | `--name="pet"`, 166 | `--name-uc-first="Pet"`, 167 | `--cwd="${cwd}"`, 168 | `--base="pet.yaml"`, 169 | `--dir="${cwd}/def/app"`, 170 | `--path="${cwd}/def/app/pet.yaml"`, 171 | `--rel-dir="def/app"`, 172 | `--rel-path="def/app/pet.yaml"`, 173 | `--ext="yaml"`, 174 | '--some-bool', 175 | '--some-int=1', 176 | ]), 177 | cmd('[baz] def/app/car.json', [ 178 | `--input-spec="${cwd}/def/app/car.json"`, 179 | `--name="car"`, 180 | `--name-uc-first="Car"`, 181 | `--cwd="${cwd}"`, 182 | `--base="car.json"`, 183 | `--dir="${cwd}/def/app"`, 184 | `--path="${cwd}/def/app/car.json"`, 185 | `--rel-dir="def/app"`, 186 | `--rel-path="def/app/car.json"`, 187 | `--ext="json"`, 188 | '--some-bool', 189 | '--some-int=1', 190 | ]), 191 | ], 192 | ], 193 | [ 194 | 'bar.json', 195 | [ 196 | cmd('[bar] api/cat.yaml', [ 197 | `--input-spec="${cwd}/api/cat.yaml"`, 198 | `--output="bar/cat"`, 199 | '--some-bool', 200 | ]), 201 | cmd('[bar] api/bird.json', [ 202 | `--input-spec="${cwd}/api/bird.json"`, 203 | `--output="bar/bird"`, 204 | '--some-bool', 205 | ]), 206 | ], 207 | ], 208 | [ 209 | 'bar.json', 210 | [ 211 | cmdWithCustomJar('[bar] api/cat.yaml', '../some/custom.jar', [ 212 | `--input-spec="${cwd}/api/cat.yaml"`, 213 | `--output="bar/cat"`, 214 | '--some-bool', 215 | ]), 216 | cmdWithCustomJar('[bar] api/bird.json', '../some/custom.jar', [ 217 | `--input-spec="${cwd}/api/bird.json"`, 218 | `--output="bar/bird"`, 219 | '--some-bool', 220 | ]), 221 | ], 222 | '../some/custom.jar', 223 | ], 224 | ['none.json', []], 225 | ['also-none.json', []], 226 | [ 227 | 'no-glob.json', 228 | [ 229 | cmd('[noGlob] http://example.local/openapi.json', [ 230 | `--input-spec="http://example.local/openapi.json"`, 231 | `--output="no-glob/openapi"`, 232 | `--name="openapi"`, 233 | `--name-uc-first="Openapi"`, 234 | `--cwd="${cwd}"`, 235 | `--base="openapi.json"`, 236 | `--dir="#{dir}"`, 237 | `--path="http://example.local/openapi.json"`, 238 | `--rel-dir="#{relDir}"`, 239 | `--rel-path="#{relPath}"`, 240 | `--ext="json"`, 241 | ]), 242 | ], 243 | ], 244 | ])('%s', (filePath, expectedCommands, customGenerator) => { 245 | let returnValue: boolean; 246 | 247 | beforeEach(async () => { 248 | configGet.mockImplementation( 249 | (path, defaultValue) => config[filePath] || defaultValue 250 | ); 251 | returnValue = await fixture.generate(customGenerator); 252 | }); 253 | 254 | it('calls the config get well', () => { 255 | expect(configGet).toHaveBeenNthCalledWith( 256 | 1, 257 | 'generator-cli.generators', 258 | {} 259 | ); 260 | }); 261 | 262 | it('runs max 10 processes at the same time', () => { 263 | expect(concurrentlyCfg).toEqual({ maxProcesses: 10 }); 264 | }); 265 | 266 | it(`executes ${expectedCommands.length} commands`, async () => { 267 | expect(executedCommands).toHaveLength(expectedCommands.length); 268 | expect(executedCommands).toEqual(expectedCommands); 269 | }); 270 | 271 | it(`resolved to ${expectedCommands.length > 1}`, () => { 272 | expect(returnValue).toEqual(expectedCommands.length > 0); 273 | }); 274 | }); 275 | }); 276 | }); 277 | }); 278 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/generator.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable } from '@nestjs/common'; 2 | import { flatten, isString, kebabCase, sortBy, upperFirst } from 'lodash'; 3 | 4 | import concurrently from 'concurrently'; 5 | import * as path from 'path'; 6 | import * as fs from 'fs-extra'; 7 | import * as glob from 'glob'; 8 | import chalk from 'chalk'; 9 | import * as os from 'os'; 10 | import { VersionManagerService } from './version-manager.service'; 11 | import { ConfigService } from './config.service'; 12 | import { LOGGER } from '../constants'; 13 | 14 | interface GeneratorConfig { 15 | glob: string; 16 | disabled: boolean; 17 | 18 | [key: string]: unknown; 19 | } 20 | 21 | @Injectable() 22 | export class GeneratorService { 23 | private readonly configPath = 'generator-cli.generators'; 24 | public readonly enabled = this.configService.has(this.configPath); 25 | 26 | constructor( 27 | @Inject(LOGGER) private readonly logger: LOGGER, 28 | private readonly configService: ConfigService, 29 | private readonly versionManager: VersionManagerService 30 | ) {} 31 | 32 | public async generate(customGenerator?: string, ...keys: string[]) { 33 | const cwd = this.configService.cwd; 34 | const generators = Object.entries( 35 | this.configService.get<{ [name: string]: GeneratorConfig }>( 36 | this.configPath, 37 | {} 38 | ) 39 | ); 40 | const enabledGenerators = generators 41 | .filter(([key, { disabled }]) => { 42 | if (!disabled) return true; 43 | this.logger.log( 44 | chalk.grey( 45 | `[info] Skip ${chalk.yellow( 46 | key 47 | )}, because this generator is disabled` 48 | ) 49 | ); 50 | return false; 51 | }) 52 | .filter(([key]) => { 53 | if (!keys.length || keys.includes(key)) return true; 54 | this.logger.log( 55 | chalk.grey( 56 | `[info] Skip ${chalk.yellow(key)}, because only ${keys 57 | .map((k) => chalk.yellow(k)) 58 | .join(', ')} shall run` 59 | ) 60 | ); 61 | return false; 62 | }); 63 | 64 | const globsWithNoMatches = []; 65 | 66 | const commands = flatten( 67 | enabledGenerators.map(([name, config]) => { 68 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 69 | const { glob: globPattern, disabled, ...params } = config; 70 | 71 | if (!globPattern) { 72 | return [ 73 | { 74 | name: `[${name}] ${params.inputSpec}`, 75 | command: this.buildCommand(cwd, params, customGenerator), 76 | }, 77 | ]; 78 | } 79 | 80 | const specFiles = glob.sync(globPattern, { cwd }); 81 | 82 | if (specFiles.length < 1) { 83 | globsWithNoMatches.push(globPattern); 84 | } 85 | 86 | return glob.sync(globPattern, { cwd }).map((spec) => ({ 87 | name: `[${name}] ${spec}`, 88 | command: this.buildCommand(cwd, params, customGenerator, spec), 89 | })); 90 | }) 91 | ); 92 | 93 | const generated = 94 | commands.length > 0 && 95 | (await (async () => { 96 | try { 97 | this.printResult(await concurrently(commands, { maxProcesses: 10 })); 98 | return true; 99 | } catch (e) { 100 | this.printResult(e); 101 | return false; 102 | } 103 | })()); 104 | 105 | globsWithNoMatches.map((g) => 106 | this.logger.log( 107 | chalk.yellow(`[warn] Did not found any file matching glob "${g}"`) 108 | ) 109 | ); 110 | return generated; 111 | } 112 | 113 | private printResult( 114 | res: { command: concurrently.CommandObj; exitCode: number }[] 115 | ) { 116 | this.logger.log( 117 | sortBy(res, 'command.name') 118 | .map(({ exitCode, command }) => { 119 | const failed = exitCode > 0; 120 | return [ 121 | chalk[failed ? 'red' : 'green'](command.name), 122 | ...(failed ? [chalk.yellow(` ${command.command}\n`)] : []), 123 | ].join('\n'); 124 | }) 125 | .join('\n') 126 | ); 127 | } 128 | 129 | private buildCommand( 130 | cwd: string, 131 | params: Record, 132 | customGenerator?: string, 133 | specFile?: string 134 | ) { 135 | const dockerVolumes = {}; 136 | const absoluteSpecPath = specFile 137 | ? path.resolve(cwd, specFile) 138 | : String(params.inputSpec); 139 | 140 | const ext = path.extname(absoluteSpecPath); 141 | const name = path.basename(absoluteSpecPath, ext); 142 | 143 | const placeholders: { [key: string]: string } = { 144 | name, 145 | Name: upperFirst(name), 146 | 147 | cwd, 148 | 149 | base: path.basename(absoluteSpecPath), 150 | dir: specFile && path.dirname(absoluteSpecPath), 151 | path: absoluteSpecPath, 152 | 153 | relDir: specFile && path.dirname(specFile), 154 | relPath: specFile, 155 | ext: ext.split('.').slice(-1).pop(), 156 | }; 157 | 158 | const command = Object.entries({ 159 | inputSpec: absoluteSpecPath, 160 | ...params, 161 | }) 162 | .map(([k, v]) => { 163 | const key = kebabCase(k); 164 | const value = (() => { 165 | switch (typeof v) { 166 | case 'object': 167 | return `"${Object.entries(v) 168 | .map((z) => z.join('=')) 169 | .join(',')}"`; 170 | case 'number': 171 | case 'bigint': 172 | return `${v}`; 173 | case 'boolean': 174 | return undefined; 175 | default: 176 | if (this.configService.useDocker) { 177 | v = this.replacePlaceholders(placeholders, v); 178 | 179 | if (key === 'output') { 180 | fs.ensureDirSync(v); 181 | } 182 | 183 | if (fs.existsSync(v)) { 184 | dockerVolumes[`/local/${key}`] = path.resolve(cwd, v); 185 | return `"/local/${key}"`; 186 | } 187 | } 188 | 189 | return `"${v}"`; 190 | } 191 | })(); 192 | 193 | return value === undefined ? `--${key}` : `--${key}=${value}`; 194 | }) 195 | .join(' '); 196 | 197 | return this.cmd( 198 | customGenerator, 199 | this.replacePlaceholders(placeholders, command), 200 | dockerVolumes 201 | ); 202 | } 203 | 204 | private replacePlaceholders( 205 | placeholders: Record, 206 | input: string 207 | ) { 208 | return Object.entries(placeholders) 209 | .filter(([, replacement]) => !!replacement) 210 | .reduce((acc, [search, replacement]) => { 211 | return acc.split(`#{${search}}`).join(replacement); 212 | }, input); 213 | } 214 | 215 | private cmd = ( 216 | customGenerator: string | undefined, 217 | appendix: string, 218 | dockerVolumes = {} 219 | ) => { 220 | if (this.configService.useDocker) { 221 | const volumes = Object.entries(dockerVolumes) 222 | .map(([k, v]) => `-v "${v}:${k}"`) 223 | .join(' '); 224 | const userInfo = os.userInfo(); 225 | const userArg = 226 | userInfo.uid !== -1 ? `--user ${userInfo.uid}:${userInfo.gid}` : ``; 227 | 228 | return [ 229 | `docker run --rm`, 230 | userArg, 231 | volumes, 232 | this.versionManager.getDockerImageName(), 233 | 'generate', 234 | appendix, 235 | ].join(' '); 236 | } 237 | 238 | const cliPath = this.versionManager.filePath(); 239 | const subCmd = customGenerator 240 | ? `-cp "${[cliPath, customGenerator].join( 241 | this.isWin() ? ';' : ':' 242 | )}" org.openapitools.codegen.OpenAPIGenerator` 243 | : `-jar "${cliPath}"`; 244 | return ['java', process.env['JAVA_OPTS'], subCmd, 'generate', appendix] 245 | .filter(isString) 246 | .join(' '); 247 | }; 248 | 249 | private isWin = () => process.platform === 'win32'; 250 | } 251 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ui.service' 2 | export * from './config.service' 3 | export * from './generator.service' 4 | export * from './pass-through.service' 5 | export * from './version-manager.service' 6 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/pass-through.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable } from '@nestjs/common'; 2 | import chalk from 'chalk'; 3 | import { exec, spawn } from 'child_process'; 4 | import { Command } from 'commander'; 5 | import { isString, startsWith, trim } from 'lodash'; 6 | import { COMMANDER_PROGRAM, LOGGER } from '../constants'; 7 | import { GeneratorService } from './generator.service'; 8 | import { VersionManagerService } from './version-manager.service'; 9 | import { ConfigService } from './config.service'; 10 | 11 | @Injectable() 12 | export class PassThroughService { 13 | constructor( 14 | @Inject(LOGGER) private readonly logger: LOGGER, 15 | @Inject(COMMANDER_PROGRAM) private readonly program: Command, 16 | private readonly versionManager: VersionManagerService, 17 | private readonly configService: ConfigService, 18 | private readonly generatorService: GeneratorService 19 | ) {} 20 | 21 | public async init() { 22 | this.program 23 | .allowUnknownOption() 24 | .option('--custom-generator ', 'Custom generator jar'); 25 | 26 | const commands = (await this.getCommands()).reduce((acc, [name, desc]) => { 27 | return acc.set( 28 | name, 29 | this.program 30 | .command(name, { hidden: !desc }) 31 | .description(desc) 32 | .allowUnknownOption() 33 | .action((_, c) => this.passThrough(c)) 34 | ); 35 | }, new Map>()); 36 | 37 | /* 38 | * Overwrite help command 39 | */ 40 | commands.get('help').action((_, cmd) => { 41 | if (!cmd.args.length) { 42 | this.printHelp(this.program); 43 | return; 44 | } 45 | 46 | const [helpCmd] = cmd.args; 47 | if (commands.has(helpCmd)) { 48 | this.printHelp(commands.get(helpCmd)); 49 | } 50 | 51 | this.passThrough(cmd); 52 | }); 53 | 54 | /* 55 | * Overwrite generate command 56 | */ 57 | commands 58 | .get('generate') 59 | .option( 60 | '--generator-key ', 61 | 'Run generator by key. Separate by comma to run many generators' 62 | ) 63 | .action(async (_, cmd) => { 64 | if (cmd.args.length === 0 || cmd.opts().generatorKey) { 65 | const customGenerator = this.program.opts()?.customGenerator; 66 | const generatorKeys = cmd.opts().generatorKey || []; 67 | 68 | if (this.generatorService.enabled) { 69 | // @todo cover by unit test 70 | if ( 71 | !(await this.generatorService.generate( 72 | customGenerator, 73 | ...generatorKeys 74 | )) 75 | ) { 76 | this.logger.log(chalk.red('Code generation failed')); 77 | process.exit(1); 78 | } 79 | return; 80 | } 81 | } 82 | 83 | this.passThrough(cmd); 84 | }); 85 | } 86 | 87 | public passThrough = (cmd: Command) => { 88 | const args = [cmd.name(), ...cmd.args]; 89 | 90 | spawn(this.cmd(), args, { 91 | stdio: 'inherit', 92 | shell: true, 93 | }).on('exit', process.exit); 94 | }; 95 | 96 | private getCommands = async (): Promise<[string, string | undefined][]> => { 97 | const [help, completion] = await Promise.all([ 98 | this.run('help'), 99 | this.run('completion').catch(() => ''), 100 | ]); 101 | 102 | const commands = help 103 | .split('\n') 104 | .filter((line) => startsWith(line, ' ')) 105 | .map(trim) 106 | .map((line) => line.match(/^([a-z-]+)\s+(.+)/i).slice(1)) 107 | .reduce((acc, [cmd, desc]) => ({ ...acc, [cmd]: desc }), {}); 108 | 109 | const allCommands = completion 110 | .split('\n') 111 | .map(trim) 112 | .filter((c) => c.length > 0 && c.indexOf('--') !== 0); 113 | 114 | for (const cmd of allCommands) { 115 | commands[cmd] = commands[cmd] || ''; 116 | } 117 | 118 | return Object.entries(commands); 119 | }; 120 | 121 | private run = (subCmd: string) => 122 | new Promise((resolve, reject) => { 123 | exec(`${this.cmd()} ${subCmd}`, (error, stdout, stderr) => { 124 | error ? reject(new Error(stderr)) : resolve(stdout); 125 | }); 126 | }); 127 | 128 | private cmd() { 129 | if (this.configService.useDocker) { 130 | return [ 131 | `docker run --rm -v "${this.configService.cwd}:/local"`, 132 | this.versionManager.getDockerImageName(), 133 | ].join(' '); 134 | } 135 | 136 | const customGenerator = this.program.opts()?.customGenerator; 137 | const cliPath = this.versionManager.filePath(); 138 | 139 | const subCmd = customGenerator 140 | ? `-cp "${[cliPath, customGenerator].join( 141 | this.isWin() ? ';' : ':' 142 | )}" org.openapitools.codegen.OpenAPIGenerator` 143 | : `-jar "${cliPath}"`; 144 | 145 | return ['java', process.env['JAVA_OPTS'], subCmd] 146 | .filter(isString) 147 | .join(' '); 148 | } 149 | 150 | private printHelp(cmd: Pick) { 151 | console.log(chalk.cyanBright(cmd.helpInformation())); 152 | } 153 | 154 | private isWin = () => process.platform === 'win32'; 155 | } 156 | -------------------------------------------------------------------------------- /apps/generator-cli/src/app/services/ui.service.ts: -------------------------------------------------------------------------------- 1 | // import ora from 'ora' 2 | import {Injectable} from '@nestjs/common'; 3 | import {prompt, Separator} from 'inquirer'; 4 | import {getTable} from 'console.table' 5 | 6 | @Injectable() 7 | export class UIService { 8 | 9 | public async table(config: { 10 | name: string, 11 | message: string, 12 | printColNum?: boolean, 13 | rows: Array<{ row: Record, short: string, value: T }>, 14 | }): Promise { 15 | 16 | 17 | const table = getTable(config.rows.map(({row}, index: number) => { 18 | return config.printColNum === false ? row : ({'#': index + 1, ...row}); 19 | })) 20 | 21 | const [header, separator, ...rows] = table.trim().split('\n') 22 | return this.list({ 23 | name: config.name, 24 | message: config.message, 25 | choices: [ 26 | new Separator(header), 27 | new Separator(separator), 28 | ...rows.map((name: string, index: number) => ({ 29 | name, 30 | short: config.rows[index].short, 31 | value: config.rows[index].value, 32 | })), 33 | new Separator(separator), 34 | new Separator(' '.repeat(separator.length)), 35 | ], 36 | }) 37 | } 38 | 39 | public async list(config: { 40 | name: string, 41 | message: string, 42 | choices: Array<{ name: Record, short?: string, value: T }>, 43 | }): Promise { 44 | 45 | const separatorCount = config 46 | .choices 47 | .filter((c) => c instanceof Separator) 48 | .length 49 | 50 | const res = await prompt([{ 51 | type: 'list', 52 | name: config.name, 53 | pageSize: process.stdout.rows - separatorCount - 1, 54 | message: config.message, 55 | choices: config.choices, 56 | }]) 57 | 58 | return res[config.name] as T 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /apps/generator-cli/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | }; 4 | -------------------------------------------------------------------------------- /apps/generator-cli/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false, 3 | }; 4 | -------------------------------------------------------------------------------- /apps/generator-cli/src/main.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This is not a production server yet! 3 | * This is only a minimal backend to get started. 4 | */ 5 | 6 | import {NestFactory} from '@nestjs/core'; 7 | import {AppModule} from './app/app.module'; 8 | 9 | async function bootstrap() { 10 | await NestFactory.createApplicationContext(AppModule, {logger: false}); 11 | } 12 | 13 | bootstrap(); 14 | -------------------------------------------------------------------------------- /apps/generator-cli/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "module": "commonjs", 6 | "types": ["node"], 7 | "emitDecoratorMetadata": true, 8 | "target": "es2021" 9 | }, 10 | "exclude": [ 11 | "jest.config.ts", 12 | "src/**/*.spec.ts", 13 | "src/**/*.test.ts", 14 | "src/**/*.mock.ts" 15 | ], 16 | "include": ["src/**/*.ts"] 17 | } 18 | -------------------------------------------------------------------------------- /apps/generator-cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "files": [], 4 | "include": [], 5 | "references": [ 6 | { 7 | "path": "./tsconfig.app.json" 8 | }, 9 | { 10 | "path": "./tsconfig.spec.json" 11 | } 12 | ], 13 | "compilerOptions": { 14 | "esModuleInterop": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /apps/generator-cli/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "module": "commonjs", 6 | "types": ["jest", "node"] 7 | }, 8 | "include": [ 9 | "jest.config.ts", 10 | "src/**/*.test.ts", 11 | "src/**/*.spec.ts", 12 | "src/**/*.mock.ts", 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /apps/generator-cli/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | /* eslint-disable @typescript-eslint/no-var-requires */ 3 | const { composePlugins, withNx } = require('@nx/webpack'); 4 | const { name, version, ...packageConfig } = require('../../package.json'); 5 | const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin'); 6 | const { BannerPlugin } = require('webpack'); 7 | const { omit } = require('lodash'); 8 | 9 | // Nx plugins for webpack. 10 | module.exports = composePlugins( 11 | withNx({ 12 | target: 'node', 13 | }), 14 | (config) => { 15 | const basePackageValues = { 16 | ...omit(packageConfig, ['scripts', 'dependencies', 'devDependencies']), 17 | version, 18 | name: `@${name}/openapi-generator-cli`, 19 | description: 20 | 'A npm package wrapper for OpenAPI Generator (https://github.com/OpenAPITools/openapi-generator), generates which API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)', 21 | scripts: { 22 | postinstall: 'opencollective || exit 0', 23 | }, 24 | bin: { 25 | 'openapi-generator-cli': './main.js', 26 | }, 27 | files: ['config.schema.json', 'README.md', 'main.js'], 28 | dependencies: { 29 | 'reflect-metadata': '', 30 | '@nuxtjs/opencollective': '', 31 | axios: '', 32 | }, 33 | }; 34 | 35 | config.plugins.push( 36 | new BannerPlugin({ banner: '#!/usr/bin/env node', raw: true }), 37 | new GeneratePackageJsonPlugin(basePackageValues), 38 | ); 39 | 40 | return config; 41 | }, 42 | ); 43 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = {extends: ['@commitlint/config-conventional']} 2 | -------------------------------------------------------------------------------- /examples/openapitools.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json", 3 | "spaces": 2, 4 | "generator-cli": { 5 | "version": "4.3.1", 6 | "generators": { 7 | "v2.0": { 8 | "generatorName": "typescript-angular", 9 | "output": "#{cwd}/output/v2.0/#{ext}/#{name}", 10 | "glob": "**/v2.0/{json,yaml}/*.{json,yaml}" 11 | }, 12 | "v3.0": { 13 | "generatorName": "typescript-fetch", 14 | "output": "#{cwd}/output/v3.0/#{ext}/#{name}", 15 | "glob": "**/v3.0/petstore.{json,yaml}" 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "examples", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "oa": "openapi-generator-cli", 6 | "oa:generate": "openapi-generator-cli generate" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/v2.0/json/api-with-examples.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "Simple API overview", 5 | "version": "v2" 6 | }, 7 | "paths": { 8 | "/": { 9 | "get": { 10 | "operationId": "listVersionsv2", 11 | "summary": "List API versions", 12 | "produces": [ 13 | "application/json" 14 | ], 15 | "responses": { 16 | "200": { 17 | "description": "200 300 response", 18 | "examples": { 19 | "application/json": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}" 20 | } 21 | }, 22 | "300": { 23 | "description": "200 300 response", 24 | "examples": { 25 | "application/json": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}" 26 | } 27 | } 28 | } 29 | } 30 | }, 31 | "/v2": { 32 | "get": { 33 | "operationId": "getVersionDetailsv2", 34 | "summary": "Show API version details", 35 | "produces": [ 36 | "application/json" 37 | ], 38 | "responses": { 39 | "200": { 40 | "description": "200 203 response", 41 | "examples": { 42 | "application/json": "{\n \"version\": {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"media-types\": [\n {\n \"base\": \"application/xml\",\n \"type\": \"application/vnd.openstack.compute+xml;version=2\"\n },\n {\n \"base\": \"application/json\",\n \"type\": \"application/vnd.openstack.compute+json;version=2\"\n }\n ],\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf\",\n \"type\": \"application/pdf\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n }\n ]\n }\n}" 43 | } 44 | }, 45 | "203": { 46 | "description": "200 203 response", 47 | "examples": { 48 | "application/json": "{\n \"version\": {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"media-types\": [\n {\n \"base\": \"application/xml\",\n \"type\": \"application/vnd.openstack.compute+xml;version=2\"\n },\n {\n \"base\": \"application/json\",\n \"type\": \"application/vnd.openstack.compute+json;version=2\"\n }\n ],\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://23.253.228.211:8774/v2/\",\n \"rel\": \"self\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf\",\n \"type\": \"application/pdf\",\n \"rel\": \"describedby\"\n },\n {\n \"href\": \"http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl\",\n \"type\": \"application/vnd.sun.wadl+xml\",\n \"rel\": \"describedby\"\n }\n ]\n }\n}" 49 | } 50 | } 51 | } 52 | } 53 | } 54 | }, 55 | "consumes": [ 56 | "application/json" 57 | ] 58 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-expanded.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "name": "Swagger API Team", 10 | "email": "apiteam@swagger.io", 11 | "url": "http://swagger.io" 12 | }, 13 | "license": { 14 | "name": "Apache 2.0", 15 | "url": "https://www.apache.org/licenses/LICENSE-2.0.html" 16 | } 17 | }, 18 | "host": "petstore.swagger.io", 19 | "basePath": "/api", 20 | "schemes": [ 21 | "http" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json" 28 | ], 29 | "paths": { 30 | "/pets": { 31 | "get": { 32 | "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", 33 | "operationId": "findPets", 34 | "parameters": [ 35 | { 36 | "name": "tags", 37 | "in": "query", 38 | "description": "tags to filter by", 39 | "required": false, 40 | "type": "array", 41 | "collectionFormat": "csv", 42 | "items": { 43 | "type": "string" 44 | } 45 | }, 46 | { 47 | "name": "limit", 48 | "in": "query", 49 | "description": "maximum number of results to return", 50 | "required": false, 51 | "type": "integer", 52 | "format": "int32" 53 | } 54 | ], 55 | "responses": { 56 | "200": { 57 | "description": "pet response", 58 | "schema": { 59 | "type": "array", 60 | "items": { 61 | "$ref": "#/definitions/Pet" 62 | } 63 | } 64 | }, 65 | "default": { 66 | "description": "unexpected error", 67 | "schema": { 68 | "$ref": "#/definitions/Error" 69 | } 70 | } 71 | } 72 | }, 73 | "post": { 74 | "description": "Creates a new pet in the store. Duplicates are allowed", 75 | "operationId": "addPet", 76 | "parameters": [ 77 | { 78 | "name": "pet", 79 | "in": "body", 80 | "description": "Pet to add to the store", 81 | "required": true, 82 | "schema": { 83 | "$ref": "#/definitions/NewPet" 84 | } 85 | } 86 | ], 87 | "responses": { 88 | "200": { 89 | "description": "pet response", 90 | "schema": { 91 | "$ref": "#/definitions/Pet" 92 | } 93 | }, 94 | "default": { 95 | "description": "unexpected error", 96 | "schema": { 97 | "$ref": "#/definitions/Error" 98 | } 99 | } 100 | } 101 | } 102 | }, 103 | "/pets/{id}": { 104 | "get": { 105 | "description": "Returns a user based on a single ID, if the user does not have access to the pet", 106 | "operationId": "find pet by id", 107 | "parameters": [ 108 | { 109 | "name": "id", 110 | "in": "path", 111 | "description": "ID of pet to fetch", 112 | "required": true, 113 | "type": "integer", 114 | "format": "int64" 115 | } 116 | ], 117 | "responses": { 118 | "200": { 119 | "description": "pet response", 120 | "schema": { 121 | "$ref": "#/definitions/Pet" 122 | } 123 | }, 124 | "default": { 125 | "description": "unexpected error", 126 | "schema": { 127 | "$ref": "#/definitions/Error" 128 | } 129 | } 130 | } 131 | }, 132 | "delete": { 133 | "description": "deletes a single pet based on the ID supplied", 134 | "operationId": "deletePet", 135 | "parameters": [ 136 | { 137 | "name": "id", 138 | "in": "path", 139 | "description": "ID of pet to delete", 140 | "required": true, 141 | "type": "integer", 142 | "format": "int64" 143 | } 144 | ], 145 | "responses": { 146 | "204": { 147 | "description": "pet deleted" 148 | }, 149 | "default": { 150 | "description": "unexpected error", 151 | "schema": { 152 | "$ref": "#/definitions/Error" 153 | } 154 | } 155 | } 156 | } 157 | } 158 | }, 159 | "definitions": { 160 | "Pet": { 161 | "type": "object", 162 | "allOf": [ 163 | { 164 | "$ref": "#/definitions/NewPet" 165 | }, 166 | { 167 | "required": [ 168 | "id" 169 | ], 170 | "properties": { 171 | "id": { 172 | "type": "integer", 173 | "format": "int64" 174 | } 175 | } 176 | } 177 | ] 178 | }, 179 | "NewPet": { 180 | "type": "object", 181 | "required": [ 182 | "name" 183 | ], 184 | "properties": { 185 | "name": { 186 | "type": "string" 187 | }, 188 | "tag": { 189 | "type": "string" 190 | } 191 | } 192 | }, 193 | "Error": { 194 | "type": "object", 195 | "required": [ 196 | "code", 197 | "message" 198 | ], 199 | "properties": { 200 | "code": { 201 | "type": "integer", 202 | "format": "int32" 203 | }, 204 | "message": { 205 | "type": "string" 206 | } 207 | } 208 | } 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-minimal.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "name": "Swagger API Team" 10 | }, 11 | "license": { 12 | "name": "MIT" 13 | } 14 | }, 15 | "host": "petstore.swagger.io", 16 | "basePath": "/api", 17 | "schemes": [ 18 | "http" 19 | ], 20 | "consumes": [ 21 | "application/json" 22 | ], 23 | "produces": [ 24 | "application/json" 25 | ], 26 | "paths": { 27 | "/pets": { 28 | "get": { 29 | "description": "Returns all pets from the system that the user has access to", 30 | "produces": [ 31 | "application/json" 32 | ], 33 | "responses": { 34 | "200": { 35 | "description": "A list of pets.", 36 | "schema": { 37 | "type": "array", 38 | "items": { 39 | "$ref": "#/definitions/Pet" 40 | } 41 | } 42 | } 43 | } 44 | } 45 | } 46 | }, 47 | "definitions": { 48 | "Pet": { 49 | "type": "object", 50 | "required": [ 51 | "id", 52 | "name" 53 | ], 54 | "properties": { 55 | "id": { 56 | "type": "integer", 57 | "format": "int64" 58 | }, 59 | "name": { 60 | "type": "string" 61 | }, 62 | "tag": { 63 | "type": "string" 64 | } 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-separate/common/Error.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "code", 5 | "message" 6 | ], 7 | "properties": { 8 | "code": { 9 | "type": "integer", 10 | "format": "int32" 11 | }, 12 | "message": { 13 | "type": "string" 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-separate/spec/NewPet.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "allOf": [ 4 | { 5 | "$ref": "Pet.json" 6 | }, 7 | { 8 | "required": [ 9 | "name" 10 | ], 11 | "properties": { 12 | "description": { 13 | "type": "integer", 14 | "format": "int64" 15 | } 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-separate/spec/Pet.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "required": [ 4 | "id", 5 | "name" 6 | ], 7 | "properties": { 8 | "id": { 9 | "type": "integer", 10 | "format": "int64" 11 | }, 12 | "name": { 13 | "type": "string" 14 | }, 15 | "tag": { 16 | "type": "string" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-separate/spec/parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "tagsParam": { 3 | "name": "tags", 4 | "in": "query", 5 | "description": "tags to filter by", 6 | "required": false, 7 | "type": "array", 8 | "collectionFormat": "csv", 9 | "items": { 10 | "type": "string" 11 | } 12 | }, 13 | "limitsParam": { 14 | "name": "limit", 15 | "in": "query", 16 | "description": "maximum number of results to return", 17 | "required": false, 18 | "type": "integer", 19 | "format": "int32" 20 | } 21 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-separate/spec/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "name": "Swagger API Team", 10 | "email": "apiteam@swagger.io", 11 | "url": "http://swagger.io" 12 | }, 13 | "license": { 14 | "name": "Apache 2.0", 15 | "url": "https://www.apache.org/licenses/LICENSE-2.0.html" 16 | } 17 | }, 18 | "host": "petstore.swagger.io", 19 | "basePath": "/api", 20 | "schemes": [ 21 | "http" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json" 28 | ], 29 | "paths": { 30 | "/pets": { 31 | "get": { 32 | "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", 33 | "operationId": "findPets", 34 | "parameters": [ 35 | { 36 | "$ref": "parameters.json#/tagsParam" 37 | }, 38 | { 39 | "$ref": "parameters.json#/limitsParam" 40 | } 41 | ], 42 | "responses": { 43 | "200": { 44 | "description": "pet response", 45 | "schema": { 46 | "type": "array", 47 | "items": { 48 | "$ref": "Pet.json" 49 | } 50 | } 51 | }, 52 | "default": { 53 | "description": "unexpected error", 54 | "schema": { 55 | "$ref": "../common/Error.json" 56 | } 57 | } 58 | } 59 | }, 60 | "post": { 61 | "description": "Creates a new pet in the store. Duplicates are allowed", 62 | "operationId": "addPet", 63 | "parameters": [ 64 | { 65 | "name": "pet", 66 | "in": "body", 67 | "description": "Pet to add to the store", 68 | "required": true, 69 | "schema": { 70 | "$ref": "NewPet.json" 71 | } 72 | } 73 | ], 74 | "responses": { 75 | "200": { 76 | "description": "pet response", 77 | "schema": { 78 | "$ref": "Pet.json" 79 | } 80 | }, 81 | "default": { 82 | "description": "unexpected error", 83 | "schema": { 84 | "$ref": "../common/Error.json" 85 | } 86 | } 87 | } 88 | } 89 | }, 90 | "/pets/{id}": { 91 | "get": { 92 | "description": "Returns a user based on a single ID, if the user does not have access to the pet", 93 | "operationId": "find pet by id", 94 | "parameters": [ 95 | { 96 | "name": "id", 97 | "in": "path", 98 | "description": "ID of pet to fetch", 99 | "required": true, 100 | "type": "integer", 101 | "format": "int64" 102 | } 103 | ], 104 | "responses": { 105 | "200": { 106 | "description": "pet response", 107 | "schema": { 108 | "$ref": "Pet.json" 109 | } 110 | }, 111 | "default": { 112 | "description": "unexpected error", 113 | "schema": { 114 | "$ref": "../common/Error.json" 115 | } 116 | } 117 | } 118 | }, 119 | "delete": { 120 | "description": "deletes a single pet based on the ID supplied", 121 | "operationId": "deletePet", 122 | "parameters": [ 123 | { 124 | "name": "id", 125 | "in": "path", 126 | "description": "ID of pet to delete", 127 | "required": true, 128 | "type": "integer", 129 | "format": "int64" 130 | } 131 | ], 132 | "responses": { 133 | "204": { 134 | "description": "pet deleted" 135 | }, 136 | "default": { 137 | "description": "unexpected error", 138 | "schema": { 139 | "$ref": "../common/Error.json" 140 | } 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-simple.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "name": "Swagger API Team" 10 | }, 11 | "license": { 12 | "name": "MIT" 13 | } 14 | }, 15 | "host": "petstore.swagger.io", 16 | "basePath": "/api", 17 | "schemes": [ 18 | "http" 19 | ], 20 | "consumes": [ 21 | "application/json" 22 | ], 23 | "produces": [ 24 | "application/json" 25 | ], 26 | "paths": { 27 | "/pets": { 28 | "get": { 29 | "description": "Returns all pets from the system that the user has access to", 30 | "operationId": "findPets", 31 | "produces": [ 32 | "application/json", 33 | "application/xml", 34 | "text/xml", 35 | "text/html" 36 | ], 37 | "parameters": [ 38 | { 39 | "name": "tags", 40 | "in": "query", 41 | "description": "tags to filter by", 42 | "required": false, 43 | "type": "array", 44 | "items": { 45 | "type": "string" 46 | }, 47 | "collectionFormat": "csv" 48 | }, 49 | { 50 | "name": "limit", 51 | "in": "query", 52 | "description": "maximum number of results to return", 53 | "required": false, 54 | "type": "integer", 55 | "format": "int32" 56 | } 57 | ], 58 | "responses": { 59 | "200": { 60 | "description": "pet response", 61 | "schema": { 62 | "type": "array", 63 | "items": { 64 | "$ref": "#/definitions/Pet" 65 | } 66 | } 67 | }, 68 | "default": { 69 | "description": "unexpected error", 70 | "schema": { 71 | "$ref": "#/definitions/ErrorModel" 72 | } 73 | } 74 | } 75 | }, 76 | "post": { 77 | "description": "Creates a new pet in the store. Duplicates are allowed", 78 | "operationId": "addPet", 79 | "produces": [ 80 | "application/json" 81 | ], 82 | "parameters": [ 83 | { 84 | "name": "pet", 85 | "in": "body", 86 | "description": "Pet to add to the store", 87 | "required": true, 88 | "schema": { 89 | "$ref": "#/definitions/NewPet" 90 | } 91 | } 92 | ], 93 | "responses": { 94 | "200": { 95 | "description": "pet response", 96 | "schema": { 97 | "$ref": "#/definitions/Pet" 98 | } 99 | }, 100 | "default": { 101 | "description": "unexpected error", 102 | "schema": { 103 | "$ref": "#/definitions/ErrorModel" 104 | } 105 | } 106 | } 107 | } 108 | }, 109 | "/pets/{id}": { 110 | "get": { 111 | "description": "Returns a user based on a single ID, if the user does not have access to the pet", 112 | "operationId": "findPetById", 113 | "produces": [ 114 | "application/json", 115 | "application/xml", 116 | "text/xml", 117 | "text/html" 118 | ], 119 | "parameters": [ 120 | { 121 | "name": "id", 122 | "in": "path", 123 | "description": "ID of pet to fetch", 124 | "required": true, 125 | "type": "integer", 126 | "format": "int64" 127 | } 128 | ], 129 | "responses": { 130 | "200": { 131 | "description": "pet response", 132 | "schema": { 133 | "$ref": "#/definitions/Pet" 134 | } 135 | }, 136 | "default": { 137 | "description": "unexpected error", 138 | "schema": { 139 | "$ref": "#/definitions/ErrorModel" 140 | } 141 | } 142 | } 143 | }, 144 | "delete": { 145 | "description": "deletes a single pet based on the ID supplied", 146 | "operationId": "deletePet", 147 | "parameters": [ 148 | { 149 | "name": "id", 150 | "in": "path", 151 | "description": "ID of pet to delete", 152 | "required": true, 153 | "type": "integer", 154 | "format": "int64" 155 | } 156 | ], 157 | "responses": { 158 | "204": { 159 | "description": "pet deleted" 160 | }, 161 | "default": { 162 | "description": "unexpected error", 163 | "schema": { 164 | "$ref": "#/definitions/ErrorModel" 165 | } 166 | } 167 | } 168 | } 169 | } 170 | }, 171 | "definitions": { 172 | "Pet": { 173 | "type": "object", 174 | "allOf": [ 175 | { 176 | "$ref": "#/definitions/NewPet" 177 | }, 178 | { 179 | "required": [ 180 | "id" 181 | ], 182 | "properties": { 183 | "id": { 184 | "type": "integer", 185 | "format": "int64" 186 | } 187 | } 188 | } 189 | ] 190 | }, 191 | "NewPet": { 192 | "type": "object", 193 | "required": [ 194 | "name" 195 | ], 196 | "properties": { 197 | "name": { 198 | "type": "string" 199 | }, 200 | "tag": { 201 | "type": "string" 202 | } 203 | } 204 | }, 205 | "ErrorModel": { 206 | "type": "object", 207 | "required": [ 208 | "code", 209 | "message" 210 | ], 211 | "properties": { 212 | "code": { 213 | "type": "integer", 214 | "format": "int32" 215 | }, 216 | "message": { 217 | "type": "string" 218 | } 219 | } 220 | } 221 | } 222 | } -------------------------------------------------------------------------------- /examples/v2.0/json/petstore-with-external-docs.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "name": "Swagger API Team", 10 | "email": "apiteam@swagger.io", 11 | "url": "http://swagger.io" 12 | }, 13 | "license": { 14 | "name": "Apache 2.0", 15 | "url": "https://www.apache.org/licenses/LICENSE-2.0.html" 16 | } 17 | }, 18 | "externalDocs": { 19 | "description": "find more info here", 20 | "url": "https://swagger.io/about" 21 | }, 22 | "host": "petstore.swagger.io", 23 | "basePath": "/api", 24 | "schemes": [ 25 | "http" 26 | ], 27 | "consumes": [ 28 | "application/json" 29 | ], 30 | "produces": [ 31 | "application/json" 32 | ], 33 | "paths": { 34 | "/pets": { 35 | "get": { 36 | "description": "Returns all pets from the system that the user has access to", 37 | "operationId": "findPets", 38 | "externalDocs": { 39 | "description": "find more info here", 40 | "url": "https://swagger.io/about" 41 | }, 42 | "produces": [ 43 | "application/json", 44 | "application/xml", 45 | "text/xml", 46 | "text/html" 47 | ], 48 | "parameters": [ 49 | { 50 | "name": "tags", 51 | "in": "query", 52 | "description": "tags to filter by", 53 | "required": false, 54 | "type": "array", 55 | "items": { 56 | "type": "string" 57 | }, 58 | "collectionFormat": "csv" 59 | }, 60 | { 61 | "name": "limit", 62 | "in": "query", 63 | "description": "maximum number of results to return", 64 | "required": false, 65 | "type": "integer", 66 | "format": "int32" 67 | } 68 | ], 69 | "responses": { 70 | "200": { 71 | "description": "pet response", 72 | "schema": { 73 | "type": "array", 74 | "items": { 75 | "$ref": "#/definitions/Pet" 76 | } 77 | } 78 | }, 79 | "default": { 80 | "description": "unexpected error", 81 | "schema": { 82 | "$ref": "#/definitions/ErrorModel" 83 | } 84 | } 85 | } 86 | }, 87 | "post": { 88 | "description": "Creates a new pet in the store. Duplicates are allowed", 89 | "operationId": "addPet", 90 | "produces": [ 91 | "application/json" 92 | ], 93 | "parameters": [ 94 | { 95 | "name": "pet", 96 | "in": "body", 97 | "description": "Pet to add to the store", 98 | "required": true, 99 | "schema": { 100 | "$ref": "#/definitions/NewPet" 101 | } 102 | } 103 | ], 104 | "responses": { 105 | "200": { 106 | "description": "pet response", 107 | "schema": { 108 | "$ref": "#/definitions/Pet" 109 | } 110 | }, 111 | "default": { 112 | "description": "unexpected error", 113 | "schema": { 114 | "$ref": "#/definitions/ErrorModel" 115 | } 116 | } 117 | } 118 | } 119 | }, 120 | "/pets/{id}": { 121 | "get": { 122 | "description": "Returns a user based on a single ID, if the user does not have access to the pet", 123 | "operationId": "findPetById", 124 | "produces": [ 125 | "application/json", 126 | "application/xml", 127 | "text/xml", 128 | "text/html" 129 | ], 130 | "parameters": [ 131 | { 132 | "name": "id", 133 | "in": "path", 134 | "description": "ID of pet to fetch", 135 | "required": true, 136 | "type": "integer", 137 | "format": "int64" 138 | } 139 | ], 140 | "responses": { 141 | "200": { 142 | "description": "pet response", 143 | "schema": { 144 | "$ref": "#/definitions/Pet" 145 | } 146 | }, 147 | "default": { 148 | "description": "unexpected error", 149 | "schema": { 150 | "$ref": "#/definitions/ErrorModel" 151 | } 152 | } 153 | } 154 | }, 155 | "delete": { 156 | "description": "deletes a single pet based on the ID supplied", 157 | "operationId": "deletePet", 158 | "parameters": [ 159 | { 160 | "name": "id", 161 | "in": "path", 162 | "description": "ID of pet to delete", 163 | "required": true, 164 | "type": "integer", 165 | "format": "int64" 166 | } 167 | ], 168 | "responses": { 169 | "204": { 170 | "description": "pet deleted" 171 | }, 172 | "default": { 173 | "description": "unexpected error", 174 | "schema": { 175 | "$ref": "#/definitions/ErrorModel" 176 | } 177 | } 178 | } 179 | } 180 | } 181 | }, 182 | "definitions": { 183 | "Pet": { 184 | "type": "object", 185 | "allOf": [ 186 | { 187 | "$ref": "#/definitions/NewPet" 188 | }, 189 | { 190 | "required": [ 191 | "id" 192 | ], 193 | "properties": { 194 | "id": { 195 | "type": "integer", 196 | "format": "int64" 197 | } 198 | } 199 | } 200 | ] 201 | }, 202 | "NewPet": { 203 | "type": "object", 204 | "required": [ 205 | "name" 206 | ], 207 | "properties": { 208 | "name": { 209 | "type": "string" 210 | }, 211 | "tag": { 212 | "type": "string" 213 | } 214 | } 215 | }, 216 | "ErrorModel": { 217 | "type": "object", 218 | "required": [ 219 | "code", 220 | "message" 221 | ], 222 | "properties": { 223 | "code": { 224 | "type": "integer", 225 | "format": "int32" 226 | }, 227 | "message": { 228 | "type": "string" 229 | } 230 | } 231 | } 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /examples/v2.0/json/petstore.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "license": { 7 | "name": "MIT" 8 | } 9 | }, 10 | "host": "petstore.swagger.io", 11 | "basePath": "/v1", 12 | "schemes": [ 13 | "http" 14 | ], 15 | "consumes": [ 16 | "application/json" 17 | ], 18 | "produces": [ 19 | "application/json" 20 | ], 21 | "paths": { 22 | "/pets": { 23 | "get": { 24 | "summary": "List all pets", 25 | "operationId": "listPets", 26 | "tags": [ 27 | "pets" 28 | ], 29 | "parameters": [ 30 | { 31 | "name": "limit", 32 | "in": "query", 33 | "description": "How many items to return at one time (max 100)", 34 | "required": false, 35 | "type": "integer", 36 | "format": "int32" 37 | } 38 | ], 39 | "responses": { 40 | "200": { 41 | "description": "An paged array of pets", 42 | "headers": { 43 | "x-next": { 44 | "type": "string", 45 | "description": "A link to the next page of responses" 46 | } 47 | }, 48 | "schema": { 49 | "$ref": "#/definitions/Pets" 50 | } 51 | }, 52 | "default": { 53 | "description": "unexpected error", 54 | "schema": { 55 | "$ref": "#/definitions/Error" 56 | } 57 | } 58 | } 59 | }, 60 | "post": { 61 | "summary": "Create a pet", 62 | "operationId": "createPets", 63 | "tags": [ 64 | "pets" 65 | ], 66 | "responses": { 67 | "201": { 68 | "description": "Null response" 69 | }, 70 | "default": { 71 | "description": "unexpected error", 72 | "schema": { 73 | "$ref": "#/definitions/Error" 74 | } 75 | } 76 | } 77 | } 78 | }, 79 | "/pets/{petId}": { 80 | "get": { 81 | "summary": "Info for a specific pet", 82 | "operationId": "showPetById", 83 | "tags": [ 84 | "pets" 85 | ], 86 | "parameters": [ 87 | { 88 | "name": "petId", 89 | "in": "path", 90 | "required": true, 91 | "description": "The id of the pet to retrieve", 92 | "type": "string" 93 | } 94 | ], 95 | "responses": { 96 | "200": { 97 | "description": "Expected response to a valid request", 98 | "schema": { 99 | "$ref": "#/definitions/Pets" 100 | } 101 | }, 102 | "default": { 103 | "description": "unexpected error", 104 | "schema": { 105 | "$ref": "#/definitions/Error" 106 | } 107 | } 108 | } 109 | } 110 | } 111 | }, 112 | "definitions": { 113 | "Pet": { 114 | "required": [ 115 | "id", 116 | "name" 117 | ], 118 | "properties": { 119 | "id": { 120 | "type": "integer", 121 | "format": "int64" 122 | }, 123 | "name": { 124 | "type": "string" 125 | }, 126 | "tag": { 127 | "type": "string" 128 | } 129 | } 130 | }, 131 | "Pets": { 132 | "type": "array", 133 | "items": { 134 | "$ref": "#/definitions/Pet" 135 | } 136 | }, 137 | "Error": { 138 | "required": [ 139 | "code", 140 | "message" 141 | ], 142 | "properties": { 143 | "code": { 144 | "type": "integer", 145 | "format": "int32" 146 | }, 147 | "message": { 148 | "type": "string" 149 | } 150 | } 151 | } 152 | } 153 | } -------------------------------------------------------------------------------- /examples/v2.0/yaml/api-with-examples.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | title: Simple API overview 4 | version: v2 5 | paths: 6 | /: 7 | get: 8 | operationId: listVersionsv2 9 | summary: List API versions 10 | produces: 11 | - application/json 12 | responses: 13 | "200": 14 | description: |- 15 | 200 300 response 16 | examples: 17 | application/json: |- 18 | { 19 | "versions": [ 20 | { 21 | "status": "CURRENT", 22 | "updated": "2011-01-21T11:33:21Z", 23 | "id": "v2.0", 24 | "links": [ 25 | { 26 | "href": "http://127.0.0.1:8774/v2/", 27 | "rel": "self" 28 | } 29 | ] 30 | }, 31 | { 32 | "status": "EXPERIMENTAL", 33 | "updated": "2013-07-23T11:33:21Z", 34 | "id": "v3.0", 35 | "links": [ 36 | { 37 | "href": "http://127.0.0.1:8774/v3/", 38 | "rel": "self" 39 | } 40 | ] 41 | } 42 | ] 43 | } 44 | "300": 45 | description: |- 46 | 200 300 response 47 | examples: 48 | application/json: |- 49 | { 50 | "versions": [ 51 | { 52 | "status": "CURRENT", 53 | "updated": "2011-01-21T11:33:21Z", 54 | "id": "v2.0", 55 | "links": [ 56 | { 57 | "href": "http://127.0.0.1:8774/v2/", 58 | "rel": "self" 59 | } 60 | ] 61 | }, 62 | { 63 | "status": "EXPERIMENTAL", 64 | "updated": "2013-07-23T11:33:21Z", 65 | "id": "v3.0", 66 | "links": [ 67 | { 68 | "href": "http://127.0.0.1:8774/v3/", 69 | "rel": "self" 70 | } 71 | ] 72 | } 73 | ] 74 | } 75 | /v2: 76 | get: 77 | operationId: getVersionDetailsv2 78 | summary: Show API version details 79 | produces: 80 | - application/json 81 | responses: 82 | "200": 83 | description: |- 84 | 200 203 response 85 | examples: 86 | application/json: |- 87 | { 88 | "version": { 89 | "status": "CURRENT", 90 | "updated": "2011-01-21T11:33:21Z", 91 | "media-types": [ 92 | { 93 | "base": "application/xml", 94 | "type": "application/vnd.openstack.compute+xml;version=2" 95 | }, 96 | { 97 | "base": "application/json", 98 | "type": "application/vnd.openstack.compute+json;version=2" 99 | } 100 | ], 101 | "id": "v2.0", 102 | "links": [ 103 | { 104 | "href": "http://127.0.0.1:8774/v2/", 105 | "rel": "self" 106 | }, 107 | { 108 | "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", 109 | "type": "application/pdf", 110 | "rel": "describedby" 111 | }, 112 | { 113 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 114 | "type": "application/vnd.sun.wadl+xml", 115 | "rel": "describedby" 116 | }, 117 | { 118 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 119 | "type": "application/vnd.sun.wadl+xml", 120 | "rel": "describedby" 121 | } 122 | ] 123 | } 124 | } 125 | "203": 126 | description: |- 127 | 200 203 response 128 | examples: 129 | application/json: |- 130 | { 131 | "version": { 132 | "status": "CURRENT", 133 | "updated": "2011-01-21T11:33:21Z", 134 | "media-types": [ 135 | { 136 | "base": "application/xml", 137 | "type": "application/vnd.openstack.compute+xml;version=2" 138 | }, 139 | { 140 | "base": "application/json", 141 | "type": "application/vnd.openstack.compute+json;version=2" 142 | } 143 | ], 144 | "id": "v2.0", 145 | "links": [ 146 | { 147 | "href": "http://23.253.228.211:8774/v2/", 148 | "rel": "self" 149 | }, 150 | { 151 | "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", 152 | "type": "application/pdf", 153 | "rel": "describedby" 154 | }, 155 | { 156 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 157 | "type": "application/vnd.sun.wadl+xml", 158 | "rel": "describedby" 159 | } 160 | ] 161 | } 162 | } 163 | consumes: 164 | - application/json 165 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-expanded.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | version: 1.0.0 4 | title: Swagger Petstore 5 | description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification 6 | termsOfService: http://swagger.io/terms/ 7 | contact: 8 | name: Swagger API Team 9 | email: apiteam@swagger.io 10 | url: http://swagger.io 11 | license: 12 | name: Apache 2.0 13 | url: https://www.apache.org/licenses/LICENSE-2.0.html 14 | host: petstore.swagger.io 15 | basePath: /api 16 | schemes: 17 | - http 18 | consumes: 19 | - application/json 20 | produces: 21 | - application/json 22 | paths: 23 | /pets: 24 | get: 25 | description: | 26 | Returns all pets from the system that the user has access to 27 | operationId: findPets 28 | parameters: 29 | - name: tags 30 | in: query 31 | description: tags to filter by 32 | required: false 33 | type: array 34 | collectionFormat: csv 35 | items: 36 | type: string 37 | - name: limit 38 | in: query 39 | description: maximum number of results to return 40 | required: false 41 | type: integer 42 | format: int32 43 | responses: 44 | "200": 45 | description: pet response 46 | schema: 47 | type: array 48 | items: 49 | $ref: '#/definitions/Pet' 50 | default: 51 | description: unexpected error 52 | schema: 53 | $ref: '#/definitions/Error' 54 | post: 55 | description: Creates a new pet in the store. Duplicates are allowed 56 | operationId: addPet 57 | parameters: 58 | - name: pet 59 | in: body 60 | description: Pet to add to the store 61 | required: true 62 | schema: 63 | $ref: '#/definitions/NewPet' 64 | responses: 65 | "200": 66 | description: pet response 67 | schema: 68 | $ref: '#/definitions/Pet' 69 | default: 70 | description: unexpected error 71 | schema: 72 | $ref: '#/definitions/Error' 73 | /pets/{id}: 74 | get: 75 | description: Returns a user based on a single ID, if the user does not have access to the pet 76 | operationId: find pet by id 77 | parameters: 78 | - name: id 79 | in: path 80 | description: ID of pet to fetch 81 | required: true 82 | type: integer 83 | format: int64 84 | responses: 85 | "200": 86 | description: pet response 87 | schema: 88 | $ref: '#/definitions/Pet' 89 | default: 90 | description: unexpected error 91 | schema: 92 | $ref: '#/definitions/Error' 93 | delete: 94 | description: deletes a single pet based on the ID supplied 95 | operationId: deletePet 96 | parameters: 97 | - name: id 98 | in: path 99 | description: ID of pet to delete 100 | required: true 101 | type: integer 102 | format: int64 103 | responses: 104 | "204": 105 | description: pet deleted 106 | default: 107 | description: unexpected error 108 | schema: 109 | $ref: '#/definitions/Error' 110 | definitions: 111 | Pet: 112 | allOf: 113 | - $ref: '#/definitions/NewPet' 114 | - required: 115 | - id 116 | type: "object" 117 | properties: 118 | id: 119 | type: integer 120 | format: int64 121 | 122 | NewPet: 123 | type: "object" 124 | required: 125 | - name 126 | properties: 127 | name: 128 | type: string 129 | tag: 130 | type: string 131 | 132 | Error: 133 | type: "object" 134 | required: 135 | - code 136 | - message 137 | properties: 138 | code: 139 | type: integer 140 | format: int32 141 | message: 142 | type: string 143 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-minimal.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | swagger: "2.0" 3 | info: 4 | version: "1.0.0" 5 | title: "Swagger Petstore" 6 | description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" 7 | termsOfService: "http://swagger.io/terms/" 8 | contact: 9 | name: "Swagger API Team" 10 | license: 11 | name: "MIT" 12 | host: "petstore.swagger.io" 13 | basePath: "/api" 14 | schemes: 15 | - "http" 16 | consumes: 17 | - "application/json" 18 | produces: 19 | - "application/json" 20 | paths: 21 | /pets: 22 | get: 23 | description: "Returns all pets from the system that the user has access to" 24 | produces: 25 | - "application/json" 26 | responses: 27 | "200": 28 | description: "A list of pets." 29 | schema: 30 | type: "array" 31 | items: 32 | $ref: "#/definitions/Pet" 33 | definitions: 34 | Pet: 35 | type: "object" 36 | required: 37 | - "id" 38 | - "name" 39 | properties: 40 | id: 41 | type: "integer" 42 | format: "int64" 43 | name: 44 | type: "string" 45 | tag: 46 | type: "string" 47 | 48 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-separate/common/Error.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | required: 3 | - code 4 | - message 5 | properties: 6 | code: 7 | type: integer 8 | format: int32 9 | message: 10 | type: string 11 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-separate/spec/NewPet.yaml: -------------------------------------------------------------------------------- 1 | type: object 2 | allOf: 3 | - $ref: 'Pet.yaml' 4 | - required: 5 | - name 6 | properties: 7 | description: 8 | type: integer 9 | format: int64 10 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-separate/spec/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 13 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-separate/spec/parameters.yaml: -------------------------------------------------------------------------------- 1 | tagsParam: 2 | name: tags 3 | in: query 4 | description: tags to filter by 5 | required: false 6 | type: array 7 | collectionFormat: csv 8 | items: 9 | type: string 10 | limitsParam: 11 | name: limit 12 | in: query 13 | description: maximum number of results to return 14 | required: false 15 | type: integer 16 | format: int32 17 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-separate/spec/swagger.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | version: 1.0.0 4 | title: Swagger Petstore 5 | description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification 6 | termsOfService: http://swagger.io/terms/ 7 | contact: 8 | name: Swagger API Team 9 | email: apiteam@swagger.io 10 | url: http://swagger.io 11 | license: 12 | name: Apache 2.0 13 | url: https://www.apache.org/licenses/LICENSE-2.0.html 14 | host: petstore.swagger.io 15 | basePath: /api 16 | schemes: 17 | - http 18 | consumes: 19 | - application/json 20 | produces: 21 | - application/json 22 | paths: 23 | /pets: 24 | get: 25 | description: | 26 | Returns all pets from the system that the user has access to 27 | Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. 28 | 29 | Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. 30 | operationId: findPets 31 | parameters: 32 | - $ref: 'parameters.yaml#/tagsParam' 33 | - $ref: 'parameters.yaml#/limitsParam' 34 | responses: 35 | "200": 36 | description: pet response 37 | schema: 38 | type: array 39 | items: 40 | $ref: 'Pet.yaml' 41 | default: 42 | description: unexpected error 43 | schema: 44 | $ref: '../common/Error.yaml' 45 | post: 46 | description: Creates a new pet in the store. Duplicates are allowed 47 | operationId: addPet 48 | parameters: 49 | - name: pet 50 | in: body 51 | description: Pet to add to the store 52 | required: true 53 | schema: 54 | $ref: 'NewPet.yaml' 55 | responses: 56 | "200": 57 | description: pet response 58 | schema: 59 | $ref: 'Pet.yaml' 60 | default: 61 | description: unexpected error 62 | schema: 63 | $ref: '../common/Error.yaml' 64 | /pets/{id}: 65 | get: 66 | description: Returns a user based on a single ID, if the user does not have access to the pet 67 | operationId: find pet by id 68 | parameters: 69 | - name: id 70 | in: path 71 | description: ID of pet to fetch 72 | required: true 73 | type: integer 74 | format: int64 75 | responses: 76 | "200": 77 | description: pet response 78 | schema: 79 | $ref: 'Pet.yaml' 80 | default: 81 | description: unexpected error 82 | schema: 83 | $ref: '../common/Error.yaml' 84 | delete: 85 | description: deletes a single pet based on the ID supplied 86 | operationId: deletePet 87 | parameters: 88 | - name: id 89 | in: path 90 | description: ID of pet to delete 91 | required: true 92 | type: integer 93 | format: int64 94 | responses: 95 | "204": 96 | description: pet deleted 97 | default: 98 | description: unexpected error 99 | schema: 100 | $ref: '../common/Error.yaml' 101 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-simple.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | swagger: "2.0" 3 | info: 4 | version: "1.0.0" 5 | title: "Swagger Petstore" 6 | description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" 7 | termsOfService: "http://swagger.io/terms/" 8 | contact: 9 | name: "Swagger API Team" 10 | license: 11 | name: "MIT" 12 | host: "petstore.swagger.io" 13 | basePath: "/api" 14 | schemes: 15 | - "http" 16 | consumes: 17 | - "application/json" 18 | produces: 19 | - "application/json" 20 | paths: 21 | /pets: 22 | get: 23 | description: "Returns all pets from the system that the user has access to" 24 | operationId: "findPets" 25 | produces: 26 | - "application/json" 27 | - "application/xml" 28 | - "text/xml" 29 | - "text/html" 30 | parameters: 31 | - 32 | name: "tags" 33 | in: "query" 34 | description: "tags to filter by" 35 | required: false 36 | type: "array" 37 | items: 38 | type: "string" 39 | collectionFormat: "csv" 40 | - 41 | name: "limit" 42 | in: "query" 43 | description: "maximum number of results to return" 44 | required: false 45 | type: "integer" 46 | format: "int32" 47 | responses: 48 | "200": 49 | description: "pet response" 50 | schema: 51 | type: "array" 52 | items: 53 | $ref: "#/definitions/Pet" 54 | default: 55 | description: "unexpected error" 56 | schema: 57 | $ref: "#/definitions/ErrorModel" 58 | post: 59 | description: "Creates a new pet in the store. Duplicates are allowed" 60 | operationId: "addPet" 61 | produces: 62 | - "application/json" 63 | parameters: 64 | - 65 | name: "pet" 66 | in: "body" 67 | description: "Pet to add to the store" 68 | required: true 69 | schema: 70 | $ref: "#/definitions/NewPet" 71 | responses: 72 | "200": 73 | description: "pet response" 74 | schema: 75 | $ref: "#/definitions/Pet" 76 | default: 77 | description: "unexpected error" 78 | schema: 79 | $ref: "#/definitions/ErrorModel" 80 | /pets/{id}: 81 | get: 82 | description: "Returns a user based on a single ID, if the user does not have access to the pet" 83 | operationId: "findPetById" 84 | produces: 85 | - "application/json" 86 | - "application/xml" 87 | - "text/xml" 88 | - "text/html" 89 | parameters: 90 | - 91 | name: "id" 92 | in: "path" 93 | description: "ID of pet to fetch" 94 | required: true 95 | type: "integer" 96 | format: "int64" 97 | responses: 98 | "200": 99 | description: "pet response" 100 | schema: 101 | $ref: "#/definitions/Pet" 102 | default: 103 | description: "unexpected error" 104 | schema: 105 | $ref: "#/definitions/ErrorModel" 106 | delete: 107 | description: "deletes a single pet based on the ID supplied" 108 | operationId: "deletePet" 109 | parameters: 110 | - 111 | name: "id" 112 | in: "path" 113 | description: "ID of pet to delete" 114 | required: true 115 | type: "integer" 116 | format: "int64" 117 | responses: 118 | "204": 119 | description: "pet deleted" 120 | default: 121 | description: "unexpected error" 122 | schema: 123 | $ref: "#/definitions/ErrorModel" 124 | definitions: 125 | Pet: 126 | type: "object" 127 | allOf: 128 | - 129 | $ref: "#/definitions/NewPet" 130 | - 131 | required: 132 | - "id" 133 | properties: 134 | id: 135 | type: "integer" 136 | format: "int64" 137 | NewPet: 138 | type: "object" 139 | required: 140 | - "name" 141 | properties: 142 | name: 143 | type: "string" 144 | tag: 145 | type: "string" 146 | ErrorModel: 147 | type: "object" 148 | required: 149 | - "code" 150 | - "message" 151 | properties: 152 | code: 153 | type: "integer" 154 | format: "int32" 155 | message: 156 | type: "string" 157 | 158 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore-with-external-docs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | swagger: "2.0" 3 | info: 4 | version: "1.0.0" 5 | title: "Swagger Petstore" 6 | description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" 7 | termsOfService: "http://swagger.io/terms/" 8 | contact: 9 | name: "Swagger API Team" 10 | email: "apiteam@swagger.io" 11 | url: "http://swagger.io" 12 | license: 13 | name: "Apache 2.0" 14 | url: "https://www.apache.org/licenses/LICENSE-2.0.html" 15 | externalDocs: 16 | description: "find more info here" 17 | url: "https://swagger.io/about" 18 | host: "petstore.swagger.io" 19 | basePath: "/api" 20 | schemes: 21 | - "http" 22 | consumes: 23 | - "application/json" 24 | produces: 25 | - "application/json" 26 | paths: 27 | /pets: 28 | get: 29 | description: "Returns all pets from the system that the user has access to" 30 | operationId: "findPets" 31 | externalDocs: 32 | description: "find more info here" 33 | url: "https://swagger.io/about" 34 | produces: 35 | - "application/json" 36 | - "application/xml" 37 | - "text/xml" 38 | - "text/html" 39 | parameters: 40 | - 41 | name: "tags" 42 | in: "query" 43 | description: "tags to filter by" 44 | required: false 45 | type: "array" 46 | items: 47 | type: "string" 48 | collectionFormat: "csv" 49 | - 50 | name: "limit" 51 | in: "query" 52 | description: "maximum number of results to return" 53 | required: false 54 | type: "integer" 55 | format: "int32" 56 | responses: 57 | "200": 58 | description: "pet response" 59 | schema: 60 | type: "array" 61 | items: 62 | $ref: "#/definitions/Pet" 63 | default: 64 | description: "unexpected error" 65 | schema: 66 | $ref: "#/definitions/ErrorModel" 67 | post: 68 | description: "Creates a new pet in the store. Duplicates are allowed" 69 | operationId: "addPet" 70 | produces: 71 | - "application/json" 72 | parameters: 73 | - 74 | name: "pet" 75 | in: "body" 76 | description: "Pet to add to the store" 77 | required: true 78 | schema: 79 | $ref: "#/definitions/NewPet" 80 | responses: 81 | "200": 82 | description: "pet response" 83 | schema: 84 | $ref: "#/definitions/Pet" 85 | default: 86 | description: "unexpected error" 87 | schema: 88 | $ref: "#/definitions/ErrorModel" 89 | /pets/{id}: 90 | get: 91 | description: "Returns a user based on a single ID, if the user does not have access to the pet" 92 | operationId: "findPetById" 93 | produces: 94 | - "application/json" 95 | - "application/xml" 96 | - "text/xml" 97 | - "text/html" 98 | parameters: 99 | - 100 | name: "id" 101 | in: "path" 102 | description: "ID of pet to fetch" 103 | required: true 104 | type: "integer" 105 | format: "int64" 106 | responses: 107 | "200": 108 | description: "pet response" 109 | schema: 110 | $ref: "#/definitions/Pet" 111 | default: 112 | description: "unexpected error" 113 | schema: 114 | $ref: "#/definitions/ErrorModel" 115 | delete: 116 | description: "deletes a single pet based on the ID supplied" 117 | operationId: "deletePet" 118 | parameters: 119 | - 120 | name: "id" 121 | in: "path" 122 | description: "ID of pet to delete" 123 | required: true 124 | type: "integer" 125 | format: "int64" 126 | responses: 127 | "204": 128 | description: "pet deleted" 129 | default: 130 | description: "unexpected error" 131 | schema: 132 | $ref: "#/definitions/ErrorModel" 133 | definitions: 134 | Pet: 135 | type: "object" 136 | allOf: 137 | - 138 | $ref: "#/definitions/NewPet" 139 | - 140 | required: 141 | - "id" 142 | properties: 143 | id: 144 | type: "integer" 145 | format: "int64" 146 | NewPet: 147 | type: "object" 148 | required: 149 | - "name" 150 | properties: 151 | name: 152 | type: "string" 153 | tag: 154 | type: "string" 155 | ErrorModel: 156 | type: "object" 157 | required: 158 | - "code" 159 | - "message" 160 | properties: 161 | code: 162 | type: "integer" 163 | format: "int32" 164 | message: 165 | type: "string" 166 | 167 | -------------------------------------------------------------------------------- /examples/v2.0/yaml/petstore.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | version: 1.0.0 4 | title: Swagger Petstore 5 | license: 6 | name: MIT 7 | host: petstore.swagger.io 8 | basePath: /v1 9 | schemes: 10 | - http 11 | consumes: 12 | - application/json 13 | produces: 14 | - application/json 15 | paths: 16 | /pets: 17 | get: 18 | summary: List all pets 19 | operationId: listPets 20 | tags: 21 | - pets 22 | parameters: 23 | - name: limit 24 | in: query 25 | description: How many items to return at one time (max 100) 26 | required: false 27 | type: integer 28 | format: int32 29 | responses: 30 | "200": 31 | description: A paged array of pets 32 | headers: 33 | x-next: 34 | type: string 35 | description: A link to the next page of responses 36 | schema: 37 | $ref: '#/definitions/Pets' 38 | default: 39 | description: unexpected error 40 | schema: 41 | $ref: '#/definitions/Error' 42 | post: 43 | summary: Create a pet 44 | operationId: createPets 45 | tags: 46 | - pets 47 | responses: 48 | "201": 49 | description: Null response 50 | default: 51 | description: unexpected error 52 | schema: 53 | $ref: '#/definitions/Error' 54 | /pets/{petId}: 55 | get: 56 | summary: Info for a specific pet 57 | operationId: showPetById 58 | tags: 59 | - pets 60 | parameters: 61 | - name: petId 62 | in: path 63 | required: true 64 | description: The id of the pet to retrieve 65 | type: string 66 | responses: 67 | "200": 68 | description: Expected response to a valid request 69 | schema: 70 | $ref: '#/definitions/Pets' 71 | default: 72 | description: unexpected error 73 | schema: 74 | $ref: '#/definitions/Error' 75 | definitions: 76 | Pet: 77 | type: "object" 78 | required: 79 | - id 80 | - name 81 | properties: 82 | id: 83 | type: integer 84 | format: int64 85 | name: 86 | type: string 87 | tag: 88 | type: string 89 | Pets: 90 | type: array 91 | items: 92 | $ref: '#/definitions/Pet' 93 | Error: 94 | type: "object" 95 | required: 96 | - code 97 | - message 98 | properties: 99 | code: 100 | type: integer 101 | format: int32 102 | message: 103 | type: string 104 | -------------------------------------------------------------------------------- /examples/v3.0/api-with-examples.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.0", 3 | "info": { 4 | "title": "Simple API overview", 5 | "version": "2.0.0" 6 | }, 7 | "paths": { 8 | "/": { 9 | "get": { 10 | "operationId": "listVersionsv2", 11 | "summary": "List API versions", 12 | "responses": { 13 | "200": { 14 | "description": "200 response", 15 | "content": { 16 | "application/json": { 17 | "examples": { 18 | "foo": { 19 | "value": { 20 | "versions": [ 21 | { 22 | "status": "CURRENT", 23 | "updated": "2011-01-21T11:33:21Z", 24 | "id": "v2.0", 25 | "links": [ 26 | { 27 | "href": "http://127.0.0.1:8774/v2/", 28 | "rel": "self" 29 | } 30 | ] 31 | }, 32 | { 33 | "status": "EXPERIMENTAL", 34 | "updated": "2013-07-23T11:33:21Z", 35 | "id": "v3.0", 36 | "links": [ 37 | { 38 | "href": "http://127.0.0.1:8774/v3/", 39 | "rel": "self" 40 | } 41 | ] 42 | } 43 | ] 44 | } 45 | } 46 | } 47 | } 48 | } 49 | }, 50 | "300": { 51 | "description": "300 response", 52 | "content": { 53 | "application/json": { 54 | "examples": { 55 | "foo": { 56 | "value": "{\n \"versions\": [\n {\n \"status\": \"CURRENT\",\n \"updated\": \"2011-01-21T11:33:21Z\",\n \"id\": \"v2.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v2/\",\n \"rel\": \"self\"\n }\n ]\n },\n {\n \"status\": \"EXPERIMENTAL\",\n \"updated\": \"2013-07-23T11:33:21Z\",\n \"id\": \"v3.0\",\n \"links\": [\n {\n \"href\": \"http://127.0.0.1:8774/v3/\",\n \"rel\": \"self\"\n }\n ]\n }\n ]\n}\n" 57 | } 58 | } 59 | } 60 | } 61 | } 62 | } 63 | } 64 | }, 65 | "/v2": { 66 | "get": { 67 | "operationId": "getVersionDetailsv2", 68 | "summary": "Show API version details", 69 | "responses": { 70 | "200": { 71 | "description": "200 response", 72 | "content": { 73 | "application/json": { 74 | "examples": { 75 | "foo": { 76 | "value": { 77 | "version": { 78 | "status": "CURRENT", 79 | "updated": "2011-01-21T11:33:21Z", 80 | "media-types": [ 81 | { 82 | "base": "application/xml", 83 | "type": "application/vnd.openstack.compute+xml;version=2" 84 | }, 85 | { 86 | "base": "application/json", 87 | "type": "application/vnd.openstack.compute+json;version=2" 88 | } 89 | ], 90 | "id": "v2.0", 91 | "links": [ 92 | { 93 | "href": "http://127.0.0.1:8774/v2/", 94 | "rel": "self" 95 | }, 96 | { 97 | "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", 98 | "type": "application/pdf", 99 | "rel": "describedby" 100 | }, 101 | { 102 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 103 | "type": "application/vnd.sun.wadl+xml", 104 | "rel": "describedby" 105 | }, 106 | { 107 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 108 | "type": "application/vnd.sun.wadl+xml", 109 | "rel": "describedby" 110 | } 111 | ] 112 | } 113 | } 114 | } 115 | } 116 | } 117 | } 118 | }, 119 | "203": { 120 | "description": "203 response", 121 | "content": { 122 | "application/json": { 123 | "examples": { 124 | "foo": { 125 | "value": { 126 | "version": { 127 | "status": "CURRENT", 128 | "updated": "2011-01-21T11:33:21Z", 129 | "media-types": [ 130 | { 131 | "base": "application/xml", 132 | "type": "application/vnd.openstack.compute+xml;version=2" 133 | }, 134 | { 135 | "base": "application/json", 136 | "type": "application/vnd.openstack.compute+json;version=2" 137 | } 138 | ], 139 | "id": "v2.0", 140 | "links": [ 141 | { 142 | "href": "http://23.253.228.211:8774/v2/", 143 | "rel": "self" 144 | }, 145 | { 146 | "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", 147 | "type": "application/pdf", 148 | "rel": "describedby" 149 | }, 150 | { 151 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 152 | "type": "application/vnd.sun.wadl+xml", 153 | "rel": "describedby" 154 | } 155 | ] 156 | } 157 | } 158 | } 159 | } 160 | } 161 | } 162 | } 163 | } 164 | } 165 | } 166 | } 167 | } -------------------------------------------------------------------------------- /examples/v3.0/api-with-examples.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | title: Simple API overview 4 | version: 2.0.0 5 | paths: 6 | /: 7 | get: 8 | operationId: listVersionsv2 9 | summary: List API versions 10 | responses: 11 | '200': 12 | description: |- 13 | 200 response 14 | content: 15 | application/json: 16 | examples: 17 | foo: 18 | value: 19 | { 20 | "versions": [ 21 | { 22 | "status": "CURRENT", 23 | "updated": "2011-01-21T11:33:21Z", 24 | "id": "v2.0", 25 | "links": [ 26 | { 27 | "href": "http://127.0.0.1:8774/v2/", 28 | "rel": "self" 29 | } 30 | ] 31 | }, 32 | { 33 | "status": "EXPERIMENTAL", 34 | "updated": "2013-07-23T11:33:21Z", 35 | "id": "v3.0", 36 | "links": [ 37 | { 38 | "href": "http://127.0.0.1:8774/v3/", 39 | "rel": "self" 40 | } 41 | ] 42 | } 43 | ] 44 | } 45 | '300': 46 | description: |- 47 | 300 response 48 | content: 49 | application/json: 50 | examples: 51 | foo: 52 | value: | 53 | { 54 | "versions": [ 55 | { 56 | "status": "CURRENT", 57 | "updated": "2011-01-21T11:33:21Z", 58 | "id": "v2.0", 59 | "links": [ 60 | { 61 | "href": "http://127.0.0.1:8774/v2/", 62 | "rel": "self" 63 | } 64 | ] 65 | }, 66 | { 67 | "status": "EXPERIMENTAL", 68 | "updated": "2013-07-23T11:33:21Z", 69 | "id": "v3.0", 70 | "links": [ 71 | { 72 | "href": "http://127.0.0.1:8774/v3/", 73 | "rel": "self" 74 | } 75 | ] 76 | } 77 | ] 78 | } 79 | /v2: 80 | get: 81 | operationId: getVersionDetailsv2 82 | summary: Show API version details 83 | responses: 84 | '200': 85 | description: |- 86 | 200 response 87 | content: 88 | application/json: 89 | examples: 90 | foo: 91 | value: 92 | { 93 | "version": { 94 | "status": "CURRENT", 95 | "updated": "2011-01-21T11:33:21Z", 96 | "media-types": [ 97 | { 98 | "base": "application/xml", 99 | "type": "application/vnd.openstack.compute+xml;version=2" 100 | }, 101 | { 102 | "base": "application/json", 103 | "type": "application/vnd.openstack.compute+json;version=2" 104 | } 105 | ], 106 | "id": "v2.0", 107 | "links": [ 108 | { 109 | "href": "http://127.0.0.1:8774/v2/", 110 | "rel": "self" 111 | }, 112 | { 113 | "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", 114 | "type": "application/pdf", 115 | "rel": "describedby" 116 | }, 117 | { 118 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 119 | "type": "application/vnd.sun.wadl+xml", 120 | "rel": "describedby" 121 | }, 122 | { 123 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 124 | "type": "application/vnd.sun.wadl+xml", 125 | "rel": "describedby" 126 | } 127 | ] 128 | } 129 | } 130 | '203': 131 | description: |- 132 | 203 response 133 | content: 134 | application/json: 135 | examples: 136 | foo: 137 | value: 138 | { 139 | "version": { 140 | "status": "CURRENT", 141 | "updated": "2011-01-21T11:33:21Z", 142 | "media-types": [ 143 | { 144 | "base": "application/xml", 145 | "type": "application/vnd.openstack.compute+xml;version=2" 146 | }, 147 | { 148 | "base": "application/json", 149 | "type": "application/vnd.openstack.compute+json;version=2" 150 | } 151 | ], 152 | "id": "v2.0", 153 | "links": [ 154 | { 155 | "href": "http://23.253.228.211:8774/v2/", 156 | "rel": "self" 157 | }, 158 | { 159 | "href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf", 160 | "type": "application/pdf", 161 | "rel": "describedby" 162 | }, 163 | { 164 | "href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl", 165 | "type": "application/vnd.sun.wadl+xml", 166 | "rel": "describedby" 167 | } 168 | ] 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /examples/v3.0/callback-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.0", 3 | "info": { 4 | "title": "Callback Example", 5 | "version": "1.0.0" 6 | }, 7 | "paths": { 8 | "/streams": { 9 | "post": { 10 | "description": "subscribes a client to receive out-of-band data", 11 | "parameters": [ 12 | { 13 | "name": "callbackUrl", 14 | "in": "query", 15 | "required": true, 16 | "description": "the location where data will be sent. Must be network accessible\nby the source server\n", 17 | "schema": { 18 | "type": "string", 19 | "format": "uri", 20 | "example": "https://tonys-server.com" 21 | } 22 | } 23 | ], 24 | "responses": { 25 | "201": { 26 | "description": "subscription successfully created", 27 | "content": { 28 | "application/json": { 29 | "schema": { 30 | "description": "subscription information", 31 | "required": [ 32 | "subscriptionId" 33 | ], 34 | "properties": { 35 | "subscriptionId": { 36 | "description": "this unique identifier allows management of the subscription", 37 | "type": "string", 38 | "example": "2531329f-fb09-4ef7-887e-84e648214436" 39 | } 40 | } 41 | } 42 | } 43 | } 44 | } 45 | }, 46 | "callbacks": { 47 | "onData": { 48 | "{$request.query.callbackUrl}/data": { 49 | "post": { 50 | "requestBody": { 51 | "description": "subscription payload", 52 | "content": { 53 | "application/json": { 54 | "schema": { 55 | "type": "object", 56 | "properties": { 57 | "timestamp": { 58 | "type": "string", 59 | "format": "date-time" 60 | }, 61 | "userData": { 62 | "type": "string" 63 | } 64 | } 65 | } 66 | } 67 | } 68 | }, 69 | "responses": { 70 | "202": { 71 | "description": "Your server implementation should return this HTTP status code\nif the data was received successfully\n" 72 | }, 73 | "204": { 74 | "description": "Your server should return this HTTP status code if no longer interested\nin further updates\n" 75 | } 76 | } 77 | } 78 | } 79 | } 80 | } 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /examples/v3.0/callback-example.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | title: Callback Example 4 | version: 1.0.0 5 | paths: 6 | /streams: 7 | post: 8 | description: subscribes a client to receive out-of-band data 9 | parameters: 10 | - name: callbackUrl 11 | in: query 12 | required: true 13 | description: | 14 | the location where data will be sent. Must be network accessible 15 | by the source server 16 | schema: 17 | type: string 18 | format: uri 19 | example: https://tonys-server.com 20 | responses: 21 | '201': 22 | description: subscription successfully created 23 | content: 24 | application/json: 25 | schema: 26 | description: subscription information 27 | required: 28 | - subscriptionId 29 | properties: 30 | subscriptionId: 31 | description: this unique identifier allows management of the subscription 32 | type: string 33 | example: 2531329f-fb09-4ef7-887e-84e648214436 34 | callbacks: 35 | # the name `onData` is a convenience locator 36 | onData: 37 | # when data is sent, it will be sent to the `callbackUrl` provided 38 | # when making the subscription PLUS the suffix `/data` 39 | '{$request.query.callbackUrl}/data': 40 | post: 41 | requestBody: 42 | description: subscription payload 43 | content: 44 | application/json: 45 | schema: 46 | type: object 47 | properties: 48 | timestamp: 49 | type: string 50 | format: date-time 51 | userData: 52 | type: string 53 | responses: 54 | '202': 55 | description: | 56 | Your server implementation should return this HTTP status code 57 | if the data was received successfully 58 | '204': 59 | description: | 60 | Your server should return this HTTP status code if no longer interested 61 | in further updates 62 | -------------------------------------------------------------------------------- /examples/v3.0/link-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.0", 3 | "info": { 4 | "title": "Link Example", 5 | "version": "1.0.0" 6 | }, 7 | "paths": { 8 | "/2.0/users/{username}": { 9 | "get": { 10 | "operationId": "getUserByName", 11 | "parameters": [ 12 | { 13 | "name": "username", 14 | "in": "path", 15 | "required": true, 16 | "schema": { 17 | "type": "string" 18 | } 19 | } 20 | ], 21 | "responses": { 22 | "200": { 23 | "description": "The User", 24 | "content": { 25 | "application/json": { 26 | "schema": { 27 | "$ref": "#/components/schemas/user" 28 | } 29 | } 30 | }, 31 | "links": { 32 | "userRepositories": { 33 | "$ref": "#/components/links/UserRepositories" 34 | } 35 | } 36 | } 37 | } 38 | } 39 | }, 40 | "/2.0/repositories/{username}": { 41 | "get": { 42 | "operationId": "getRepositoriesByOwner", 43 | "parameters": [ 44 | { 45 | "name": "username", 46 | "in": "path", 47 | "required": true, 48 | "schema": { 49 | "type": "string" 50 | } 51 | } 52 | ], 53 | "responses": { 54 | "200": { 55 | "description": "repositories owned by the supplied user", 56 | "content": { 57 | "application/json": { 58 | "schema": { 59 | "type": "array", 60 | "items": { 61 | "$ref": "#/components/schemas/repository" 62 | } 63 | } 64 | } 65 | }, 66 | "links": { 67 | "userRepository": { 68 | "$ref": "#/components/links/UserRepository" 69 | } 70 | } 71 | } 72 | } 73 | } 74 | }, 75 | "/2.0/repositories/{username}/{slug}": { 76 | "get": { 77 | "operationId": "getRepository", 78 | "parameters": [ 79 | { 80 | "name": "username", 81 | "in": "path", 82 | "required": true, 83 | "schema": { 84 | "type": "string" 85 | } 86 | }, 87 | { 88 | "name": "slug", 89 | "in": "path", 90 | "required": true, 91 | "schema": { 92 | "type": "string" 93 | } 94 | } 95 | ], 96 | "responses": { 97 | "200": { 98 | "description": "The repository", 99 | "content": { 100 | "application/json": { 101 | "schema": { 102 | "$ref": "#/components/schemas/repository" 103 | } 104 | } 105 | }, 106 | "links": { 107 | "repositoryPullRequests": { 108 | "$ref": "#/components/links/RepositoryPullRequests" 109 | } 110 | } 111 | } 112 | } 113 | } 114 | }, 115 | "/2.0/repositories/{username}/{slug}/pullrequests": { 116 | "get": { 117 | "operationId": "getPullRequestsByRepository", 118 | "parameters": [ 119 | { 120 | "name": "username", 121 | "in": "path", 122 | "required": true, 123 | "schema": { 124 | "type": "string" 125 | } 126 | }, 127 | { 128 | "name": "slug", 129 | "in": "path", 130 | "required": true, 131 | "schema": { 132 | "type": "string" 133 | } 134 | }, 135 | { 136 | "name": "state", 137 | "in": "query", 138 | "schema": { 139 | "type": "string", 140 | "enum": [ 141 | "open", 142 | "merged", 143 | "declined" 144 | ] 145 | } 146 | } 147 | ], 148 | "responses": { 149 | "200": { 150 | "description": "an array of pull request objects", 151 | "content": { 152 | "application/json": { 153 | "schema": { 154 | "type": "array", 155 | "items": { 156 | "$ref": "#/components/schemas/pullrequest" 157 | } 158 | } 159 | } 160 | } 161 | } 162 | } 163 | } 164 | }, 165 | "/2.0/repositories/{username}/{slug}/pullrequests/{pid}": { 166 | "get": { 167 | "operationId": "getPullRequestsById", 168 | "parameters": [ 169 | { 170 | "name": "username", 171 | "in": "path", 172 | "required": true, 173 | "schema": { 174 | "type": "string" 175 | } 176 | }, 177 | { 178 | "name": "slug", 179 | "in": "path", 180 | "required": true, 181 | "schema": { 182 | "type": "string" 183 | } 184 | }, 185 | { 186 | "name": "pid", 187 | "in": "path", 188 | "required": true, 189 | "schema": { 190 | "type": "string" 191 | } 192 | } 193 | ], 194 | "responses": { 195 | "200": { 196 | "description": "a pull request object", 197 | "content": { 198 | "application/json": { 199 | "schema": { 200 | "$ref": "#/components/schemas/pullrequest" 201 | } 202 | } 203 | }, 204 | "links": { 205 | "pullRequestMerge": { 206 | "$ref": "#/components/links/PullRequestMerge" 207 | } 208 | } 209 | } 210 | } 211 | } 212 | }, 213 | "/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge": { 214 | "post": { 215 | "operationId": "mergePullRequest", 216 | "parameters": [ 217 | { 218 | "name": "username", 219 | "in": "path", 220 | "required": true, 221 | "schema": { 222 | "type": "string" 223 | } 224 | }, 225 | { 226 | "name": "slug", 227 | "in": "path", 228 | "required": true, 229 | "schema": { 230 | "type": "string" 231 | } 232 | }, 233 | { 234 | "name": "pid", 235 | "in": "path", 236 | "required": true, 237 | "schema": { 238 | "type": "string" 239 | } 240 | } 241 | ], 242 | "responses": { 243 | "204": { 244 | "description": "the PR was successfully merged" 245 | } 246 | } 247 | } 248 | } 249 | }, 250 | "components": { 251 | "links": { 252 | "UserRepositories": { 253 | "operationId": "getRepositoriesByOwner", 254 | "parameters": { 255 | "username": "$response.body#/username" 256 | } 257 | }, 258 | "UserRepository": { 259 | "operationId": "getRepository", 260 | "parameters": { 261 | "username": "$response.body#/owner/username", 262 | "slug": "$response.body#/slug" 263 | } 264 | }, 265 | "RepositoryPullRequests": { 266 | "operationId": "getPullRequestsByRepository", 267 | "parameters": { 268 | "username": "$response.body#/owner/username", 269 | "slug": "$response.body#/slug" 270 | } 271 | }, 272 | "PullRequestMerge": { 273 | "operationId": "mergePullRequest", 274 | "parameters": { 275 | "username": "$response.body#/author/username", 276 | "slug": "$response.body#/repository/slug", 277 | "pid": "$response.body#/id" 278 | } 279 | } 280 | }, 281 | "schemas": { 282 | "user": { 283 | "type": "object", 284 | "properties": { 285 | "username": { 286 | "type": "string" 287 | }, 288 | "uuid": { 289 | "type": "string" 290 | } 291 | } 292 | }, 293 | "repository": { 294 | "type": "object", 295 | "properties": { 296 | "slug": { 297 | "type": "string" 298 | }, 299 | "owner": { 300 | "$ref": "#/components/schemas/user" 301 | } 302 | } 303 | }, 304 | "pullrequest": { 305 | "type": "object", 306 | "properties": { 307 | "id": { 308 | "type": "integer" 309 | }, 310 | "title": { 311 | "type": "string" 312 | }, 313 | "repository": { 314 | "$ref": "#/components/schemas/repository" 315 | }, 316 | "author": { 317 | "$ref": "#/components/schemas/user" 318 | } 319 | } 320 | } 321 | } 322 | } 323 | } -------------------------------------------------------------------------------- /examples/v3.0/link-example.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | info: 3 | title: Link Example 4 | version: 1.0.0 5 | paths: 6 | /2.0/users/{username}: 7 | get: 8 | operationId: getUserByName 9 | parameters: 10 | - name: username 11 | in: path 12 | required: true 13 | schema: 14 | type: string 15 | responses: 16 | '200': 17 | description: The User 18 | content: 19 | application/json: 20 | schema: 21 | $ref: '#/components/schemas/user' 22 | links: 23 | userRepositories: 24 | $ref: '#/components/links/UserRepositories' 25 | /2.0/repositories/{username}: 26 | get: 27 | operationId: getRepositoriesByOwner 28 | parameters: 29 | - name: username 30 | in: path 31 | required: true 32 | schema: 33 | type: string 34 | responses: 35 | '200': 36 | description: repositories owned by the supplied user 37 | content: 38 | application/json: 39 | schema: 40 | type: array 41 | items: 42 | $ref: '#/components/schemas/repository' 43 | links: 44 | userRepository: 45 | $ref: '#/components/links/UserRepository' 46 | /2.0/repositories/{username}/{slug}: 47 | get: 48 | operationId: getRepository 49 | parameters: 50 | - name: username 51 | in: path 52 | required: true 53 | schema: 54 | type: string 55 | - name: slug 56 | in: path 57 | required: true 58 | schema: 59 | type: string 60 | responses: 61 | '200': 62 | description: The repository 63 | content: 64 | application/json: 65 | schema: 66 | $ref: '#/components/schemas/repository' 67 | links: 68 | repositoryPullRequests: 69 | $ref: '#/components/links/RepositoryPullRequests' 70 | /2.0/repositories/{username}/{slug}/pullrequests: 71 | get: 72 | operationId: getPullRequestsByRepository 73 | parameters: 74 | - name: username 75 | in: path 76 | required: true 77 | schema: 78 | type: string 79 | - name: slug 80 | in: path 81 | required: true 82 | schema: 83 | type: string 84 | - name: state 85 | in: query 86 | schema: 87 | type: string 88 | enum: 89 | - open 90 | - merged 91 | - declined 92 | responses: 93 | '200': 94 | description: an array of pull request objects 95 | content: 96 | application/json: 97 | schema: 98 | type: array 99 | items: 100 | $ref: '#/components/schemas/pullrequest' 101 | /2.0/repositories/{username}/{slug}/pullrequests/{pid}: 102 | get: 103 | operationId: getPullRequestsById 104 | parameters: 105 | - name: username 106 | in: path 107 | required: true 108 | schema: 109 | type: string 110 | - name: slug 111 | in: path 112 | required: true 113 | schema: 114 | type: string 115 | - name: pid 116 | in: path 117 | required: true 118 | schema: 119 | type: string 120 | responses: 121 | '200': 122 | description: a pull request object 123 | content: 124 | application/json: 125 | schema: 126 | $ref: '#/components/schemas/pullrequest' 127 | links: 128 | pullRequestMerge: 129 | $ref: '#/components/links/PullRequestMerge' 130 | /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge: 131 | post: 132 | operationId: mergePullRequest 133 | parameters: 134 | - name: username 135 | in: path 136 | required: true 137 | schema: 138 | type: string 139 | - name: slug 140 | in: path 141 | required: true 142 | schema: 143 | type: string 144 | - name: pid 145 | in: path 146 | required: true 147 | schema: 148 | type: string 149 | responses: 150 | '204': 151 | description: the PR was successfully merged 152 | components: 153 | links: 154 | UserRepositories: 155 | # returns array of '#/components/schemas/repository' 156 | operationId: getRepositoriesByOwner 157 | parameters: 158 | username: $response.body#/username 159 | UserRepository: 160 | # returns '#/components/schemas/repository' 161 | operationId: getRepository 162 | parameters: 163 | username: $response.body#/owner/username 164 | slug: $response.body#/slug 165 | RepositoryPullRequests: 166 | # returns '#/components/schemas/pullrequest' 167 | operationId: getPullRequestsByRepository 168 | parameters: 169 | username: $response.body#/owner/username 170 | slug: $response.body#/slug 171 | PullRequestMerge: 172 | # executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge 173 | operationId: mergePullRequest 174 | parameters: 175 | username: $response.body#/author/username 176 | slug: $response.body#/repository/slug 177 | pid: $response.body#/id 178 | schemas: 179 | user: 180 | type: object 181 | properties: 182 | username: 183 | type: string 184 | uuid: 185 | type: string 186 | repository: 187 | type: object 188 | properties: 189 | slug: 190 | type: string 191 | owner: 192 | $ref: '#/components/schemas/user' 193 | pullrequest: 194 | type: object 195 | properties: 196 | id: 197 | type: integer 198 | title: 199 | type: string 200 | repository: 201 | $ref: '#/components/schemas/repository' 202 | author: 203 | $ref: '#/components/schemas/user' 204 | -------------------------------------------------------------------------------- /examples/v3.0/petstore-expanded.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification", 7 | "termsOfService": "http://swagger.io/terms/", 8 | "contact": { 9 | "name": "Swagger API Team", 10 | "email": "apiteam@swagger.io", 11 | "url": "http://swagger.io" 12 | }, 13 | "license": { 14 | "name": "Apache 2.0", 15 | "url": "https://www.apache.org/licenses/LICENSE-2.0.html" 16 | } 17 | }, 18 | "servers": [ 19 | { 20 | "url": "http://petstore.swagger.io/api" 21 | } 22 | ], 23 | "paths": { 24 | "/pets": { 25 | "get": { 26 | "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", 27 | "operationId": "findPets", 28 | "parameters": [ 29 | { 30 | "name": "tags", 31 | "in": "query", 32 | "description": "tags to filter by", 33 | "required": false, 34 | "style": "form", 35 | "schema": { 36 | "type": "array", 37 | "items": { 38 | "type": "string" 39 | } 40 | } 41 | }, 42 | { 43 | "name": "limit", 44 | "in": "query", 45 | "description": "maximum number of results to return", 46 | "required": false, 47 | "schema": { 48 | "type": "integer", 49 | "format": "int32" 50 | } 51 | } 52 | ], 53 | "responses": { 54 | "200": { 55 | "description": "pet response", 56 | "content": { 57 | "application/json": { 58 | "schema": { 59 | "type": "array", 60 | "items": { 61 | "$ref": "#/components/schemas/Pet" 62 | } 63 | } 64 | } 65 | } 66 | }, 67 | "default": { 68 | "description": "unexpected error", 69 | "content": { 70 | "application/json": { 71 | "schema": { 72 | "$ref": "#/components/schemas/Error" 73 | } 74 | } 75 | } 76 | } 77 | } 78 | }, 79 | "post": { 80 | "description": "Creates a new pet in the store. Duplicates are allowed", 81 | "operationId": "addPet", 82 | "requestBody": { 83 | "description": "Pet to add to the store", 84 | "required": true, 85 | "content": { 86 | "application/json": { 87 | "schema": { 88 | "$ref": "#/components/schemas/NewPet" 89 | } 90 | } 91 | } 92 | }, 93 | "responses": { 94 | "200": { 95 | "description": "pet response", 96 | "content": { 97 | "application/json": { 98 | "schema": { 99 | "$ref": "#/components/schemas/Pet" 100 | } 101 | } 102 | } 103 | }, 104 | "default": { 105 | "description": "unexpected error", 106 | "content": { 107 | "application/json": { 108 | "schema": { 109 | "$ref": "#/components/schemas/Error" 110 | } 111 | } 112 | } 113 | } 114 | } 115 | } 116 | }, 117 | "/pets/{id}": { 118 | "get": { 119 | "description": "Returns a user based on a single ID, if the user does not have access to the pet", 120 | "operationId": "find pet by id", 121 | "parameters": [ 122 | { 123 | "name": "id", 124 | "in": "path", 125 | "description": "ID of pet to fetch", 126 | "required": true, 127 | "schema": { 128 | "type": "integer", 129 | "format": "int64" 130 | } 131 | } 132 | ], 133 | "responses": { 134 | "200": { 135 | "description": "pet response", 136 | "content": { 137 | "application/json": { 138 | "schema": { 139 | "$ref": "#/components/schemas/Pet" 140 | } 141 | } 142 | } 143 | }, 144 | "default": { 145 | "description": "unexpected error", 146 | "content": { 147 | "application/json": { 148 | "schema": { 149 | "$ref": "#/components/schemas/Error" 150 | } 151 | } 152 | } 153 | } 154 | } 155 | }, 156 | "delete": { 157 | "description": "deletes a single pet based on the ID supplied", 158 | "operationId": "deletePet", 159 | "parameters": [ 160 | { 161 | "name": "id", 162 | "in": "path", 163 | "description": "ID of pet to delete", 164 | "required": true, 165 | "schema": { 166 | "type": "integer", 167 | "format": "int64" 168 | } 169 | } 170 | ], 171 | "responses": { 172 | "204": { 173 | "description": "pet deleted" 174 | }, 175 | "default": { 176 | "description": "unexpected error", 177 | "content": { 178 | "application/json": { 179 | "schema": { 180 | "$ref": "#/components/schemas/Error" 181 | } 182 | } 183 | } 184 | } 185 | } 186 | } 187 | } 188 | }, 189 | "components": { 190 | "schemas": { 191 | "Pet": { 192 | "allOf": [ 193 | { 194 | "$ref": "#/components/schemas/NewPet" 195 | }, 196 | { 197 | "type": "object", 198 | "required": [ 199 | "id" 200 | ], 201 | "properties": { 202 | "id": { 203 | "type": "integer", 204 | "format": "int64" 205 | } 206 | } 207 | } 208 | ] 209 | }, 210 | "NewPet": { 211 | "type": "object", 212 | "required": [ 213 | "name" 214 | ], 215 | "properties": { 216 | "name": { 217 | "type": "string" 218 | }, 219 | "tag": { 220 | "type": "string" 221 | } 222 | } 223 | }, 224 | "Error": { 225 | "type": "object", 226 | "required": [ 227 | "code", 228 | "message" 229 | ], 230 | "properties": { 231 | "code": { 232 | "type": "integer", 233 | "format": "int32" 234 | }, 235 | "message": { 236 | "type": "string" 237 | } 238 | } 239 | } 240 | } 241 | } 242 | } -------------------------------------------------------------------------------- /examples/v3.0/petstore-expanded.yaml: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | version: 1.0.0 4 | title: Swagger Petstore 5 | description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification 6 | termsOfService: http://swagger.io/terms/ 7 | contact: 8 | name: Swagger API Team 9 | email: apiteam@swagger.io 10 | url: http://swagger.io 11 | license: 12 | name: Apache 2.0 13 | url: https://www.apache.org/licenses/LICENSE-2.0.html 14 | servers: 15 | - url: http://petstore.swagger.io/api 16 | paths: 17 | /pets: 18 | get: 19 | description: | 20 | Returns all pets from the system that the user has access to 21 | Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. 22 | 23 | Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. 24 | operationId: findPets 25 | parameters: 26 | - name: tags 27 | in: query 28 | description: tags to filter by 29 | required: false 30 | style: form 31 | schema: 32 | type: array 33 | items: 34 | type: string 35 | - name: limit 36 | in: query 37 | description: maximum number of results to return 38 | required: false 39 | schema: 40 | type: integer 41 | format: int32 42 | responses: 43 | '200': 44 | description: pet response 45 | content: 46 | application/json: 47 | schema: 48 | type: array 49 | items: 50 | $ref: '#/components/schemas/Pet' 51 | default: 52 | description: unexpected error 53 | content: 54 | application/json: 55 | schema: 56 | $ref: '#/components/schemas/Error' 57 | post: 58 | description: Creates a new pet in the store. Duplicates are allowed 59 | operationId: addPet 60 | requestBody: 61 | description: Pet to add to the store 62 | required: true 63 | content: 64 | application/json: 65 | schema: 66 | $ref: '#/components/schemas/NewPet' 67 | responses: 68 | '200': 69 | description: pet response 70 | content: 71 | application/json: 72 | schema: 73 | $ref: '#/components/schemas/Pet' 74 | default: 75 | description: unexpected error 76 | content: 77 | application/json: 78 | schema: 79 | $ref: '#/components/schemas/Error' 80 | /pets/{id}: 81 | get: 82 | description: Returns a user based on a single ID, if the user does not have access to the pet 83 | operationId: find pet by id 84 | parameters: 85 | - name: id 86 | in: path 87 | description: ID of pet to fetch 88 | required: true 89 | schema: 90 | type: integer 91 | format: int64 92 | responses: 93 | '200': 94 | description: pet response 95 | content: 96 | application/json: 97 | schema: 98 | $ref: '#/components/schemas/Pet' 99 | default: 100 | description: unexpected error 101 | content: 102 | application/json: 103 | schema: 104 | $ref: '#/components/schemas/Error' 105 | delete: 106 | description: deletes a single pet based on the ID supplied 107 | operationId: deletePet 108 | parameters: 109 | - name: id 110 | in: path 111 | description: ID of pet to delete 112 | required: true 113 | schema: 114 | type: integer 115 | format: int64 116 | responses: 117 | '204': 118 | description: pet deleted 119 | default: 120 | description: unexpected error 121 | content: 122 | application/json: 123 | schema: 124 | $ref: '#/components/schemas/Error' 125 | components: 126 | schemas: 127 | Pet: 128 | allOf: 129 | - $ref: '#/components/schemas/NewPet' 130 | - type: object 131 | required: 132 | - id 133 | properties: 134 | id: 135 | type: integer 136 | format: int64 137 | 138 | NewPet: 139 | type: object 140 | required: 141 | - name 142 | properties: 143 | name: 144 | type: string 145 | tag: 146 | type: string 147 | 148 | Error: 149 | type: object 150 | required: 151 | - code 152 | - message 153 | properties: 154 | code: 155 | type: integer 156 | format: int32 157 | message: 158 | type: string 159 | -------------------------------------------------------------------------------- /examples/v3.0/petstore.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.0", 3 | "info": { 4 | "version": "1.0.0", 5 | "title": "Swagger Petstore", 6 | "license": { 7 | "name": "MIT" 8 | } 9 | }, 10 | "servers": [ 11 | { 12 | "url": "http://petstore.swagger.io/v1" 13 | } 14 | ], 15 | "paths": { 16 | "/pets": { 17 | "get": { 18 | "summary": "List all pets", 19 | "operationId": "listPets", 20 | "tags": [ 21 | "pets" 22 | ], 23 | "parameters": [ 24 | { 25 | "name": "limit", 26 | "in": "query", 27 | "description": "How many items to return at one time (max 100)", 28 | "required": false, 29 | "schema": { 30 | "type": "integer", 31 | "format": "int32" 32 | } 33 | } 34 | ], 35 | "responses": { 36 | "200": { 37 | "description": "A paged array of pets", 38 | "headers": { 39 | "x-next": { 40 | "description": "A link to the next page of responses", 41 | "schema": { 42 | "type": "string" 43 | } 44 | } 45 | }, 46 | "content": { 47 | "application/json": { 48 | "schema": { 49 | "$ref": "#/components/schemas/Pets" 50 | } 51 | } 52 | } 53 | }, 54 | "default": { 55 | "description": "unexpected error", 56 | "content": { 57 | "application/json": { 58 | "schema": { 59 | "$ref": "#/components/schemas/Error" 60 | } 61 | } 62 | } 63 | } 64 | } 65 | }, 66 | "post": { 67 | "summary": "Create a pet", 68 | "operationId": "createPets", 69 | "tags": [ 70 | "pets" 71 | ], 72 | "responses": { 73 | "201": { 74 | "description": "Null response" 75 | }, 76 | "default": { 77 | "description": "unexpected error", 78 | "content": { 79 | "application/json": { 80 | "schema": { 81 | "$ref": "#/components/schemas/Error" 82 | } 83 | } 84 | } 85 | } 86 | } 87 | } 88 | }, 89 | "/pets/{petId}": { 90 | "get": { 91 | "summary": "Info for a specific pet", 92 | "operationId": "showPetById", 93 | "tags": [ 94 | "pets" 95 | ], 96 | "parameters": [ 97 | { 98 | "name": "petId", 99 | "in": "path", 100 | "required": true, 101 | "description": "The id of the pet to retrieve", 102 | "schema": { 103 | "type": "string" 104 | } 105 | } 106 | ], 107 | "responses": { 108 | "200": { 109 | "description": "Expected response to a valid request", 110 | "content": { 111 | "application/json": { 112 | "schema": { 113 | "$ref": "#/components/schemas/Pet" 114 | } 115 | } 116 | } 117 | }, 118 | "default": { 119 | "description": "unexpected error", 120 | "content": { 121 | "application/json": { 122 | "schema": { 123 | "$ref": "#/components/schemas/Error" 124 | } 125 | } 126 | } 127 | } 128 | } 129 | } 130 | } 131 | }, 132 | "components": { 133 | "schemas": { 134 | "Pet": { 135 | "type": "object", 136 | "required": [ 137 | "id", 138 | "name" 139 | ], 140 | "properties": { 141 | "id": { 142 | "type": "integer", 143 | "format": "int64" 144 | }, 145 | "name": { 146 | "type": "string" 147 | }, 148 | "tag": { 149 | "type": "string" 150 | } 151 | } 152 | }, 153 | "Pets": { 154 | "type": "array", 155 | "items": { 156 | "$ref": "#/components/schemas/Pet" 157 | } 158 | }, 159 | "Error": { 160 | "type": "object", 161 | "required": [ 162 | "code", 163 | "message" 164 | ], 165 | "properties": { 166 | "code": { 167 | "type": "integer", 168 | "format": "int32" 169 | }, 170 | "message": { 171 | "type": "string" 172 | } 173 | } 174 | } 175 | } 176 | } 177 | } -------------------------------------------------------------------------------- /examples/v3.0/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 | format: int32 24 | responses: 25 | '200': 26 | description: A 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: "#/components/schemas/Pets" 36 | default: 37 | description: unexpected error 38 | content: 39 | application/json: 40 | schema: 41 | $ref: "#/components/schemas/Error" 42 | post: 43 | summary: Create a pet 44 | operationId: createPets 45 | tags: 46 | - pets 47 | responses: 48 | '201': 49 | description: Null response 50 | default: 51 | description: unexpected error 52 | content: 53 | application/json: 54 | schema: 55 | $ref: "#/components/schemas/Error" 56 | /pets/{petId}: 57 | get: 58 | summary: Info for a specific pet 59 | operationId: showPetById 60 | tags: 61 | - pets 62 | parameters: 63 | - name: petId 64 | in: path 65 | required: true 66 | description: The id of the pet to retrieve 67 | schema: 68 | type: string 69 | responses: 70 | '200': 71 | description: Expected response to a valid request 72 | content: 73 | application/json: 74 | schema: 75 | $ref: "#/components/schemas/Pet" 76 | default: 77 | description: unexpected error 78 | content: 79 | application/json: 80 | schema: 81 | $ref: "#/components/schemas/Error" 82 | components: 83 | schemas: 84 | Pet: 85 | type: object 86 | required: 87 | - id 88 | - name 89 | properties: 90 | id: 91 | type: integer 92 | format: int64 93 | name: 94 | type: string 95 | tag: 96 | type: string 97 | Pets: 98 | type: array 99 | items: 100 | $ref: "#/components/schemas/Pet" 101 | Error: 102 | type: object 103 | required: 104 | - code 105 | - message 106 | properties: 107 | code: 108 | type: integer 109 | format: int32 110 | message: 111 | type: string 112 | -------------------------------------------------------------------------------- /examples/v3.0/uspto.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.1 2 | servers: 3 | - url: '{scheme}://developer.uspto.gov/ds-api' 4 | variables: 5 | scheme: 6 | description: 'The Data Set API is accessible via https and http' 7 | enum: 8 | - 'https' 9 | - 'http' 10 | default: 'https' 11 | info: 12 | description: >- 13 | The Data Set API (DSAPI) allows the public users to discover and search 14 | USPTO exported data sets. This is a generic API that allows USPTO users to 15 | make any CSV based data files searchable through API. With the help of GET 16 | call, it returns the list of data fields that are searchable. With the help 17 | of POST call, data can be fetched based on the filters on the field names. 18 | Please note that POST call is used to search the actual data. The reason for 19 | the POST call is that it allows users to specify any complex search criteria 20 | without worry about the GET size limitations as well as encoding of the 21 | input parameters. 22 | version: 1.0.0 23 | title: USPTO Data Set API 24 | contact: 25 | name: Open Data Portal 26 | url: 'https://developer.uspto.gov' 27 | email: developer@uspto.gov 28 | tags: 29 | - name: metadata 30 | description: Find out about the data sets 31 | - name: search 32 | description: Search a data set 33 | paths: 34 | /: 35 | get: 36 | tags: 37 | - metadata 38 | operationId: list-data-sets 39 | summary: List available data sets 40 | responses: 41 | '200': 42 | description: Returns a list of data sets 43 | content: 44 | application/json: 45 | schema: 46 | $ref: '#/components/schemas/dataSetList' 47 | example: 48 | { 49 | "total": 2, 50 | "apis": [ 51 | { 52 | "apiKey": "oa_citations", 53 | "apiVersionNumber": "v1", 54 | "apiUrl": "https://developer.uspto.gov/ds-api/oa_citations/v1/fields", 55 | "apiDocumentationUrl": "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/oa_citations.json" 56 | }, 57 | { 58 | "apiKey": "cancer_moonshot", 59 | "apiVersionNumber": "v1", 60 | "apiUrl": "https://developer.uspto.gov/ds-api/cancer_moonshot/v1/fields", 61 | "apiDocumentationUrl": "https://developer.uspto.gov/ds-api-docs/index.html?url=https://developer.uspto.gov/ds-api/swagger/docs/cancer_moonshot.json" 62 | } 63 | ] 64 | } 65 | /{dataset}/{version}/fields: 66 | get: 67 | tags: 68 | - metadata 69 | summary: >- 70 | Provides the general information about the API and the list of fields 71 | that can be used to query the dataset. 72 | description: >- 73 | This GET API returns the list of all the searchable field names that are 74 | in the oa_citations. Please see the 'fields' attribute which returns an 75 | array of field names. Each field or a combination of fields can be 76 | searched using the syntax options shown below. 77 | operationId: list-searchable-fields 78 | parameters: 79 | - name: dataset 80 | in: path 81 | description: 'Name of the dataset.' 82 | required: true 83 | example: "oa_citations" 84 | schema: 85 | type: string 86 | - name: version 87 | in: path 88 | description: Version of the dataset. 89 | required: true 90 | example: "v1" 91 | schema: 92 | type: string 93 | responses: 94 | '200': 95 | description: >- 96 | The dataset API for the given version is found and it is accessible 97 | to consume. 98 | content: 99 | application/json: 100 | schema: 101 | type: string 102 | '404': 103 | description: >- 104 | The combination of dataset name and version is not found in the 105 | system or it is not published yet to be consumed by public. 106 | content: 107 | application/json: 108 | schema: 109 | type: string 110 | /{dataset}/{version}/records: 111 | post: 112 | tags: 113 | - search 114 | summary: >- 115 | Provides search capability for the data set with the given search 116 | criteria. 117 | description: >- 118 | This API is based on Solr/Lucene Search. The data is indexed using 119 | SOLR. This GET API returns the list of all the searchable field names 120 | that are in the Solr Index. Please see the 'fields' attribute which 121 | returns an array of field names. Each field or a combination of fields 122 | can be searched using the Solr/Lucene Syntax. Please refer 123 | https://lucene.apache.org/core/3_6_2/queryparsersyntax.html#Overview for 124 | the query syntax. List of field names that are searchable can be 125 | determined using above GET api. 126 | operationId: perform-search 127 | parameters: 128 | - name: version 129 | in: path 130 | description: Version of the dataset. 131 | required: true 132 | schema: 133 | type: string 134 | default: v1 135 | - name: dataset 136 | in: path 137 | description: 'Name of the dataset. In this case, the default value is oa_citations' 138 | required: true 139 | schema: 140 | type: string 141 | default: oa_citations 142 | responses: 143 | '200': 144 | description: successful operation 145 | content: 146 | application/json: 147 | schema: 148 | type: array 149 | items: 150 | type: object 151 | additionalProperties: 152 | type: object 153 | '404': 154 | description: No matching record found for the given criteria. 155 | requestBody: 156 | content: 157 | application/x-www-form-urlencoded: 158 | schema: 159 | type: object 160 | properties: 161 | criteria: 162 | description: >- 163 | Uses Lucene Query Syntax in the format of 164 | propertyName:value, propertyName:[num1 TO num2] and date 165 | range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the 166 | response please see the 'docs' element which has the list of 167 | record objects. Each record structure would consist of all 168 | the fields and their corresponding values. 169 | type: string 170 | default: '*:*' 171 | start: 172 | description: Starting record number. Default value is 0. 173 | type: integer 174 | default: 0 175 | rows: 176 | description: >- 177 | Specify number of rows to be returned. If you run the search 178 | with default values, in the response you will see 'numFound' 179 | attribute which will tell the number of records available in 180 | the dataset. 181 | type: integer 182 | default: 100 183 | required: 184 | - criteria 185 | components: 186 | schemas: 187 | dataSetList: 188 | type: object 189 | properties: 190 | total: 191 | type: integer 192 | apis: 193 | type: array 194 | items: 195 | type: object 196 | properties: 197 | apiKey: 198 | type: string 199 | description: To be used as a dataset parameter value 200 | apiVersionNumber: 201 | type: string 202 | description: To be used as a version parameter value 203 | apiUrl: 204 | type: string 205 | format: uriref 206 | description: "The URL describing the dataset's fields" 207 | apiDocumentationUrl: 208 | type: string 209 | format: uriref 210 | description: A URL to the API console for each API 211 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1726560853, 9 | "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1727863144, 24 | "narHash": "sha256-E9uNBPoac2pZ62a3k482RnMpDM9aQAG5PnFKi36cTQE=", 25 | "owner": "nixos", 26 | "repo": "nixpkgs", 27 | "rev": "1ef7ab47629547cfdaeddee7b8cde510bae78d10", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "nixos", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "root": { 37 | "inputs": { 38 | "flake-utils": "flake-utils", 39 | "nixpkgs": "nixpkgs" 40 | } 41 | }, 42 | "systems": { 43 | "locked": { 44 | "lastModified": 1681028828, 45 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 46 | "owner": "nix-systems", 47 | "repo": "default", 48 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 49 | "type": "github" 50 | }, 51 | "original": { 52 | "owner": "nix-systems", 53 | "repo": "default", 54 | "type": "github" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "OpenAPI generator CLI nix flake"; 3 | 4 | inputs.nixpkgs.url = "github:nixos/nixpkgs"; 5 | inputs.flake-utils.url = "github:numtide/flake-utils"; 6 | 7 | outputs = { self, nixpkgs, flake-utils, ... }: 8 | flake-utils.lib.eachDefaultSystem (system: 9 | let 10 | pkgs = import nixpkgs { inherit system; }; 11 | in 12 | { 13 | devShells.default = pkgs.mkShell 14 | { 15 | buildInputs = with pkgs;[ 16 | # These dependencies match the github workflows 17 | yarn 18 | nodejs_18 19 | ]; 20 | }; 21 | } 22 | ); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /img/vm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/623732ce18518724abe575c5cdd33cdc8ff072d5/img/vm.gif -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | import { getJestProjectsAsync } from '@nx/jest'; 2 | 3 | export default async () => ({ 4 | projects: await getJestProjectsAsync(), 5 | }); 6 | -------------------------------------------------------------------------------- /jest.preset.js: -------------------------------------------------------------------------------- 1 | const nxPreset = require('@nx/jest/preset').default; 2 | 3 | module.exports = { ...nxPreset }; 4 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | const {exec} = require('child_process'); 2 | const https = require('https'); 3 | const path = require('path'); 4 | 5 | const fs = require('fs-extra'); 6 | 7 | const packageInfo = require('../package.json'); 8 | const registry = 'https://registry.npmjs.org'; 9 | const tagPrefix = 'cli-'; 10 | 11 | async function httpGET(url) { 12 | return new Promise((resolve, reject) => { 13 | https.get(url, (resp) => { 14 | let data = ''; 15 | resp.on('data', (chunk) => data += chunk); 16 | resp.on('end', () => resolve(data)); 17 | }).on("error", reject); 18 | }); 19 | } 20 | 21 | async function getOpenapiGeneratorCliDownloadLinks() { 22 | const baseUrl = 'https://search.maven.org'; 23 | const queryUrl = `${baseUrl}/solrsearch/select?q=g:org.openapitools+AND+a:openapi-generator-cli&core=gav&start=0&rows=200`; 24 | 25 | return httpGET(queryUrl).then(data => { 26 | const {response} = JSON.parse(data); 27 | 28 | if (response) { 29 | return response.docs.reduce((downloadLinks, doc) => { 30 | 31 | const group = doc.g.replace('.', '/'); 32 | const artifact = doc.a.replace('.', '/'); 33 | const version = doc.v; 34 | 35 | return { 36 | ...downloadLinks, 37 | [doc.v]: `https://repo1.maven.org/maven2/${group}/${artifact}/${version}/${artifact}-${version}.jar`, 38 | } 39 | }, {}); 40 | } 41 | }); 42 | } 43 | 44 | async function getAlreadyPublishedVersions() { 45 | return new Promise((resolve, reject) => { 46 | exec(`npm view ${packageInfo.name} --registry ${registry} --json`, (error, stdout) => { 47 | if (error !== null) { 48 | reject(error); 49 | return; 50 | } 51 | 52 | try { 53 | const json = JSON.parse(stdout); 54 | resolve(Object.keys(json['dist-tags']).map(tag => { 55 | return tag.replace(tagPrefix, ''); 56 | })); 57 | } catch (e) { 58 | reject(e); 59 | } 60 | }); 61 | }); 62 | } 63 | 64 | async function downloadFile(downloadLink, savePath) { 65 | 66 | await fs.ensureDir(path.dirname(savePath)); 67 | 68 | return new Promise(resolve => { 69 | const file = fs.createWriteStream(savePath); 70 | https.get(downloadLink, response => { 71 | response.pipe(file); 72 | response.on('end', () => { 73 | resolve(); 74 | }); 75 | }); 76 | }); 77 | } 78 | 79 | async function buildPackage(openapiGeneratorCliVersion, openapiGeneratorCliDownloadLink) { 80 | console.log(`Build package for openapi-generator-cli@${openapiGeneratorCliVersion}`); 81 | 82 | const packageDistDir = path.resolve('./dist', openapiGeneratorCliVersion); 83 | 84 | // download the java binary 85 | await downloadFile(openapiGeneratorCliDownloadLink, path.resolve(packageDistDir, 'bin/openapi-generator.jar')); 86 | 87 | // copy all files which are listen in the package.json (files property) to package dist directory 88 | packageInfo.files 89 | .filter(file => !file.endsWith('openapi-generator.jar')) 90 | .forEach(async file => await fs.copy(path.resolve(file), path.resolve(packageDistDir, file))); 91 | 92 | // build the package json file based on the main package.json 93 | const {scripts, dependencies, devDependencies, ...packageJsonDefault} = packageInfo; 94 | console.debug(`scripts:${scripts}, dependencies:${dependencies}, devDependencies:${devDependencies}`); 95 | 96 | await fs.outputJson(path.resolve(packageDistDir, 'package.json'), { 97 | ...packageJsonDefault, 98 | version: `${packageInfo.version}-${openapiGeneratorCliVersion}` 99 | }); 100 | } 101 | 102 | module.exports = { 103 | config: { 104 | registry, 105 | tagPrefix, 106 | }, 107 | getOpenapiGeneratorCliDownloadLinks, 108 | getAlreadyPublishedVersions, 109 | buildPackage, 110 | }; 111 | -------------------------------------------------------------------------------- /libs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/623732ce18518724abe575c5cdd33cdc8ff072d5/libs/.gitkeep -------------------------------------------------------------------------------- /nx.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/nx/schemas/nx-schema.json", 3 | "namedInputs": { 4 | "default": ["{projectRoot}/**/*", "sharedGlobals"], 5 | "sharedGlobals": [ 6 | "{workspaceRoot}/workspace.json", 7 | "{workspaceRoot}/tsconfig.base.json", 8 | "{workspaceRoot}/tslint.json", 9 | "{workspaceRoot}/nx.json" 10 | ], 11 | "production": [ 12 | "default", 13 | "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)", 14 | "!{projectRoot}/tsconfig.spec.json", 15 | "!{projectRoot}/jest.config.[jt]s", 16 | "!{projectRoot}/src/test-setup.[jt]s" 17 | ] 18 | }, 19 | "targetDefaults": { 20 | "build": { 21 | "dependsOn": ["^build"], 22 | "inputs": ["production", "^production"], 23 | "cache": true 24 | }, 25 | "lint": { 26 | "cache": true 27 | }, 28 | "@nx/jest:jest": { 29 | "cache": true, 30 | "inputs": ["default", "^production"], 31 | "options": { 32 | "passWithNoTests": true 33 | }, 34 | "configurations": { 35 | "ci": { 36 | "ci": true, 37 | "codeCoverage": true 38 | } 39 | } 40 | } 41 | }, 42 | "useInferencePlugins": false, 43 | "defaultBase": "master", 44 | "useLegacyCache": true 45 | } 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openapitools", 3 | "version": "0.0.0-development", 4 | "license": "Apache-2.0", 5 | "private": false, 6 | "author": { 7 | "name": "OpenAPI Tools", 8 | "url": "https://openapitools.org/", 9 | "email": "team@openapitools.org" 10 | }, 11 | "contributors": [ 12 | { 13 | "name": "Kay Schecker", 14 | "email": "sayhello@kay-schecker.de", 15 | "url": "https://www.kay-schecker.de" 16 | } 17 | ], 18 | "homepage": "https://github.com/OpenAPITools/openapi-generator-cli", 19 | "bugs": "https://github.com/OpenAPITools/openapi-generator-cli/issues", 20 | "readme": "README.md", 21 | "funding": { 22 | "type": "opencollective", 23 | "url": "https://opencollective.com/openapi_generator" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/OpenAPITools/openapi-generator-cli.git" 28 | }, 29 | "publishConfig": { 30 | "registry": "https://registry.npmjs.org" 31 | }, 32 | "keywords": [ 33 | "rest-api", 34 | "rest-client", 35 | "sdk", 36 | "generator", 37 | "restful-api", 38 | "api", 39 | "api-client", 40 | "api-server", 41 | "openapi3", 42 | "openapi", 43 | "oas", 44 | "rest" 45 | ], 46 | "engines": { 47 | "node": ">=16" 48 | }, 49 | "scripts": { 50 | "nx": "nx", 51 | "start": "nx serve generator-cli", 52 | "cli": "node ./dist/apps/generator-cli/main.js", 53 | "build": "NODE_OPTIONS=--openssl-legacy-provider nx build generator-cli", 54 | "publish": "npm run build && npm publish ./dist/apps/generator-cli", 55 | "test": "nx test generator-cli", 56 | "lint": "nx lint generator-cli", 57 | "e2e": "nx e2e generator-cli", 58 | "affected:test": "nx affected --target=test", 59 | "affected:lint": "nx affected --target=lint", 60 | "affected:build": "nx affected --target=build", 61 | "affected:e2e": "nx affected --target=e2e", 62 | "affected:dep-graph": "nx affected --target=dep-graph", 63 | "affected": "nx affected", 64 | "format": "nx format:write", 65 | "format:write": "nx format:write", 66 | "format:check": "nx format:check", 67 | "update": "nx migrate latest", 68 | "workspace-schematic": "nx workspace-schematic", 69 | "dep-graph": "nx dep-graph", 70 | "help": "nx help", 71 | "semantic-release": "semantic-release", 72 | "prepare": "husky" 73 | }, 74 | "collective": { 75 | "type": "opencollective", 76 | "url": "https://opencollective.com/openapi_generator", 77 | "donation": { 78 | "text": "Please sponsor OpenAPI Generator." 79 | } 80 | }, 81 | "dependencies": { 82 | "@nestjs/axios": "^4.0.0", 83 | "@nestjs/common": "^11.0.16", 84 | "@nestjs/core": "^11.0.16", 85 | "@nestjs/platform-express": "^11.0.16", 86 | "@nuxtjs/opencollective": "0.3.2", 87 | "axios": "^1.8.4", 88 | "chalk": "4.1.2", 89 | "commander": "8.3.0", 90 | "compare-versions": "4.1.4", 91 | "concurrently": "6.5.1", 92 | "console.table": "0.10.0", 93 | "fs-extra": "11.3.0", 94 | "glob": "9.x", 95 | "inquirer": "8.2.6", 96 | "jsonpath": "1.1.1", 97 | "lodash": "4.17.21", 98 | "proxy-agent": "^6.4.0", 99 | "reflect-metadata": "^0.2.2", 100 | "rxjs": "^7.8.2", 101 | "tslib": "^2.3.0" 102 | }, 103 | "devDependencies": { 104 | "@commitlint/cli": "19.8.1", 105 | "@commitlint/config-conventional": "19.8.1", 106 | "@nestjs/schematics": "^11.0.5", 107 | "@nestjs/testing": "^11.0.16", 108 | "@nx/eslint": "20.8.2", 109 | "@nx/eslint-plugin": "20.8.2", 110 | "@nx/jest": "20.8.2", 111 | "@nx/js": "20.8.2", 112 | "@nx/nest": "20.8.2", 113 | "@nx/node": "20.8.2", 114 | "@nx/webpack": "20.8.2", 115 | "@nx/workspace": "20.8.2", 116 | "@semantic-release/changelog": "6.0.3", 117 | "@types/concurrently": "7.0.3", 118 | "@types/fs-extra": "11.0.4", 119 | "@types/inquirer": "8.2.11", 120 | "@types/jest": "29.5.14", 121 | "@types/jsonpath": "0.2.4", 122 | "@types/lodash": "4.17.16", 123 | "@types/node": "20.14.8", 124 | "@typescript-eslint/eslint-plugin": "7.18.0", 125 | "@typescript-eslint/parser": "7.18.0", 126 | "dotenv": "16.5.0", 127 | "eslint": "9.27.0", 128 | "eslint-config-prettier": "^10.0.0", 129 | "generate-package-json-webpack-plugin": "2.6.0", 130 | "husky": "9.1.7", 131 | "jest": "29.7.0", 132 | "jest-environment-jsdom": "29.7.0", 133 | "jest-environment-node": "^29.4.1", 134 | "nx": "20.8.2", 135 | "prettier": "3.5.3", 136 | "semantic-release": "22.0.12", 137 | "ts-jest": "29.3.4", 138 | "ts-node": "10.9.2", 139 | "tslint": "6.1.3", 140 | "type-fest": "4.41.0", 141 | "typescript": "5.8.3" 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "baseBranches": [ 3 | "master" 4 | ], 5 | "extends": [ 6 | "config:base" 7 | ], 8 | "packageRules": [ 9 | { 10 | "matchUpdateTypes": [ 11 | "minor", 12 | "patch", 13 | "pin", 14 | "digest" 15 | ], 16 | "automerge": true 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /tools/schematics/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/623732ce18518724abe575c5cdd33cdc8ff072d5/tools/schematics/.gitkeep -------------------------------------------------------------------------------- /tools/tsconfig.tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "../dist/out-tsc/tools", 5 | "rootDir": ".", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": ["node"] 9 | }, 10 | "include": ["**/*.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "resolveJsonModule": true, 10 | "experimentalDecorators": true, 11 | "importHelpers": true, 12 | "target": "es2015", 13 | "module": "esnext", 14 | "typeRoots": ["node_modules/@types"], 15 | "lib": ["es2017", "dom"], 16 | "skipLibCheck": true, 17 | "skipDefaultLibCheck": true, 18 | "baseUrl": ".", 19 | "paths": {} 20 | }, 21 | "exclude": ["node_modules", "tmp"] 22 | } 23 | --------------------------------------------------------------------------------