├── .editorconfig ├── .github ├── CONTRIBUTING.md ├── dependabot.yaml └── workflows │ ├── auto-merge.yml │ └── go-test.yml ├── .gitignore ├── .golangci.yml ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── doc.go ├── doc_test.go ├── errors.go ├── example_test.go ├── fixtures ├── bugs │ ├── 145 │ │ └── Program Files (x86) │ │ │ └── AppName │ │ │ ├── ref.json │ │ │ ├── todos-expanded.json │ │ │ ├── todos.common.json │ │ │ └── todos.json │ └── 1816 │ │ └── fixture-1816.yaml ├── json │ ├── models │ │ ├── modelWithArrayRef.json │ │ ├── modelWithComposition.json │ │ ├── modelWithDateTimeMap.json │ │ ├── modelWithExamples.json │ │ ├── modelWithInt32Map.json │ │ ├── modelWithInt64Map.json │ │ ├── modelWithMultipleProperties.json │ │ ├── modelWithObjectMap.json │ │ ├── modelWithPrimitiveArray.json │ │ ├── modelWithStringProperty.json │ │ ├── modelWithXmlAttributes.json │ │ ├── models.json │ │ ├── multipleModels.json │ │ └── properties │ │ │ ├── propertyWithBooleanArray.json │ │ │ ├── propertyWithByteArray.json │ │ │ ├── propertyWithComplexArray.json │ │ │ ├── propertyWithDateTimeArray.json │ │ │ ├── propertyWithInt32Array.json │ │ │ ├── propertyWithInt64Array.json │ │ │ ├── propertyWithRef.json │ │ │ ├── propertyWithStringArray.json │ │ │ ├── simpleBooleanProperty.json │ │ │ ├── simpleByteProperty.json │ │ │ ├── simpleDateTimeProperty.json │ │ │ ├── simpleInt32Property.json │ │ │ ├── simpleInt64Property.json │ │ │ └── simpleStringProperty.json │ ├── resources │ │ ├── cascadingSchemes.json │ │ ├── commonParameters.json │ │ ├── multipleMimeTypes.json │ │ ├── operations │ │ │ ├── operationWithTags.json │ │ │ ├── stringPathAndBoolQueryParamResource.json │ │ │ └── stringPathParamResource.json │ │ ├── parameters │ │ │ ├── bodyComplexArrayParameter.json │ │ │ ├── bodyComplexParameter.json │ │ │ ├── bodyInt64Parameter.json │ │ │ ├── bodyStringArrayParameter.json │ │ │ ├── bodyStringParameter.json │ │ │ ├── formDataComplexParameter.json │ │ │ ├── formDataInt64Parameter.json │ │ │ ├── formDataStringArrayParameter.json │ │ │ ├── formDataStringParameter.json │ │ │ ├── headerInt64ArrayParameter.json │ │ │ ├── headerStringArrayParameter.json │ │ │ ├── headerStringParameter.json │ │ │ ├── pathInt64Parameter.json │ │ │ ├── pathStringArrayParameter.json │ │ │ ├── pathStringParameter.json │ │ │ ├── queryInt64ArrayParameter.json │ │ │ ├── queryStringParameter.json │ │ │ └── queryWithComplexParameter.json │ │ ├── pathLoaderIssue.json │ │ ├── resourceWithExamplePayload.json │ │ ├── resourceWithLinkedDefinitions.json │ │ ├── resourceWithLinkedDefinitions_part1.json │ │ ├── resourceWithRelativeHost.json │ │ ├── reusableParameters.json │ │ ├── securityExample.json │ │ ├── stringPathParamResource.json │ │ ├── taggedResource.json │ │ └── vendorExtensionExamples.json │ └── responses │ │ ├── complexArrayResponse.json │ │ ├── dateTimeResponse.json │ │ ├── int32Response.json │ │ ├── int64Response.json │ │ ├── multipleResponses.json │ │ ├── stringArrayResponse.json │ │ ├── stringResponse.json │ │ ├── stringResponseWithHeader.json │ │ └── voidResponse.json └── yaml │ ├── .gitkeep │ ├── models │ ├── modelWithArrayRef.yaml │ ├── modelWithComposition.yaml │ ├── modelWithDateTimeMap.yaml │ ├── modelWithExamples.yaml │ ├── modelWithInt32Map.yaml │ ├── modelWithInt64Map.yaml │ ├── modelWithMultipleProperties.yaml │ ├── modelWithObjectMap.yaml │ ├── modelWithPrimitiveArray.yaml │ ├── modelWithStringProperty.yaml │ ├── modelWithXmlAttributes.yaml │ ├── models.yaml │ ├── multipleModels.yaml │ └── properties │ │ ├── propertyWithBooleanArray.yaml │ │ ├── propertyWithByteArray.yaml │ │ ├── propertyWithComplexArray.yaml │ │ ├── propertyWithDateTimeArray.yaml │ │ ├── propertyWithInt32Array.yaml │ │ ├── propertyWithInt64Array.yaml │ │ ├── propertyWithRef.yaml │ │ ├── propertyWithStringArray.yaml │ │ ├── simpleBooleanProperty.yaml │ │ ├── simpleByteProperty.yaml │ │ ├── simpleDateTimeProperty.yaml │ │ ├── simpleInt32Property.yaml │ │ ├── simpleInt64Property.yaml │ │ └── simpleStringProperty.yaml │ ├── resources │ ├── cascadingSchemes.yaml │ ├── commonParameters.yaml │ ├── multipleMimeTypes.yaml │ ├── operations │ │ ├── operationWithTags.yaml │ │ ├── stringPathAndBoolQueryParamResource.yaml │ │ └── stringPathParamResource.yaml │ ├── parameters │ │ ├── bodyComplexArrayParameter.yaml │ │ ├── bodyComplexParameter.yaml │ │ ├── bodyInt64Parameter.yaml │ │ ├── bodyStringArrayParameter.yaml │ │ ├── bodyStringParameter.yaml │ │ ├── formDataComplexParameter.yaml │ │ ├── formDataInt64Parameter.yaml │ │ ├── formDataStringArrayParameter.yaml │ │ ├── formDataStringParameter.yaml │ │ ├── headerInt64ArrayParameter.yaml │ │ ├── headerStringArrayParameter.yaml │ │ ├── headerStringParameter.yaml │ │ ├── pathInt64Parameter.yaml │ │ ├── pathStringArrayParameter.yaml │ │ ├── pathStringParameter.yaml │ │ ├── queryInt64ArrayParameter.yaml │ │ ├── queryStringParameter.yaml │ │ └── queryWithComplexParameter.yaml │ ├── resourceWithExamplePayload.yaml │ ├── resourceWithLinkedDefinitions.yaml │ ├── resourceWithLinkedDefinitions_part1.yaml │ ├── resourceWithRelativeHost.yaml │ ├── reusableParameters.yaml │ ├── securityExample.yaml │ ├── stringPathParamResource.yaml │ ├── taggedResource.yaml │ └── vendorExtensionExamples.yaml │ ├── responses │ ├── complexArrayResponse.yaml │ ├── dateTimeResponse.yaml │ ├── int32Response.yaml │ ├── int64Response.yaml │ ├── multipleResponses.yaml │ ├── stringArrayResponse.yaml │ ├── stringResponse.yaml │ ├── stringResponseWithHeader.yaml │ └── voidResponse.yaml │ ├── swagger │ ├── 1 │ │ └── 2 │ │ │ └── 3 │ │ │ └── 4 │ │ │ └── swagger.yaml │ ├── shared │ │ ├── definitions │ │ │ └── page.yaml │ │ └── something.yaml │ ├── spec.yml │ └── test3-ter-model-schema.json │ └── yaml │ ├── .gitkeep │ ├── models │ ├── modelWithArrayRef.yaml │ ├── modelWithComposition.yaml │ ├── modelWithDateTimeMap.yaml │ ├── modelWithExamples.yaml │ ├── modelWithInt32Map.yaml │ ├── modelWithInt64Map.yaml │ ├── modelWithMultipleProperties.yaml │ ├── modelWithObjectMap.yaml │ ├── modelWithPrimitiveArray.yaml │ ├── modelWithStringProperty.yaml │ ├── modelWithXmlAttributes.yaml │ ├── models.yaml │ ├── multipleModels.yaml │ └── properties │ │ ├── propertyWithBooleanArray.yaml │ │ ├── propertyWithByteArray.yaml │ │ ├── propertyWithComplexArray.yaml │ │ ├── propertyWithDateTimeArray.yaml │ │ ├── propertyWithInt32Array.yaml │ │ ├── propertyWithInt64Array.yaml │ │ ├── propertyWithRef.yaml │ │ ├── propertyWithStringArray.yaml │ │ ├── simpleBooleanProperty.yaml │ │ ├── simpleByteProperty.yaml │ │ ├── simpleDateTimeProperty.yaml │ │ ├── simpleInt32Property.yaml │ │ ├── simpleInt64Property.yaml │ │ └── simpleStringProperty.yaml │ ├── resources │ ├── cascadingSchemes.yaml │ ├── commonParameters.yaml │ ├── multipleMimeTypes.yaml │ ├── operations │ │ ├── operationWithTags.yaml │ │ ├── stringPathAndBoolQueryParamResource.yaml │ │ └── stringPathParamResource.yaml │ ├── parameters │ │ ├── bodyComplexArrayParameter.yaml │ │ ├── bodyComplexParameter.yaml │ │ ├── bodyInt64Parameter.yaml │ │ ├── bodyStringArrayParameter.yaml │ │ ├── bodyStringParameter.yaml │ │ ├── formDataComplexParameter.yaml │ │ ├── formDataInt64Parameter.yaml │ │ ├── formDataStringArrayParameter.yaml │ │ ├── formDataStringParameter.yaml │ │ ├── headerInt64ArrayParameter.yaml │ │ ├── headerStringArrayParameter.yaml │ │ ├── headerStringParameter.yaml │ │ ├── pathInt64Parameter.yaml │ │ ├── pathStringArrayParameter.yaml │ │ ├── pathStringParameter.yaml │ │ ├── queryInt64ArrayParameter.yaml │ │ ├── queryStringParameter.yaml │ │ └── queryWithComplexParameter.yaml │ ├── resourceWithExamplePayload.yaml │ ├── resourceWithLinkedDefinitions.yaml │ ├── resourceWithLinkedDefinitions_part1.yaml │ ├── resourceWithRelativeHost.yaml │ ├── reusableParameters.yaml │ ├── securityExample.yaml │ ├── stringPathParamResource.yaml │ ├── taggedResource.yaml │ └── vendorExtensionExamples.yaml │ └── responses │ ├── complexArrayResponse.yaml │ ├── dateTimeResponse.yaml │ ├── int32Response.yaml │ ├── int64Response.yaml │ ├── multipleResponses.yaml │ ├── stringArrayResponse.yaml │ ├── stringResponse.yaml │ ├── stringResponseWithHeader.yaml │ └── voidResponse.yaml ├── fmts ├── fixture_test.go ├── yaml.go └── yaml_test.go ├── go.mod ├── go.sum ├── json_test.go ├── loaders.go ├── loaders_test.go ├── options.go ├── options_test.go ├── spec.go └── spec_test.go /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | trim_trailing_whitespace = true 11 | 12 | # Set default charset 13 | [*.{js,py,go,scala,rb,java,html,css,less,sass,md}] 14 | charset = utf-8 15 | 16 | # Tab indentation (no size specified) 17 | [*.go] 18 | indent_style = tab 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | 23 | # Matches the exact files either package.json or .travis.yml 24 | [{package.json,.travis.yml}] 25 | indent_style = space 26 | indent_size = 2 27 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contribution Guidelines 2 | 3 | ### Pull requests are always welcome 4 | 5 | We are always thrilled to receive pull requests, and do our best to 6 | process them as fast as possible. Not sure if that typo is worth a pull 7 | request? Do it! We will appreciate it. 8 | 9 | If your pull request is not accepted on the first try, don't be 10 | discouraged! If there's a problem with the implementation, hopefully you 11 | received feedback on what to improve. 12 | 13 | We're trying very hard to keep go-swagger lean and focused. We don't want it 14 | to do everything for everybody. This means that we might decide against 15 | incorporating a new feature. However, there might be a way to implement 16 | that feature *on top of* go-swagger. 17 | 18 | 19 | ### Conventions 20 | 21 | Fork the repo and make changes on your fork in a feature branch: 22 | 23 | - If it's a bugfix branch, name it XXX-something where XXX is the number of the 24 | issue 25 | - If it's a feature branch, create an enhancement issue to announce your 26 | intentions, and name it XXX-something where XXX is the number of the issue. 27 | 28 | Submit unit tests for your changes. Go has a great test framework built in; use 29 | it! Take a look at existing tests for inspiration. Run the full test suite on 30 | your branch before submitting a pull request. 31 | 32 | Update the documentation when creating or modifying features. Test 33 | your documentation changes for clarity, concision, and correctness, as 34 | well as a clean documentation build. See ``docs/README.md`` for more 35 | information on building the docs and how docs get released. 36 | 37 | Write clean code. Universally formatted code promotes ease of writing, reading, 38 | and maintenance. Always run `gofmt -s -w file.go` on each changed file before 39 | committing your changes. Most editors have plugins that do this automatically. 40 | 41 | Pull requests descriptions should be as clear as possible and include a 42 | reference to all the issues that they address. 43 | 44 | Pull requests must not contain commits from other users or branches. 45 | 46 | Commit messages must start with a capitalized and short summary (max. 50 47 | chars) written in the imperative, followed by an optional, more detailed 48 | explanatory text which is separated from the summary by an empty line. 49 | 50 | Code review comments may be added to your pull request. Discuss, then make the 51 | suggested modifications and push additional commits to your feature branch. Be 52 | sure to post a comment after pushing. The new commits will show up in the pull 53 | request automatically, but the reviewers will not be notified unless you 54 | comment. 55 | 56 | Before the pull request is merged, make sure that you squash your commits into 57 | logical units of work using `git rebase -i` and `git push -f`. After every 58 | commit the test suite should be passing. Include documentation changes in the 59 | same commit so that a revert would remove all traces of the feature or fix. 60 | 61 | Commits that fix or close an issue should include a reference like `Closes #XXX` 62 | or `Fixes #XXX`, which will automatically close the issue when merged. 63 | 64 | ### Sign your work 65 | 66 | The sign-off is a simple line at the end of the explanation for the 67 | patch, which certifies that you wrote it or otherwise have the right to 68 | pass it on as an open-source patch. The rules are pretty simple: if you 69 | can certify the below (from 70 | [developercertificate.org](http://developercertificate.org/)): 71 | 72 | ``` 73 | Developer Certificate of Origin 74 | Version 1.1 75 | 76 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 77 | 660 York Street, Suite 102, 78 | San Francisco, CA 94110 USA 79 | 80 | Everyone is permitted to copy and distribute verbatim copies of this 81 | license document, but changing it is not allowed. 82 | 83 | 84 | Developer's Certificate of Origin 1.1 85 | 86 | By making a contribution to this project, I certify that: 87 | 88 | (a) The contribution was created in whole or in part by me and I 89 | have the right to submit it under the open source license 90 | indicated in the file; or 91 | 92 | (b) The contribution is based upon previous work that, to the best 93 | of my knowledge, is covered under an appropriate open source 94 | license and I have the right under that license to submit that 95 | work with modifications, whether created in whole or in part 96 | by me, under the same open source license (unless I am 97 | permitted to submit under a different license), as indicated 98 | in the file; or 99 | 100 | (c) The contribution was provided directly to me by some other 101 | person who certified (a), (b) or (c) and I have not modified 102 | it. 103 | 104 | (d) I understand and agree that this project and the contribution 105 | are public and that a record of the contribution (including all 106 | personal information I submit with it, including my sign-off) is 107 | maintained indefinitely and may be redistributed consistent with 108 | this project or the open source license(s) involved. 109 | ``` 110 | 111 | then you just add a line to every git commit message: 112 | 113 | Signed-off-by: Joe Smith 114 | 115 | using your real name (sorry, no pseudonyms or anonymous contributions.) 116 | 117 | You can add the sign off when creating the git commit via `git commit -s`. 118 | -------------------------------------------------------------------------------- /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | day: "friday" 8 | open-pull-requests-limit: 2 # <- default is 5 9 | groups: # <- group all github actions updates in a single PR 10 | # 1. development-dependencies are auto-merged 11 | development-dependencies: 12 | patterns: 13 | - '*' 14 | 15 | - package-ecosystem: "gomod" 16 | # We define 4 groups of dependencies to regroup update pull requests: 17 | # - development (e.g. test dependencies) 18 | # - go-openapi updates 19 | # - golang.org (e.g. golang.org/x/... packages) 20 | # - other dependencies (direct or indirect) 21 | # 22 | # * All groups are checked once a week and each produce at most 1 PR. 23 | # * All dependabot PRs are auto-approved 24 | # 25 | # Auto-merging policy, when requirements are met: 26 | # 1. development-dependencies are auto-merged 27 | # 2. golang.org-dependencies are auto-merged 28 | # 3. go-openapi patch updates are auto-merged. Minor/major version updates require a manual merge. 29 | # 4. other dependencies require a manual merge 30 | directory: "/" 31 | schedule: 32 | interval: "weekly" 33 | day: "friday" 34 | open-pull-requests-limit: 4 35 | groups: 36 | development-dependencies: 37 | patterns: 38 | - "github.com/stretchr/testify" 39 | 40 | golang.org-dependencies: 41 | patterns: 42 | - "golang.org/*" 43 | 44 | go-openapi-dependencies: 45 | patterns: 46 | - "github.com/go-openapi/*" 47 | 48 | other-dependencies: 49 | exclude-patterns: 50 | - "github.com/go-openapi/*" 51 | - "github.com/stretchr/testify" 52 | - "golang.org/*" 53 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot auto-merge 2 | on: pull_request 3 | 4 | permissions: 5 | contents: write 6 | pull-requests: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: github.event.pull_request.user.login == 'dependabot[bot]' 12 | steps: 13 | - name: Dependabot metadata 14 | id: metadata 15 | uses: dependabot/fetch-metadata@v2 16 | 17 | - name: Auto-approve all dependabot PRs 18 | run: gh pr review --approve "$PR_URL" 19 | env: 20 | PR_URL: ${{github.event.pull_request.html_url}} 21 | GH_TOKEN: ${{secrets.GITHUB_TOKEN}} 22 | 23 | - name: Auto-merge dependabot PRs for development dependencies 24 | if: contains(steps.metadata.outputs.dependency-group, 'development-dependencies') 25 | run: gh pr merge --auto --rebase "$PR_URL" 26 | env: 27 | PR_URL: ${{github.event.pull_request.html_url}} 28 | GH_TOKEN: ${{secrets.GITHUB_TOKEN}} 29 | 30 | - name: Auto-merge dependabot PRs for go-openapi patches 31 | if: contains(steps.metadata.outputs.dependency-group, 'go-openapi-dependencies') && (steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch') 32 | run: gh pr merge --auto --rebase "$PR_URL" 33 | env: 34 | PR_URL: ${{github.event.pull_request.html_url}} 35 | GH_TOKEN: ${{secrets.GITHUB_TOKEN}} 36 | 37 | - name: Auto-merge dependabot PRs for golang.org updates 38 | if: contains(steps.metadata.outputs.dependency-group, 'golang.org-dependencies') 39 | run: gh pr merge --auto --rebase "$PR_URL" 40 | env: 41 | PR_URL: ${{github.event.pull_request.html_url}} 42 | GH_TOKEN: ${{secrets.GITHUB_TOKEN}} 43 | 44 | -------------------------------------------------------------------------------- /.github/workflows/go-test.yml: -------------------------------------------------------------------------------- 1 | name: go test 2 | 3 | on: 4 | push: 5 | tags: 6 | - v* 7 | branches: 8 | - master 9 | 10 | pull_request: 11 | 12 | jobs: 13 | lint: 14 | name: Lint 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-go@v5 19 | with: 20 | go-version: stable 21 | check-latest: true 22 | cache: true 23 | - name: golangci-lint 24 | uses: golangci/golangci-lint-action@v8 25 | with: 26 | version: latest 27 | only-new-issues: true 28 | skip-cache: true 29 | 30 | test: 31 | name: Unit tests 32 | runs-on: ${{ matrix.os }} 33 | 34 | strategy: 35 | matrix: 36 | os: [ ubuntu-latest, macos-latest, windows-latest ] 37 | go_version: ['oldstable', 'stable' ] 38 | 39 | steps: 40 | - uses: actions/setup-go@v5 41 | with: 42 | go-version: '${{ matrix.go_version }}' 43 | check-latest: true 44 | cache: true 45 | 46 | - uses: actions/checkout@v4 47 | - name: Run unit tests 48 | shell: bash 49 | run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic -coverpkg=$(go list)/... ./... 50 | 51 | - name: Upload coverage to codecov 52 | uses: codecov/codecov-action@v5 53 | with: 54 | files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out' 55 | flags: '${{ matrix.go_version }}-${{ matrix.os }}' 56 | fail_ci_if_error: false 57 | verbose: true 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | secrets.yml 2 | coverage.out 3 | profile.cov 4 | profile.out 5 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | linters: 3 | default: all 4 | disable: 5 | - cyclop 6 | - depguard 7 | - errchkjson 8 | - errorlint 9 | - exhaustruct 10 | - forcetypeassert 11 | - funlen 12 | - gochecknoglobals 13 | - gochecknoinits 14 | - gocognit 15 | - godot 16 | - godox 17 | - gosmopolitan 18 | - inamedparam 19 | - ireturn 20 | - lll 21 | - musttag 22 | - nestif 23 | - nlreturn 24 | - nonamedreturns 25 | - paralleltest 26 | - testpackage 27 | - thelper 28 | - tparallel 29 | - unparam 30 | - varnamelen 31 | - whitespace 32 | - wrapcheck 33 | - wsl 34 | settings: 35 | dupl: 36 | threshold: 200 37 | goconst: 38 | min-len: 2 39 | min-occurrences: 3 40 | gocyclo: 41 | min-complexity: 45 42 | exclusions: 43 | generated: lax 44 | presets: 45 | - comments 46 | - common-false-positives 47 | - legacy 48 | - std-error-handling 49 | paths: 50 | - third_party$ 51 | - builtin$ 52 | - examples$ 53 | formatters: 54 | enable: 55 | - gofmt 56 | - goimports 57 | exclusions: 58 | generated: lax 59 | paths: 60 | - third_party$ 61 | - builtin$ 62 | - examples$ 63 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | after_success: 2 | - bash <(curl -s https://codecov.io/bash) 3 | go: 4 | - 1.16.x 5 | - 1.x 6 | install: 7 | - go get gotest.tools/gotestsum 8 | language: go 9 | arch: 10 | - amd64 11 | - ppc64le 12 | jobs: 13 | include: 14 | # include linting job, but only for latest go version and amd64 arch 15 | - go: 1.x 16 | arch: amd64 17 | install: 18 | go get github.com/golangci/golangci-lint/cmd/golangci-lint 19 | script: 20 | - golangci-lint run --new-from-rev master 21 | notifications: 22 | slack: 23 | secure: OxkPwVp35qBTUilgWC8xykSj+sGMcj0h8IIOKD+Rflx2schZVlFfdYdyVBM+s9OqeOfvtuvnR9v1Ye2rPKAvcjWdC4LpRGUsgmItZaI6Um8Aj6+K9udCw5qrtZVfOVmRu8LieH//XznWWKdOultUuniW0MLqw5+II87Gd00RWbCGi0hk0PykHe7uK+PDA2BEbqyZ2WKKYCvfB3j+0nrFOHScXqnh0V05l2E83J4+Sgy1fsPy+1WdX58ZlNBG333ibaC1FS79XvKSmTgKRkx3+YBo97u6ZtUmJa5WZjf2OdLG3KIckGWAv6R5xgxeU31N0Ng8L332w/Edpp2O/M2bZwdnKJ8hJQikXIAQbICbr+lTDzsoNzMdEIYcHpJ5hjPbiUl3Bmd+Jnsjf5McgAZDiWIfpCKZ29tPCEkVwRsOCqkyPRMNMzHHmoja495P5jR+ODS7+J8RFg5xgcnOgpP9D4Wlhztlf5WyZMpkLxTUD+bZq2SRf50HfHFXTkfq22zPl3d1eq0yrLwh/Z/fWKkfb6SyysROL8y6s8u3dpFX1YHSg0BR6i913h4aoZw9B2BG27cafLLTwKYsp2dFo1PWl4O6u9giFJIeqwloZHLKKrwh0cBFhB7RH0I58asxkZpCH6uWjJierahmHe7iS+E6i+9oCHkOZ59hmCYNimIs3hM= 24 | script: 25 | - gotestsum -f short-verbose -- -race -timeout=20m -coverprofile=coverage.txt -covermode=atomic ./... 26 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at ivan+abuse@flanders.co.nz. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Loads OAI specs [![Build Status](https://github.com/go-openapi/loads/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/loads/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/loads/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/loads) 2 | 3 | [![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/loads/master/LICENSE) [![GoDoc](https://godoc.org/github.com/go-openapi/loads?status.svg)](http://godoc.org/github.com/go-openapi/loads) 4 | [![Go Report Card](https://goreportcard.com/badge/github.com/go-openapi/loads)](https://goreportcard.com/report/github.com/go-openapi/loads) 5 | 6 | Loading of OAI specification documents from local or remote locations. Supports JSON and YAML documents. 7 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 go-swagger maintainers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package loads provides document loading methods for swagger (OAI) specifications. 16 | // 17 | // It is used by other go-openapi packages to load and run analysis on local or remote spec documents. 18 | package loads 19 | -------------------------------------------------------------------------------- /doc_test.go: -------------------------------------------------------------------------------- 1 | package loads_test 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os" 7 | "path/filepath" 8 | 9 | "github.com/go-openapi/loads" 10 | "github.com/go-openapi/swag" 11 | ) 12 | 13 | func ExampleSpec() { 14 | // Example with default loaders defined at the package level 15 | 16 | path := "fixtures/yaml/swagger/spec.yml" 17 | doc, err := loads.Spec(path) 18 | if err != nil { 19 | fmt.Println("Could not load this spec") 20 | return 21 | } 22 | 23 | fmt.Printf("Spec loaded: %q\n", doc.Host()) 24 | 25 | // Output: Spec loaded: "api.example.com" 26 | } 27 | 28 | func ExampleLoaderOption() { 29 | // Example with custom loaders passed as options 30 | 31 | path := "fixtures/yaml/swagger/spec.yml" 32 | 33 | // a simpler version of loads.JSONDoc 34 | jsonLoader := loads.NewDocLoaderWithMatch( 35 | func(pth string) (json.RawMessage, error) { 36 | buf, err := os.ReadFile(pth) 37 | return json.RawMessage(buf), err 38 | }, 39 | func(pth string) bool { 40 | return filepath.Ext(pth) == ".json" 41 | }, 42 | ) 43 | 44 | // equivalent to the default loader at the package level, which does: 45 | // 46 | // loads.AddLoader(swag.YAMLMatcher, swag.YAMLDoc) 47 | yamlLoader := loads.NewDocLoaderWithMatch( 48 | swag.YAMLDoc, 49 | func(pth string) bool { 50 | return filepath.Ext(pth) == ".yml" 51 | }, 52 | ) 53 | 54 | doc, err := loads.Spec(path, loads.WithDocLoaderMatches(jsonLoader, yamlLoader)) 55 | if err != nil { 56 | fmt.Println("Could not load this spec") 57 | return 58 | } 59 | 60 | fmt.Printf("Spec loaded: %q\n", doc.Host()) 61 | 62 | // Output: Spec loaded: "api.example.com" 63 | } 64 | -------------------------------------------------------------------------------- /errors.go: -------------------------------------------------------------------------------- 1 | package loads 2 | 3 | type loaderError string 4 | 5 | func (e loaderError) Error() string { 6 | return string(e) 7 | } 8 | 9 | const ( 10 | // ErrLoads is an error returned by the loads package 11 | ErrLoads loaderError = "loaderrs error" 12 | 13 | // ErrNoLoader indicates that no configured loader matched the input 14 | ErrNoLoader loaderError = "no loader matched" 15 | ) 16 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | package loads 2 | -------------------------------------------------------------------------------- /fixtures/bugs/145/Program Files (x86)/AppName/ref.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions": { 3 | "todo-partial": { 4 | "title": "Todo Partial", 5 | "type": "object", 6 | "properties": { 7 | "name": { 8 | "type": "string" 9 | }, 10 | "completed": { 11 | "type": ["boolean", "null"] 12 | } 13 | }, 14 | "required": ["name", "completed"] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /fixtures/bugs/145/Program Files (x86)/AppName/todos.common.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0", 5 | "title": "To-do Demo", 6 | "description": 7 | "### Notes:\n\nThis OAS2 (Swagger 2) specification defines common models and responses, that other specifications may reference.\n\nFor example, check out the user poperty in the main.oas2 todo-partial model - it references the user model in this specification!\n\nLikewise, the main.oas2 operations reference the shared error responses in this common specification.", 8 | "contact": { 9 | "name": "Stoplight", 10 | "url": "https://stoplight.io" 11 | }, 12 | "license": { 13 | "name": "MIT" 14 | } 15 | }, 16 | "host": "example.com", 17 | "securityDefinitions": {}, 18 | "paths": {}, 19 | "responses": { 20 | "401": { 21 | "description": "", 22 | "schema": { 23 | "$ref": "#/definitions/error-response" 24 | }, 25 | "examples": { 26 | "application/json": { 27 | "status": "401", 28 | "error": "Not Authorized" 29 | } 30 | } 31 | }, 32 | "403": { 33 | "description": "", 34 | "schema": { 35 | "$ref": "#/definitions/error-response" 36 | }, 37 | "examples": { 38 | "application/json": { 39 | "status": "403", 40 | "error": "Forbbiden" 41 | } 42 | } 43 | }, 44 | "404": { 45 | "description": "", 46 | "schema": { 47 | "$ref": "#/definitions/error-response" 48 | }, 49 | "examples": { 50 | "application/json": { 51 | "status": "404", 52 | "error": "Not Found" 53 | } 54 | } 55 | }, 56 | "500": { 57 | "description": "", 58 | "schema": { 59 | "$ref": "#/definitions/error-response" 60 | }, 61 | "examples": { 62 | "application/json": { 63 | "status": "500", 64 | "error": "Server Error" 65 | } 66 | } 67 | } 68 | }, 69 | "definitions": { 70 | "user": { 71 | "title": "User", 72 | "type": "object", 73 | "properties": { 74 | "name": { 75 | "type": "string", 76 | "description": "The user's full name." 77 | }, 78 | "age": { 79 | "type": "number", 80 | "minimum": 0, 81 | "maximum": 150 82 | }, 83 | "error": { 84 | "$ref": "#/definitions/error-response" 85 | } 86 | }, 87 | "required": ["name", "age"] 88 | }, 89 | "error-response": { 90 | "type": "object", 91 | "title": "Error Response", 92 | "properties": { 93 | "status": { 94 | "type": "string" 95 | }, 96 | "error": { 97 | "type": "string" 98 | } 99 | }, 100 | "required": ["status", "error"] 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /fixtures/json/models/modelWithArrayRef.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": [ 3 | "id" 4 | ], 5 | "properties": { 6 | "id": { 7 | "type": "integer", 8 | "format": "int64" 9 | }, 10 | "children": { 11 | "type": "array", 12 | "items": { 13 | "$ref": "Person" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /fixtures/json/models/modelWithComposition.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions": { 3 | "Cat": { 4 | "description": "A representation of a cat", 5 | "allOf": [ 6 | { "$ref": "#/models/Pet" }, 7 | { 8 | "properties": { 9 | "huntingSkill": { 10 | "type": "string", 11 | "description": "The measured skill for hunting", 12 | "default": "lazy", 13 | "enum": ["clueless", "lazy", "adventerous", "aggressive"] 14 | } 15 | }, 16 | "required": [ "huntingSkill" ] 17 | } 18 | ] 19 | }, 20 | "Dog": { 21 | "description": "A representation of a dog", 22 | "allOf": [ 23 | { "$ref": "#/models/Pet" }, 24 | { 25 | "properties": { 26 | "packSize": { 27 | "type": "integer", 28 | "format": "int32", 29 | "description": "the size of the pack the dog is from", 30 | "default": 0, 31 | "minimum": 0 32 | } 33 | }, 34 | "required": [ "name", "packSize" ] 35 | } 36 | ] 37 | }, 38 | "Fish": { 39 | "description": "A representation of a fish", 40 | "allOf": [ 41 | { "$ref": "#/models/Pet" }, 42 | { 43 | "properties": { 44 | "fins": { 45 | "type": "integer", 46 | "format": "int32", 47 | "description": "count of fins", 48 | "minimum": 0 49 | } 50 | }, 51 | "required": [ "fins" ] 52 | } 53 | ] 54 | }, 55 | "Pet": { 56 | "discriminator": "petType", 57 | "properties": { 58 | "name": { 59 | "type": "string" 60 | }, 61 | "petType": { 62 | "type": "string" 63 | } 64 | }, 65 | "required": [ "name", "petType" ] 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /fixtures/json/models/modelWithDateTimeMap.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "true", 3 | "additionalProperties": { 4 | "type": "string", 5 | "format": "date-time" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/models/modelWithExamples.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions": { 3 | "Pet": { 4 | "properties": { 5 | "name": { 6 | "type": "string" 7 | } 8 | }, 9 | "required": [ 10 | "name" 11 | ] 12 | }, 13 | "Dog": { 14 | "properties": { 15 | "id": { 16 | "type": "integer", 17 | "format": "int64" 18 | }, 19 | "name": { 20 | "type": "string" 21 | } 22 | }, 23 | "required": [ 24 | "name" 25 | ] 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /fixtures/json/models/modelWithInt32Map.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "This is a Map[String, Integer]", 3 | "additionalProperties": { 4 | "type": "integer", 5 | "format": "int32" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /fixtures/json/models/modelWithInt64Map.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "true", 3 | "additionalProperties": { 4 | "type": "integer", 5 | "format": "int64" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/models/modelWithMultipleProperties.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "true", 3 | "properties": { 4 | "booleanValue": { 5 | "type": "boolean" 6 | }, 7 | "byteValue": { 8 | "type": "string", 9 | "format": "byte" 10 | }, 11 | "dateTimeValue": { 12 | "type": "string", 13 | "format": "date-time" 14 | }, 15 | "int32Value": { 16 | "type": "integer", 17 | "format": "int32" 18 | }, 19 | "int64Value": { 20 | "type": "integer", 21 | "format": "int64" 22 | }, 23 | "stringValue": { 24 | "type": "string" 25 | }, 26 | "booleanArrayValue": { 27 | "type": "array", 28 | "items": { 29 | "type": "boolean" 30 | } 31 | }, 32 | "byteArrayValue": { 33 | "type": "array", 34 | "items": { 35 | "type": "string", 36 | "format": "byte" 37 | } 38 | }, 39 | "dateTimeArrayValue": { 40 | "type": "array", 41 | "items": { 42 | "type": "string", 43 | "format": "date-time" 44 | } 45 | }, 46 | "int32ArrayValue": { 47 | "type": "array", 48 | "items": { 49 | "type": "integer", 50 | "format": "int32" 51 | } 52 | }, 53 | "int64ArrayValue": { 54 | "type": "array", 55 | "items": { 56 | "type": "integer", 57 | "format": "int64" 58 | } 59 | }, 60 | "stringArrayValue": { 61 | "type": "array", 62 | "items": { 63 | "type": "string" 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /fixtures/json/models/modelWithObjectMap.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "This is a Map[String, { id: Long, name: String}]", 3 | "additionalProperties": { 4 | "type": "object", 5 | "properties": { 6 | "id": { 7 | "type": "integer", 8 | "format": "int64" 9 | }, 10 | "name": { 11 | "type": "string" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /fixtures/json/models/modelWithPrimitiveArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": [ 3 | "id" 4 | ], 5 | "properties": { 6 | "id": { 7 | "type": "integer", 8 | "format": "int64" 9 | }, 10 | "childrensAges": { 11 | "type": "array", 12 | "items": { 13 | "type": "integer", 14 | "format": "int32" 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /fixtures/json/models/modelWithStringProperty.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "true", 3 | "properties": { 4 | "name": { 5 | "type": "string" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /fixtures/json/models/modelWithXmlAttributes.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "this model serves xml and json structures", 3 | "xml": { 4 | "name": "XMLModel" 5 | }, 6 | "properties": { 7 | "id": { 8 | "type": "integer", 9 | "format": "int64", 10 | "xml": { 11 | "attribute": true, 12 | "namespace": "ns1", 13 | "prefix": "urn1" 14 | } 15 | }, 16 | "items": { 17 | "type": "array", 18 | "items": { 19 | "type": "string" 20 | }, 21 | "xml": { 22 | "wrapped": true 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /fixtures/json/models/models.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions": { 3 | "Pet": { 4 | "properties": { 5 | "name": { 6 | "type": "string" 7 | } 8 | }, 9 | "required": [ 10 | "name" 11 | ] 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /fixtures/json/models/multipleModels.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions": { 3 | "Pet": { 4 | "properties": { 5 | "name": { 6 | "type": "string" 7 | } 8 | }, 9 | "required": [ 10 | "name" 11 | ] 12 | }, 13 | "Dog": { 14 | "properties": { 15 | "id": { 16 | "type": "integer", 17 | "format": "int64" 18 | }, 19 | "name": { 20 | "type": "string" 21 | } 22 | }, 23 | "required": [ 24 | "name" 25 | ] 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithBooleanArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "boolean" 5 | } 6 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithByteArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "string", 5 | "format": "byte" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithComplexArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "$ref": "ComplexType" 5 | } 6 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithDateTimeArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "string", 5 | "format": "date-time" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithInt32Array.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "integer", 5 | "format": "int32" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithInt64Array.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "integer", 5 | "format": "int64" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithRef.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "Foo", 3 | "description": "a boolean", 4 | "readOnly": true 5 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/propertyWithStringArray.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "items": { 4 | "type": "string" 5 | } 6 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/simpleBooleanProperty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "boolean", 3 | "description": "a boolean", 4 | "readOnly": true 5 | } 6 | -------------------------------------------------------------------------------- /fixtures/json/models/properties/simpleByteProperty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "string", 3 | "format": "byte" 4 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/simpleDateTimeProperty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "string", 3 | "format": "date-time" 4 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/simpleInt32Property.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "integer", 3 | "format": "int32" 4 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/simpleInt64Property.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "integer", 3 | "format": "int64" 4 | } -------------------------------------------------------------------------------- /fixtures/json/models/properties/simpleStringProperty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "string" 3 | } 4 | -------------------------------------------------------------------------------- /fixtures/json/resources/cascadingSchemes.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json", 28 | "application/xml" 29 | ], 30 | "paths": { 31 | "/pets/{petId}": { 32 | "get": { 33 | "description": "Returns a pet based on ID", 34 | "summary": "Find pet by ID", 35 | "operationId": "getPetsById", 36 | "produces": [ 37 | "application/json", 38 | "text/html" 39 | ], 40 | "parameters": [ 41 | { 42 | "name": "petId", 43 | "in": "path", 44 | "description": "ID of pet that needs to be fetched", 45 | "required": true, 46 | "type": "array", 47 | "items": { 48 | "type": "string" 49 | }, 50 | "collectionFormat": "csv" 51 | } 52 | ], 53 | "responses": { 54 | "200": { 55 | "description": "pet response", 56 | "schema": { 57 | "$ref": "Pet" 58 | } 59 | }, 60 | "default": { 61 | "description": "error payload", 62 | "schema": { 63 | "$ref": "ErrorModel" 64 | } 65 | } 66 | }, 67 | "schemes": [ "https" ] 68 | } 69 | } 70 | }, 71 | "definitions": { 72 | "Pet": { 73 | "required": [ 74 | "name" 75 | ], 76 | "properties": { 77 | "name": { 78 | "type": "string" 79 | }, 80 | "tag": { 81 | "type": "string" 82 | } 83 | } 84 | }, 85 | "ErrorModel": { 86 | "required": [ "code", "message" ], 87 | "properties": { 88 | "code": { 89 | "type": "integer", 90 | "format": "int32" 91 | }, 92 | "message": { 93 | "type": "string" 94 | } 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /fixtures/json/resources/commonParameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json", 28 | "application/xml" 29 | ], 30 | "paths": { 31 | "/pets/{id}": { 32 | "parameters": [ 33 | { 34 | "name": "id", 35 | "in": "path", 36 | "description": "ID of pet to use", 37 | "required": true, 38 | "type": "array", 39 | "items": { 40 | "type": "string" 41 | }, 42 | "collectionFormat": "csv" 43 | } 44 | ], 45 | "get": { 46 | "description": "Returns pets based on ID", 47 | "summary": "Find pets by ID", 48 | "operationId": "getPetsById", 49 | "produces": [ 50 | "application/json", 51 | "text/html" 52 | ], 53 | "responses": { 54 | "200": { 55 | "description": "pet response", 56 | "schema": { 57 | "type": "array", 58 | "items": { 59 | "$ref": "Pet" 60 | } 61 | } 62 | }, 63 | "default": { 64 | "description": "error payload", 65 | "schema": { 66 | "$ref": "ErrorModel" 67 | } 68 | } 69 | } 70 | } 71 | } 72 | }, 73 | "definitions": { 74 | "Pet": { 75 | "required": [ 76 | "name" 77 | ], 78 | "properties": { 79 | "name": { 80 | "type": "string" 81 | }, 82 | "tag": { 83 | "type": "string" 84 | } 85 | } 86 | }, 87 | "ErrorModel": { 88 | "required": [ "code", "message" ], 89 | "properties": { 90 | "code": { 91 | "type": "integer", 92 | "format": "int32" 93 | }, 94 | "message": { 95 | "type": "string" 96 | } 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /fixtures/json/resources/multipleMimeTypes.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "text/plain; charset=utf-8", 25 | "application/json", 26 | "application/vnd.github+json", 27 | "application/vnd.github.v3+json", 28 | "application/vnd.github.v3.raw+json", 29 | "application/vnd.github.v3.text+json", 30 | "application/vnd.github.v3.html+json", 31 | "application/vnd.github.v3.full+json", 32 | "application/vnd.github.v3.diff", 33 | "application/vnd.github.v3.patch" 34 | ], 35 | "produces": [ 36 | "application/json", 37 | "application/xml" 38 | ], 39 | "paths": { 40 | "/pets/{id}": { 41 | "parameters": [ 42 | { 43 | "name": "id", 44 | "in": "path", 45 | "description": "ID of pet to use", 46 | "required": true, 47 | "type": "array", 48 | "items": { 49 | "type": "string" 50 | }, 51 | "collectionFormat": "csv" 52 | } 53 | ], 54 | "get": { 55 | "description": "Returns pets based on ID", 56 | "summary": "Find pets by ID", 57 | "operationId": "getPetsById", 58 | "produces": [ 59 | "application/json", 60 | "text/html" 61 | ], 62 | "responses": { 63 | "200": { 64 | "description": "pet response", 65 | "schema": { 66 | "type": "array", 67 | "items": { 68 | "$ref": "Pet" 69 | } 70 | } 71 | }, 72 | "default": { 73 | "description": "error payload", 74 | "schema": { 75 | "$ref": "ErrorModel" 76 | } 77 | } 78 | } 79 | } 80 | } 81 | }, 82 | "definitions": { 83 | "Pet": { 84 | "required": [ 85 | "name" 86 | ], 87 | "properties": { 88 | "name": { 89 | "type": "string" 90 | }, 91 | "tag": { 92 | "type": "string" 93 | } 94 | } 95 | }, 96 | "ErrorModel": { 97 | "required": [ "code", "message" ], 98 | "properties": { 99 | "code": { 100 | "type": "integer", 101 | "format": "int32" 102 | }, 103 | "message": { 104 | "type": "string" 105 | } 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /fixtures/json/resources/operations/operationWithTags.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Returns a pet based on ID", 3 | "summary": "Find pet by ID", 4 | "operationId": "getPetsById", 5 | "tags": [ "foo", "bar"], 6 | "produces": [ 7 | "application/json", 8 | "text/html" 9 | ], 10 | "parameters": [ 11 | { 12 | "name": "petId", 13 | "in": "path", 14 | "description": "ID of pet that needs to be fetched", 15 | "required": true, 16 | "type": "integer", 17 | "format": "int64" 18 | } 19 | ], 20 | "responses": { 21 | "200": { 22 | "description": "a pet to be returned", 23 | "schema": {"$ref": "Pet"} 24 | }, 25 | "default": { 26 | "description": "Unexpected error", 27 | "schema": {"$ref": "ErrorModel"} 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /fixtures/json/resources/operations/stringPathAndBoolQueryParamResource.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Returns a pet based on ID", 3 | "summary": "Find pet by ID", 4 | "operationId": "getPetsById", 5 | "produces": [ 6 | "application/json", 7 | "text/html" 8 | ], 9 | "parameters": [ 10 | { 11 | "name": "petId", 12 | "in": "path", 13 | "description": "ID of pet that needs to be fetched", 14 | "required": true, 15 | "type": "integer", 16 | "format": "int64" 17 | }, 18 | { 19 | "name": "includeDetails", 20 | "in": "query", 21 | "description": "include details in response", 22 | "required": true, 23 | "type": "boolean" 24 | } 25 | ], 26 | "responses": { 27 | "200": { 28 | "description": "a pet to be returned", 29 | "schema": {"$ref": "Pet"} 30 | }, 31 | "default": { 32 | "description": "Unexpected error", 33 | "schema": {"$ref": "ErrorModel"} 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /fixtures/json/resources/operations/stringPathParamResource.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Returns a pet based on ID", 3 | "summary": "Find pet by ID", 4 | "operationId": "getPetsById", 5 | "produces": [ 6 | "application/json", 7 | "text/html" 8 | ], 9 | "parameters": [ 10 | { 11 | "name": "petId", 12 | "in": "path", 13 | "description": "ID of pet that needs to be fetched", 14 | "required": true, 15 | "type": "integer", 16 | "format": "int64" 17 | } 18 | ], 19 | "responses": { 20 | "200": { 21 | "description": "fun", 22 | "schema": {"$ref": "Pet"} 23 | }, 24 | "400": { 25 | "description": "Invalid ID supplied <= this is purely for documentation", 26 | "schema": {"$ref": "ErrorModel"} 27 | }, 28 | "default": { 29 | "description": "Unexpected error", 30 | "schema": {"$ref": "ErrorModel"} 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/bodyComplexArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "user", 3 | "in": "body", 4 | "description": "user to add to the system", 5 | "required": true, 6 | "schema": { 7 | "type": "array", 8 | "items": { 9 | "type": "string" 10 | }, 11 | "format": "csv" 12 | } 13 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/bodyComplexParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "user", 3 | "in": "body", 4 | "description": "user to add to the system", 5 | "required": true, 6 | "schema": { 7 | "$ref": "User" 8 | } 9 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/bodyInt64Parameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "id", 3 | "in": "body", 4 | "description": "id to add", 5 | "required": true, 6 | "schema": { 7 | "type": "integer", 8 | "format": "int64" 9 | } 10 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/bodyStringArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "user", 3 | "in": "body", 4 | "description": "user to add to the system", 5 | "required": true, 6 | "schema": { 7 | "type": "array", 8 | "items": { 9 | "type": "string" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/bodyStringParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "user", 3 | "in": "body", 4 | "description": "user to add to the system", 5 | "required": true, 6 | "schema": { 7 | "type": "string" 8 | } 9 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/formDataComplexParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firstName", 3 | "in": "formData", 4 | "description": "users first name", 5 | "required": true, 6 | "$ref": "Nothing" 7 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/formDataInt64Parameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "id", 3 | "in": "formData", 4 | "description": "username to fetch", 5 | "required": true, 6 | "type": "integer", 7 | "format": "int64" 8 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/formDataStringArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "user", 3 | "in": "formData", 4 | "description": "user to add to the system", 5 | "required": true, 6 | "type": "array", 7 | "items": { 8 | "type": "string" 9 | } 10 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/formDataStringParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "firstName", 3 | "in": "formData", 4 | "description": "users first name", 5 | "required": true, 6 | "type": "string" 7 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/headerInt64ArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "token", 3 | "in": "header", 4 | "description": "token to be passed as a header", 5 | "required": true, 6 | "type": "array", 7 | "items": { 8 | "type": "integer", 9 | "format": "int64" 10 | }, 11 | "collectionFormat": "csv" 12 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/headerStringArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "token", 3 | "in": "header", 4 | "description": "token to be passed as a header", 5 | "required": true, 6 | "type": "array", 7 | "items": { 8 | "type": "string" 9 | }, 10 | "collectionFormat": "csv" 11 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/headerStringParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "token", 3 | "in": "header", 4 | "description": "token to be passed as a header", 5 | "required": true, 6 | "type": "string" 7 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/pathInt64Parameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "id", 3 | "in": "path", 4 | "description": "username to fetch", 5 | "required": true, 6 | "type": "integer", 7 | "format": "int64" 8 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/pathStringArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "usernames", 3 | "in": "path", 4 | "description": "usernames to pass", 5 | "required": true, 6 | "type": "array", 7 | "items": { 8 | "type": "string" 9 | }, 10 | "collectionFormat": "csv" 11 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/pathStringParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "username", 3 | "in": "path", 4 | "description": "username to fetch", 5 | "required": true, 6 | "type": "string" 7 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/queryInt64ArrayParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "id", 3 | "in": "query", 4 | "description": "ID of the object to fetch", 5 | "required": true, 6 | "type": "array", 7 | "items": { 8 | "type": "integer", 9 | "format": "int64" 10 | }, 11 | "collectionFormat": "csv" 12 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/queryStringParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "id", 3 | "in": "query", 4 | "description": "ID of the object to fetch", 5 | "required": true, 6 | "type": "integer", 7 | "format": "int64" 8 | } -------------------------------------------------------------------------------- /fixtures/json/resources/parameters/queryWithComplexParameter.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "id", 3 | "in": "query", 4 | "description": "a complex object which should not validate", 5 | "required": true, 6 | "schema": { 7 | "$ref": "Pet" 8 | } 9 | } -------------------------------------------------------------------------------- /fixtures/json/resources/pathLoaderIssue.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "PartSearch Api", 5 | "description": "Search for Parts", 6 | "version": "v3" 7 | }, 8 | "host": "api.example.com", 9 | "paths": { 10 | "\/Products\/Keyword": { 11 | "post": { 12 | "consumes": [ 13 | "application\/json" 14 | ], 15 | "produces": [ 16 | "application\/json" 17 | ], 18 | "parameters": [ 19 | { 20 | "in": "body", 21 | "name": "body", 22 | "description": "KeywordSearchRequest", 23 | "schema": { 24 | "$ref" : "#/definitions/KeywordSearchRequest" 25 | } 26 | } 27 | ], 28 | "responses": { 29 | "200": { 30 | "description": "Success", 31 | "schema": { 32 | "description":"bla", 33 | "type": "string" 34 | } 35 | } 36 | } 37 | } 38 | } 39 | }, 40 | "definitions": { 41 | "KeywordSearchRequest": { 42 | "description": "Keyword Search Request object", 43 | "type": "string" 44 | }, 45 | "KeywordSearchResponse": { 46 | "description": "Response model for a keyword search request.", 47 | "type": "string" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /fixtures/json/resources/resourceWithExamplePayload.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json", 28 | "application/xml" 29 | ], 30 | "paths": { 31 | "/pets/{petId}": { 32 | "get": { 33 | "description": "Returns a pet based on ID", 34 | "summary": "Find pet by ID", 35 | "operationId": "getPetsById", 36 | "produces": [ 37 | "application/json", 38 | "text/html" 39 | ], 40 | "parameters": [ 41 | { 42 | "name": "petId", 43 | "in": "path", 44 | "description": "ID of pet that needs to be fetched", 45 | "required": true, 46 | "type": "array", 47 | "items": { 48 | "type": "string" 49 | }, 50 | "collectionFormat": "csv" 51 | } 52 | ], 53 | "responses": { 54 | "200": { 55 | "description": "pet response", 56 | "schema": { 57 | "$ref": "Pet" 58 | }, 59 | "examples": { 60 | "application/json": { 61 | "id": 9, 62 | "category": { 63 | "name": "domestic" 64 | }, 65 | "name": "monster", 66 | "tags": [ 67 | { 68 | "name": "for sale" 69 | } 70 | ], 71 | "status": "alive" 72 | } 73 | } 74 | }, 75 | "default": { 76 | "description": "error payload", 77 | "schema": { 78 | "$ref": "ErrorModel" 79 | } 80 | } 81 | } 82 | } 83 | } 84 | }, 85 | "definitions": { 86 | "Pet": { 87 | "required": [ 88 | "name" 89 | ], 90 | "properties": { 91 | "name": { 92 | "type": "string", 93 | "example": "cat" 94 | }, 95 | "tag": { 96 | "type": "string", 97 | "example": "for sale" 98 | } 99 | } 100 | }, 101 | "ErrorModel": { 102 | "required": [ "code", "message" ], 103 | "properties": { 104 | "code": { 105 | "type": "integer", 106 | "format": "int32" 107 | }, 108 | "message": { 109 | "type": "string" 110 | } 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /fixtures/json/resources/resourceWithLinkedDefinitions.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json", 28 | "application/xml" 29 | ], 30 | "paths": { 31 | "/pets/{petId}": { 32 | "$ref": "https://raw.githubusercontent.com/reverb/swagger-spec/master/fixtures/v2.0/json/resources/resourceWithLinkedDefinitions_part1.json" 33 | } 34 | }, 35 | "definitions": { 36 | "Pet": { 37 | "required": [ 38 | "name" 39 | ], 40 | "properties": { 41 | "name": { 42 | "type": "string" 43 | }, 44 | "tag": { 45 | "type": "string" 46 | } 47 | } 48 | }, 49 | "ErrorModel": { 50 | "required": [ "code", "message" ], 51 | "properties": { 52 | "code": { 53 | "type": "integer", 54 | "format": "int32" 55 | }, 56 | "message": { 57 | "type": "string" 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /fixtures/json/resources/resourceWithLinkedDefinitions_part1.json: -------------------------------------------------------------------------------- 1 | { 2 | "get": { 3 | "description": "Returns a pet based on ID", 4 | "summary": "Find pet by ID", 5 | "operationId": "getPetsById", 6 | "produces": [ 7 | "application/json", 8 | "text/html" 9 | ], 10 | "parameters": [ 11 | { 12 | "name": "petId", 13 | "in": "path", 14 | "description": "ID of pet that needs to be fetched", 15 | "required": true, 16 | "type": "array", 17 | "items": { 18 | "type": "string" 19 | }, 20 | "collectionFormat": "csv" 21 | } 22 | ], 23 | "responses": { 24 | "200": { 25 | "description": "pet response", 26 | "schema": { 27 | "$ref": "Pet" 28 | } 29 | }, 30 | "default": { 31 | "description": "error payload", 32 | "schema": { 33 | "$ref": "ErrorModel" 34 | } 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /fixtures/json/resources/resourceWithRelativeHost.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "basePath": "/v1", 18 | "schemes": [ 19 | "http", 20 | "https" 21 | ], 22 | "consumes": [ 23 | "application/json" 24 | ], 25 | "produces": [ 26 | "application/json", 27 | "application/xml" 28 | ], 29 | "paths": { 30 | "/pets/{id}": { 31 | "parameters": [ 32 | { 33 | "name": "id", 34 | "in": "path", 35 | "description": "ID of pet to use", 36 | "required": true, 37 | "type": "array", 38 | "items": { 39 | "type": "string" 40 | }, 41 | "collectionFormat": "csv" 42 | } 43 | ], 44 | "get": { 45 | "description": "Returns pets based on ID", 46 | "summary": "Find pets by ID", 47 | "operationId": "getPetsById", 48 | "produces": [ 49 | "application/json", 50 | "text/html" 51 | ], 52 | "responses": { 53 | "200": { 54 | "description": "pet response", 55 | "schema": { 56 | "type": "array", 57 | "items": { 58 | "$ref": "Pet" 59 | } 60 | } 61 | }, 62 | "default": { 63 | "description": "error payload", 64 | "schema": { 65 | "$ref": "ErrorModel" 66 | } 67 | } 68 | } 69 | } 70 | } 71 | }, 72 | "definitions": { 73 | "Pet": { 74 | "required": [ 75 | "name" 76 | ], 77 | "properties": { 78 | "name": { 79 | "type": "string" 80 | }, 81 | "tag": { 82 | "type": "string" 83 | } 84 | } 85 | }, 86 | "ErrorModel": { 87 | "required": [ "code", "message" ], 88 | "properties": { 89 | "code": { 90 | "type": "integer", 91 | "format": "int32" 92 | }, 93 | "message": { 94 | "type": "string" 95 | } 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /fixtures/json/resources/reusableParameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json", 28 | "application/xml" 29 | ], 30 | "paths": { 31 | "/pets/{id}": { 32 | "get": { 33 | "description": "Returns pets based on ID", 34 | "summary": "Find pets by ID", 35 | "operationId": "getPetsById", 36 | "parameters": [ 37 | { "$ref": "#/parameters/skipParam" }, 38 | { "$ref": "#/parameters/limitParam" } 39 | ], 40 | "responses": { 41 | "200": { 42 | "description": "pet response", 43 | "schema": { 44 | "type": "array", 45 | "items": { 46 | "$ref": "Pet" 47 | } 48 | } 49 | }, 50 | "default": { 51 | "description": "error payload", 52 | "schema": { 53 | "$ref": "ErrorModel" 54 | } 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "parameters": { 61 | "skipParam": { 62 | "name": "skip", 63 | "in": "query", 64 | "description": "number of items to skip", 65 | "required": true, 66 | "type": "integer", 67 | "format": "int32" 68 | }, 69 | "limitParam": { 70 | "name": "limit", 71 | "in": "query", 72 | "description": "max records to return", 73 | "required": true, 74 | "type": "integer", 75 | "format": "int32" 76 | } 77 | }, 78 | "definitions": { 79 | "Pet": { 80 | "required": [ 81 | "name" 82 | ], 83 | "properties": { 84 | "name": { 85 | "type": "string" 86 | }, 87 | "tag": { 88 | "type": "string" 89 | } 90 | } 91 | }, 92 | "ErrorModel": { 93 | "required": [ "code", "message" ], 94 | "properties": { 95 | "code": { 96 | "type": "integer", 97 | "format": "int32" 98 | }, 99 | "message": { 100 | "type": "string" 101 | } 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /fixtures/json/resources/securityExample.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "basePath": "/v1", 18 | "schemes": [ 19 | "http", 20 | "https" 21 | ], 22 | "consumes": [ 23 | "application/json" 24 | ], 25 | "produces": [ 26 | "application/json", 27 | "application/xml" 28 | ], 29 | "security": [ 30 | { 31 | "githubAccessCode": [ "user", "gist" ] 32 | }, 33 | { 34 | "internalApiKey": [] 35 | } 36 | ], 37 | "paths": { 38 | "/pets/{id}": { 39 | "parameters": [ 40 | { 41 | "name": "id", 42 | "in": "path", 43 | "description": "ID of pet to use", 44 | "required": true, 45 | "type": "array", 46 | "items": { 47 | "type": "string" 48 | }, 49 | "collectionFormat": "csv" 50 | } 51 | ], 52 | "get": { 53 | "description": "Returns pets based on ID", 54 | "summary": "Find pets by ID", 55 | "operationId": "getPetsById", 56 | "security": [ 57 | { 58 | "githubAuth":[ 59 | "user:read", 60 | "user:write" 61 | ] 62 | }, 63 | { 64 | "internalApiKey": [] 65 | } 66 | ], 67 | "produces": [ 68 | "application/json", 69 | "text/html" 70 | ], 71 | "responses": { 72 | "200": { 73 | "description": "pet response", 74 | "schema": { 75 | "type": "array", 76 | "items": { 77 | "$ref": "Pet" 78 | } 79 | } 80 | }, 81 | "default": { 82 | "description": "error payload", 83 | "schema": { 84 | "$ref": "ErrorModel" 85 | } 86 | } 87 | } 88 | } 89 | } 90 | }, 91 | "securityDefinitions": { 92 | "githubAccessCode": { 93 | "type": "oauth2", 94 | "scopes": { 95 | "user": "Grants read/write access to profile info only. Note that this scope includes user:email and user:follow.", 96 | "user:email": "Grants read access to a user’s email addresses.", 97 | "user:follow": "Grants access to follow or unfollow other users.", 98 | "public_repo": "Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations.", 99 | "repo": "Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations.", 100 | "repo_deployment": "Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.", 101 | "repo:status": "Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.", 102 | "delete_repo": "Grants access to delete adminable repositories.", 103 | "notifications": "Grants read access to a user’s notifications. repo also provides this access.", 104 | "gist": "Grants write access to gists.", 105 | "read:repo_hook": "Grants read and ping access to hooks in public or private repositories.", 106 | "write:repo_hook": "Grants read, write, and ping access to hooks in public or private repositories.", 107 | "admin:repo_hook": "Grants read, write, ping, and delete access to hooks in public or private repositories.", 108 | "read:org": "Read-only access to organization, teams, and membership.", 109 | "write:org": "Publicize and unpublicize organization membership.", 110 | "admin:org": "Fully manage organization, teams, and memberships.", 111 | "read:public_key": "List and view details for public keys.", 112 | "write:public_key": "Create, list, and view details for public keys.", 113 | "admin:public_key": "Fully manage public keys." 114 | }, 115 | "flow": "accessCode", 116 | "authorizationUrl": "https://github.com/login/oauth/authorize", 117 | "tokenUrl": "https://github.com/login/oauth/access_token" 118 | }, 119 | "petstoreImplicit": { 120 | "type": "oauth2", 121 | "scopes": { 122 | "user": "Grants read/write access to profile info only. Note that this scope includes user:email and user:follow.", 123 | "user:email": "Grants read access to a user’s email addresses.", 124 | "user:follow": "Grants access to follow or unfollow other users.", 125 | "public_repo": "Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations.", 126 | "repo": "Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations.", 127 | "repo_deployment": "Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.", 128 | "repo:status": "Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.", 129 | "delete_repo": "Grants access to delete adminable repositories.", 130 | "notifications": "Grants read access to a user’s notifications. repo also provides this access.", 131 | "gist": "Grants write access to gists.", 132 | "read:repo_hook": "Grants read and ping access to hooks in public or private repositories.", 133 | "write:repo_hook": "Grants read, write, and ping access to hooks in public or private repositories.", 134 | "admin:repo_hook": "Grants read, write, ping, and delete access to hooks in public or private repositories.", 135 | "read:org": "Read-only access to organization, teams, and membership.", 136 | "write:org": "Publicize and unpublicize organization membership.", 137 | "admin:org": "Fully manage organization, teams, and memberships.", 138 | "read:public_key": "List and view details for public keys.", 139 | "write:public_key": "Create, list, and view details for public keys.", 140 | "admin:public_key": "Fully manage public keys." 141 | }, 142 | "flow": "implicit", 143 | "authorizationUrl": "http://petstore.swagger.wordnik.com/oauth/dialog" 144 | }, 145 | "internalApiKey": { 146 | "type": "apiKey", 147 | "in": "header", 148 | "name": "api_key" 149 | } 150 | }, 151 | "definitions": { 152 | "Pet": { 153 | "required": [ 154 | "name" 155 | ], 156 | "properties": { 157 | "name": { 158 | "type": "string" 159 | }, 160 | "tag": { 161 | "type": "string" 162 | } 163 | } 164 | }, 165 | "ErrorModel": { 166 | "required": [ 167 | "code", 168 | "message" 169 | ], 170 | "properties": { 171 | "code": { 172 | "type": "integer", 173 | "format": "int32" 174 | }, 175 | "message": { 176 | "type": "string" 177 | } 178 | } 179 | } 180 | } 181 | } -------------------------------------------------------------------------------- /fixtures/json/resources/stringPathParamResource.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "version": "1.0.9-abcd", 5 | "title": "Swagger Sample API", 6 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 7 | "termsOfService": "http://helloreverb.com/terms/", 8 | "contact": { 9 | "name": "wordnik api team", 10 | "url": "http://developer.wordnik.com" 11 | }, 12 | "license": { 13 | "name": "Creative Commons 4.0 International", 14 | "url": "http://creativecommons.org/licenses/by/4.0/" 15 | } 16 | }, 17 | "host": "my.api.com", 18 | "basePath": "/v1", 19 | "schemes": [ 20 | "http", 21 | "https" 22 | ], 23 | "consumes": [ 24 | "application/json" 25 | ], 26 | "produces": [ 27 | "application/json", 28 | "application/xml" 29 | ], 30 | "paths": { 31 | "/pets/{petId}": { 32 | "get": { 33 | "description": "Returns a pet based on ID", 34 | "summary": "Find pet by ID", 35 | "operationId": "getPetsById", 36 | "produces": [ 37 | "application/json", 38 | "text/html" 39 | ], 40 | "parameters": [ 41 | { 42 | "name": "petId", 43 | "in": "path", 44 | "description": "ID of pet that needs to be fetched", 45 | "required": true, 46 | "type": "array", 47 | "items": { 48 | "type": "string" 49 | }, 50 | "collectionFormat": "csv" 51 | } 52 | ], 53 | "responses": { 54 | "200": { 55 | "description": "pet response", 56 | "schema": { 57 | "$ref": "Pet" 58 | } 59 | }, 60 | "default": { 61 | "description": "error payload", 62 | "schema": { 63 | "$ref": "ErrorModel" 64 | } 65 | } 66 | } 67 | } 68 | } 69 | }, 70 | "definitions": { 71 | "Pet": { 72 | "required": [ 73 | "name" 74 | ], 75 | "properties": { 76 | "name": { 77 | "type": "string" 78 | }, 79 | "tag": { 80 | "type": "string" 81 | } 82 | } 83 | }, 84 | "ErrorModel": { 85 | "required": [ "code", "message" ], 86 | "properties": { 87 | "code": { 88 | "type": "integer", 89 | "format": "int32" 90 | }, 91 | "message": { 92 | "type": "string" 93 | } 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /fixtures/json/resources/taggedResource.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "x-reverb": { 4 | "addAnythingYouWant": true 5 | }, 6 | "info": { 7 | "x-reverb-info": "this is an example", 8 | "version": "1.0.9-abcd", 9 | "title": "Swagger Sample API", 10 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 11 | "termsOfService": "http://helloreverb.com/terms/", 12 | "contact": { 13 | "name": "wordnik api team", 14 | "url": "http://developer.wordnik.com" 15 | }, 16 | "license": { 17 | "name": "Creative Commons 4.0 International", 18 | "url": "http://creativecommons.org/licenses/by/4.0/" 19 | } 20 | }, 21 | "host": "my.api.com", 22 | "basePath": "/v1", 23 | "schemes": [ 24 | "http", 25 | "https" 26 | ], 27 | "consumes": [ 28 | "application/json" 29 | ], 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "tags": [ 35 | { 36 | "name": "pets" 37 | } 38 | ], 39 | "paths": { 40 | "x-reverb-path-info": "vendor info", 41 | "/pets": { 42 | "x-vendor-method": {}, 43 | "get": { 44 | "x-vendor-operation-property": {}, 45 | "description": "Returns a pet based on ID", 46 | "summary": "Find pet by ID", 47 | "operationId": "getPetsById", 48 | "produces": [ 49 | "application/json", 50 | "text/html" 51 | ], 52 | "parameters": [ 53 | { 54 | "x-vendor-parameter-property": {}, 55 | "name": "petId", 56 | "in": "path", 57 | "description": "ID of pet that needs to be fetched", 58 | "required": true, 59 | "type": "array", 60 | "items": { 61 | "type": "string" 62 | }, 63 | "collectionFormat": "csv" 64 | } 65 | ], 66 | "responses": { 67 | "x-vendor-operation-response-property": {}, 68 | "200": { 69 | "description": "pet response", 70 | "schema": { 71 | "$ref": "Pet" 72 | } 73 | }, 74 | "default": { 75 | "description": "error payload", 76 | "schema": { 77 | "$ref": "ErrorModel" 78 | } 79 | } 80 | } 81 | } 82 | } 83 | }, 84 | "definitions": { 85 | "Pet": { 86 | "x-vendor-model-property": {}, 87 | "required": [ 88 | "name" 89 | ], 90 | "properties": { 91 | "name": { 92 | "type": "string" 93 | }, 94 | "tag": { 95 | "type": "string" 96 | } 97 | } 98 | }, 99 | "ErrorModel": { 100 | "required": [ "code", "message" ], 101 | "properties": { 102 | "code": { 103 | "type": "integer", 104 | "format": "int32" 105 | }, 106 | "message": { 107 | "type": "string" 108 | } 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /fixtures/json/resources/vendorExtensionExamples.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "x-reverb": { 4 | "addAnythingYouWant": true 5 | }, 6 | "info": { 7 | "x-reverb-info": "this is an example", 8 | "version": "1.0.9-abcd", 9 | "title": "Swagger Sample API", 10 | "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", 11 | "termsOfService": "http://helloreverb.com/terms/", 12 | "contact": { 13 | "name": "wordnik api team", 14 | "url": "http://developer.wordnik.com" 15 | }, 16 | "license": { 17 | "name": "Creative Commons 4.0 International", 18 | "url": "http://creativecommons.org/licenses/by/4.0/" 19 | } 20 | }, 21 | "host": "my.api.com", 22 | "basePath": "/v1", 23 | "schemes": [ 24 | "http", 25 | "https" 26 | ], 27 | "consumes": [ 28 | "application/json" 29 | ], 30 | "produces": [ 31 | "application/json", 32 | "application/xml" 33 | ], 34 | "paths": { 35 | "x-reverb-path-info": "vendor info", 36 | "/pets": { 37 | "x-vendor-method": {}, 38 | "get": { 39 | "x-vendor-operation-property": {}, 40 | "description": "Returns a pet based on ID", 41 | "summary": "Find pet by ID", 42 | "operationId": "getPetsById", 43 | "produces": [ 44 | "application/json", 45 | "text/html" 46 | ], 47 | "parameters": [ 48 | { 49 | "x-vendor-parameter-property": {}, 50 | "name": "petId", 51 | "in": "path", 52 | "description": "ID of pet that needs to be fetched", 53 | "required": true, 54 | "type": "array", 55 | "items": { 56 | "type": "string" 57 | }, 58 | "collectionFormat": "csv" 59 | } 60 | ], 61 | "responses": { 62 | "x-vendor-operation-response-property": {}, 63 | "200": { 64 | "description": "pet response", 65 | "schema": { 66 | "$ref": "Pet" 67 | } 68 | }, 69 | "default": { 70 | "description": "error payload", 71 | "schema": { 72 | "$ref": "ErrorModel" 73 | } 74 | } 75 | } 76 | } 77 | } 78 | }, 79 | "definitions": { 80 | "Pet": { 81 | "x-vendor-model-property": {}, 82 | "required": [ 83 | "name" 84 | ], 85 | "properties": { 86 | "name": { 87 | "type": "string" 88 | }, 89 | "tag": { 90 | "type": "string" 91 | } 92 | } 93 | }, 94 | "ErrorModel": { 95 | "required": [ "code", "message" ], 96 | "properties": { 97 | "code": { 98 | "type": "integer", 99 | "format": "int32" 100 | }, 101 | "message": { 102 | "type": "string" 103 | } 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /fixtures/json/responses/complexArrayResponse.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A complex object array response", 3 | "schema": { 4 | "type": "array", 5 | "items": { 6 | "$ref": "VeryComplexType" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /fixtures/json/responses/dateTimeResponse.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A date-time response", 3 | "schema": { 4 | "type": "string", 5 | "format": "date-time" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/responses/int32Response.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A simple string response", 3 | "schema": { 4 | "type": "integer", 5 | "format": "int32" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/responses/int64Response.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A simple string response", 3 | "schema": { 4 | "type": "integer", 5 | "format": "int64" 6 | } 7 | } -------------------------------------------------------------------------------- /fixtures/json/responses/multipleResponses.json: -------------------------------------------------------------------------------- 1 | { 2 | "200": { 3 | "description": "simple string response", 4 | "schema": { 5 | "type": "string" 6 | } 7 | }, 8 | "201": { 9 | "description": "object created" 10 | }, 11 | "default": { 12 | "description": "oops", 13 | "schema": { 14 | "type": "integer", 15 | "format": "int32" 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /fixtures/json/responses/stringArrayResponse.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A string array response", 3 | "schema": { 4 | "type": "array", 5 | "items": { 6 | "type": "string" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /fixtures/json/responses/stringResponse.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A simple string response", 3 | "schema": { 4 | "type": "string" 5 | } 6 | } -------------------------------------------------------------------------------- /fixtures/json/responses/stringResponseWithHeader.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "A simple string response", 3 | "schema": { 4 | "type": "string" 5 | }, 6 | "headers": { 7 | "is-dog": {"type": "boolean"}, 8 | "is-cat": {"type": "boolean"} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /fixtures/json/responses/voidResponse.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "object created" 3 | } -------------------------------------------------------------------------------- /fixtures/yaml/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/go-openapi/loads/1afdd18ac3d8eee37f59f8e358fb079f246467ae/fixtures/yaml/.gitkeep -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithArrayRef.yaml: -------------------------------------------------------------------------------- 1 | required: 2 | - id 3 | properties: 4 | id: {type: integer, format: int64} 5 | children: {type: array, items: {$ref: Person}} 6 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithComposition.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Cat: {description: 'A representation of a cat', allOf: [{$ref: '#/models/Pet'}, {properties: {huntingSkill: {type: string, description: 'The measured skill for hunting', default: lazy, enum: [clueless, lazy, adventerous, aggressive]}}, required: [huntingSkill]}]} 3 | Dog: {description: 'A representation of a dog', allOf: [{$ref: '#/models/Pet'}, {properties: {packSize: {type: integer, format: int32, description: 'the size of the pack the dog is from', default: 0}}, required: [name, packSize]}]} 4 | Fish: {description: 'A representation of a fish', allOf: [{$ref: '#/models/Pet'}, {properties: {fins: {type: integer, format: int32, description: 'count of fins'}}, required: [fins]}]} 5 | Pet: {discriminator: petType, properties: {name: {type: string}, petType: {type: string}}, required: [name, petType]} 6 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithDateTimeMap.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | additionalProperties: 3 | type: string 4 | format: date-time 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithExamples.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Pet: {properties: {name: {type: string}}, required: [name]} 3 | Dog: {properties: {id: {type: integer, format: int64}, name: {type: string}}, required: [name]} 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithInt32Map.yaml: -------------------------------------------------------------------------------- 1 | description: 'This is a Map[String, Integer]' 2 | additionalProperties: 3 | type: integer 4 | format: int32 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithInt64Map.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | additionalProperties: 3 | type: integer 4 | format: int64 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithMultipleProperties.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | properties: 3 | booleanValue: {type: boolean} 4 | byteValue: {type: string, format: byte} 5 | dateTimeValue: {type: string, format: date-time} 6 | int32Value: {type: integer, format: int32} 7 | int64Value: {type: integer, format: int64} 8 | stringValue: {type: string} 9 | booleanArrayValue: {type: array, items: {type: boolean}} 10 | byteArrayValue: {type: array, items: {type: string, format: byte}} 11 | dateTimeArrayValue: {type: array, items: {type: string, format: date-time}} 12 | int32ArrayValue: {type: array, items: {type: integer, format: int32}} 13 | int64ArrayValue: {type: array, items: {type: integer, format: int64}} 14 | stringArrayValue: {type: array, items: {type: string}} 15 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithObjectMap.yaml: -------------------------------------------------------------------------------- 1 | description: "This is a Map[String, { id: Long, name: String}]" 2 | additionalProperties: 3 | type: "object" 4 | properties: 5 | id: 6 | type: "integer" 7 | format: "int64" 8 | name: 9 | type: "string" 10 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithPrimitiveArray.yaml: -------------------------------------------------------------------------------- 1 | required: 2 | - id 3 | properties: 4 | id: {type: integer, format: int64} 5 | childrensAges: {type: array, items: {type: integer, format: int32}} 6 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithStringProperty.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | properties: 3 | name: {type: string} 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/modelWithXmlAttributes.yaml: -------------------------------------------------------------------------------- 1 | description: 'this model serves xml and json structures' 2 | xml: 3 | name: XMLModel 4 | properties: 5 | id: {type: integer, format: int64, xml: {attribute: true, namespace: ns1, prefix: urn1}} 6 | items: {type: array, items: {type: string}, xml: {wrapped: true}} 7 | -------------------------------------------------------------------------------- /fixtures/yaml/models/models.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Pet: {properties: {name: {type: string}}, required: [name]} 3 | -------------------------------------------------------------------------------- /fixtures/yaml/models/multipleModels.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Pet: {properties: {name: {type: string}}, required: [name]} 3 | Dog: {properties: {id: {type: integer, format: int64}, name: {type: string}}, required: [name]} 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithBooleanArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: boolean 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithByteArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: string 4 | format: byte 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithComplexArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | $ref: ComplexType 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithDateTimeArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: string 4 | format: date-time 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithInt32Array.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: integer 4 | format: int32 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithInt64Array.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: integer 4 | format: int64 5 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithRef.yaml: -------------------------------------------------------------------------------- 1 | $ref: Foo 2 | description: 'a boolean' 3 | readOnly: true 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/propertyWithStringArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: string 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/simpleBooleanProperty.yaml: -------------------------------------------------------------------------------- 1 | type: boolean 2 | description: 'a boolean' 3 | readOnly: true 4 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/simpleByteProperty.yaml: -------------------------------------------------------------------------------- 1 | type: string 2 | format: byte 3 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/simpleDateTimeProperty.yaml: -------------------------------------------------------------------------------- 1 | type: string 2 | format: date-time 3 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/simpleInt32Property.yaml: -------------------------------------------------------------------------------- 1 | type: integer 2 | format: int32 3 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/simpleInt64Property.yaml: -------------------------------------------------------------------------------- 1 | type: integer 2 | format: int64 3 | -------------------------------------------------------------------------------- /fixtures/yaml/models/properties/simpleStringProperty.yaml: -------------------------------------------------------------------------------- 1 | type: string 2 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/cascadingSchemes.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {get: {description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}, schemes: [https]}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/commonParameters.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/multipleMimeTypes.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - 'text/plain; charset=utf-8' 16 | - application/json 17 | - application/vnd.github+json 18 | - application/vnd.github.v3+json 19 | - application/vnd.github.v3.raw+json 20 | - application/vnd.github.v3.text+json 21 | - application/vnd.github.v3.html+json 22 | - application/vnd.github.v3.full+json 23 | - application/vnd.github.v3.diff 24 | - application/vnd.github.v3.patch 25 | produces: 26 | - application/json 27 | - application/xml 28 | paths: 29 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 30 | definitions: 31 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 32 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 33 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/operations/operationWithTags.yaml: -------------------------------------------------------------------------------- 1 | description: 'Returns a pet based on ID' 2 | summary: 'Find pet by ID' 3 | operationId: getPetsById 4 | tags: 5 | - foo 6 | - bar 7 | produces: 8 | - application/json 9 | - text/html 10 | parameters: 11 | - {name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: integer, format: int64} 12 | responses: 13 | '200': {description: 'a pet to be returned', schema: {$ref: Pet}} 14 | default: {description: 'Unexpected error', schema: {$ref: ErrorModel}} 15 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/operations/stringPathAndBoolQueryParamResource.yaml: -------------------------------------------------------------------------------- 1 | description: 'Returns a pet based on ID' 2 | summary: 'Find pet by ID' 3 | operationId: getPetsById 4 | produces: 5 | - application/json 6 | - text/html 7 | parameters: 8 | - {name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: integer, format: int64} 9 | - {name: includeDetails, in: query, description: 'include details in response', required: true, type: boolean} 10 | responses: 11 | '200': {description: 'a pet to be returned', schema: {$ref: Pet}} 12 | default: {description: 'Unexpected error', schema: {$ref: ErrorModel}} 13 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/operations/stringPathParamResource.yaml: -------------------------------------------------------------------------------- 1 | description: 'Returns a pet based on ID' 2 | summary: 'Find pet by ID' 3 | operationId: getPetsById 4 | produces: 5 | - application/json 6 | - text/html 7 | parameters: 8 | - {name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: integer, format: int64} 9 | responses: 10 | '200': {description: fun, schema: {$ref: Pet}} 11 | '400': {description: 'Invalid ID supplied <= this is purely for documentation', schema: {$ref: ErrorModel}} 12 | default: {description: 'Unexpected error', schema: {$ref: ErrorModel}} 13 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/bodyComplexArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | type: array 7 | items: {type: string} 8 | format: csv 9 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/bodyComplexParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | $ref: User 7 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/bodyInt64Parameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: body 3 | description: 'id to add' 4 | required: true 5 | schema: 6 | type: integer 7 | format: int64 8 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/bodyStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | type: array 7 | items: {type: string} 8 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/bodyStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | type: string 7 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/formDataComplexParameter.yaml: -------------------------------------------------------------------------------- 1 | name: firstName 2 | in: formData 3 | description: 'users first name' 4 | required: true 5 | $ref: Nothing 6 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/formDataInt64Parameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: formData 3 | description: 'username to fetch' 4 | required: true 5 | type: integer 6 | format: int64 7 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/formDataStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: formData 3 | description: 'user to add to the system' 4 | required: true 5 | type: array 6 | items: 7 | type: string 8 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/formDataStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: firstName 2 | in: formData 3 | description: 'users first name' 4 | required: true 5 | type: string 6 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/headerInt64ArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: token 2 | in: header 3 | description: 'token to be passed as a header' 4 | required: true 5 | type: array 6 | items: 7 | type: integer 8 | format: int64 9 | collectionFormat: csv 10 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/headerStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: token 2 | in: header 3 | description: 'token to be passed as a header' 4 | required: true 5 | type: array 6 | items: 7 | type: string 8 | collectionFormat: csv 9 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/headerStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: token 2 | in: header 3 | description: 'token to be passed as a header' 4 | required: true 5 | type: string 6 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/pathInt64Parameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: path 3 | description: 'username to fetch' 4 | required: true 5 | type: integer 6 | format: int64 7 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/pathStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: usernames 2 | in: path 3 | description: 'usernames to pass' 4 | required: true 5 | type: array 6 | items: 7 | type: string 8 | collectionFormat: csv 9 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/pathStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: username 2 | in: path 3 | description: 'username to fetch' 4 | required: true 5 | type: string 6 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/queryInt64ArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: query 3 | description: 'ID of the object to fetch' 4 | required: true 5 | type: array 6 | items: 7 | type: integer 8 | format: int64 9 | collectionFormat: csv 10 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/queryStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: query 3 | description: 'ID of the object to fetch' 4 | required: true 5 | type: integer 6 | format: int64 7 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/parameters/queryWithComplexParameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: query 3 | description: 'a complex object which should not validate' 4 | required: true 5 | schema: 6 | $ref: Pet 7 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/resourceWithExamplePayload.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {get: {description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}, examples: {application/json: {id: 9, category: {name: domestic}, name: monster, tags: [{name: 'for sale'}], status: alive}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string, example: cat}, tag: {type: string, example: 'for sale'}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/resourceWithLinkedDefinitions.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {$ref: 'https://raw.githubusercontent.com/reverb/swagger-spec/master/fixtures/v2.0/json/resources/resourceWithLinkedDefinitions_part1.json'} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/resourceWithLinkedDefinitions_part1.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | description: 'Returns a pet based on ID' 3 | summary: 'Find pet by ID' 4 | operationId: getPetsById 5 | produces: [application/json, text/html] 6 | parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}] 7 | responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}} 8 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/resourceWithRelativeHost.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | basePath: /v1 10 | schemes: 11 | - http 12 | - https 13 | consumes: 14 | - application/json 15 | produces: 16 | - application/json 17 | - application/xml 18 | paths: 19 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 20 | definitions: 21 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 22 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 23 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/reusableParameters.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{id}': {get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, parameters: [{$ref: '#/parameters/skipParam'}, {$ref: '#/parameters/limitParam'}], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | parameters: 22 | skipParam: {name: skip, in: query, description: 'number of items to skip', required: true, type: integer, format: int32} 23 | limitParam: {name: limit, in: query, description: 'max records to return', required: true, type: integer, format: int32} 24 | definitions: 25 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 26 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 27 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/securityExample.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | basePath: /v1 10 | schemes: 11 | - http 12 | - https 13 | consumes: 14 | - application/json 15 | produces: 16 | - application/json 17 | - application/xml 18 | security: 19 | - {githubAccessCode: [user, gist]} 20 | - {internalApiKey: []} 21 | paths: 22 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, security: [{githubAuth: ['user:read', 'user:write']}, {internalApiKey: []}], produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 23 | securityDefinitions: 24 | githubAccessCode: {type: oauth2, scopes: {user: 'Grants read/write access to profile info only. Note that this scope includes user:email and user:follow.', 'user:email': 'Grants read access to a user’s email addresses.', 'user:follow': 'Grants access to follow or unfollow other users.', public_repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations.', repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations.', repo_deployment: 'Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.', 'repo:status': 'Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.', delete_repo: 'Grants access to delete adminable repositories.', notifications: 'Grants read access to a user’s notifications. repo also provides this access.', gist: 'Grants write access to gists.', 'read:repo_hook': 'Grants read and ping access to hooks in public or private repositories.', 'write:repo_hook': 'Grants read, write, and ping access to hooks in public or private repositories.', 'admin:repo_hook': 'Grants read, write, ping, and delete access to hooks in public or private repositories.', 'read:org': 'Read-only access to organization, teams, and membership.', 'write:org': 'Publicize and unpublicize organization membership.', 'admin:org': 'Fully manage organization, teams, and memberships.', 'read:public_key': 'List and view details for public keys.', 'write:public_key': 'Create, list, and view details for public keys.', 'admin:public_key': 'Fully manage public keys.'}, flow: accessCode, authorizationUrl: 'https://github.com/login/oauth/authorize', tokenUrl: 'https://github.com/login/oauth/access_token'} 25 | petstoreImplicit: {type: oauth2, scopes: {user: 'Grants read/write access to profile info only. Note that this scope includes user:email and user:follow.', 'user:email': 'Grants read access to a user’s email addresses.', 'user:follow': 'Grants access to follow or unfollow other users.', public_repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations.', repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations.', repo_deployment: 'Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.', 'repo:status': 'Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.', delete_repo: 'Grants access to delete adminable repositories.', notifications: 'Grants read access to a user’s notifications. repo also provides this access.', gist: 'Grants write access to gists.', 'read:repo_hook': 'Grants read and ping access to hooks in public or private repositories.', 'write:repo_hook': 'Grants read, write, and ping access to hooks in public or private repositories.', 'admin:repo_hook': 'Grants read, write, ping, and delete access to hooks in public or private repositories.', 'read:org': 'Read-only access to organization, teams, and membership.', 'write:org': 'Publicize and unpublicize organization membership.', 'admin:org': 'Fully manage organization, teams, and memberships.', 'read:public_key': 'List and view details for public keys.', 'write:public_key': 'Create, list, and view details for public keys.', 'admin:public_key': 'Fully manage public keys.'}, flow: implicit, authorizationUrl: 'http://petstore.swagger.wordnik.com/oauth/dialog'} 26 | internalApiKey: {type: apiKey, in: header, name: api_key} 27 | definitions: 28 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 29 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 30 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/stringPathParamResource.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {get: {description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/taggedResource.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | x-reverb: 3 | addAnythingYouWant: true 4 | info: 5 | x-reverb-info: 'this is an example' 6 | version: 1.0.9-abcd 7 | title: 'Swagger Sample API' 8 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 9 | termsOfService: 'http://helloreverb.com/terms/' 10 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 11 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 12 | host: my.api.com 13 | basePath: /v1 14 | schemes: 15 | - http 16 | - https 17 | consumes: 18 | - application/json 19 | produces: 20 | - application/json 21 | - application/xml 22 | tags: 23 | - {name: pets} 24 | paths: 25 | x-reverb-path-info: 'vendor info' 26 | /pets: {x-vendor-method: {}, get: {x-vendor-operation-property: {}, description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{x-vendor-parameter-property: {}, name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, x-vendor-operation-response-property: {}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 27 | definitions: 28 | Pet: {x-vendor-model-property: {}, required: [name], properties: {name: {type: string}, tag: {type: string}}} 29 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 30 | -------------------------------------------------------------------------------- /fixtures/yaml/resources/vendorExtensionExamples.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | x-reverb: 3 | addAnythingYouWant: true 4 | info: 5 | x-reverb-info: 'this is an example' 6 | version: 1.0.9-abcd 7 | title: 'Swagger Sample API' 8 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 9 | termsOfService: 'http://helloreverb.com/terms/' 10 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 11 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 12 | host: my.api.com 13 | basePath: /v1 14 | schemes: 15 | - http 16 | - https 17 | consumes: 18 | - application/json 19 | produces: 20 | - application/json 21 | - application/xml 22 | paths: 23 | x-reverb-path-info: 'vendor info' 24 | /pets: {x-vendor-method: {}, get: {x-vendor-operation-property: {}, description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{x-vendor-parameter-property: {}, name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, x-vendor-operation-response-property: {}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 25 | definitions: 26 | Pet: {x-vendor-model-property: {}, required: [name], properties: {name: {type: string}, tag: {type: string}}} 27 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 28 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/complexArrayResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A complex object array response' 2 | schema: 3 | type: array 4 | items: {$ref: VeryComplexType} 5 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/dateTimeResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A date-time response' 2 | schema: 3 | type: string 4 | format: date-time 5 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/int32Response.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: integer 4 | format: int32 5 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/int64Response.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: integer 4 | format: int64 5 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/multipleResponses.yaml: -------------------------------------------------------------------------------- 1 | '200': 2 | description: 'simple string response' 3 | schema: {type: string} 4 | '201': 5 | description: 'object created' 6 | default: 7 | description: oops 8 | schema: {type: integer, format: int32} 9 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/stringArrayResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A string array response' 2 | schema: 3 | type: array 4 | items: {type: string} 5 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/stringResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: string 4 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/stringResponseWithHeader.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: string 4 | headers: 5 | is-dog: {type: boolean} 6 | is-cat: {type: boolean} 7 | -------------------------------------------------------------------------------- /fixtures/yaml/responses/voidResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'object created' 2 | -------------------------------------------------------------------------------- /fixtures/yaml/swagger/1/2/3/4/swagger.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | title: Something 4 | contact: 5 | name: Somebody 6 | url: https://url.com 7 | email: email@url.com 8 | description: Something 9 | version: v1 10 | host: security.sonusnet.com 11 | schemes: 12 | - https 13 | - http 14 | basePath: /api 15 | produces: 16 | - application/json 17 | - plain/text 18 | 19 | paths: 20 | /whatnot: 21 | get: 22 | description: Get something 23 | responses: 24 | 200: 25 | description: The something 26 | schema: 27 | $ref: '#/definitions/Something' 28 | 500: 29 | description: Oops 30 | 31 | definitions: 32 | Something: 33 | description: A collection of service events 34 | type: object 35 | properties: 36 | page: 37 | $ref: '../../../../shared/definitions/page.yaml#/definitions/Page' 38 | something: 39 | #type: array 40 | #description: An array of something 41 | #items: 42 | $ref: '../../../../shared/something.yaml#/definitions/Something' 43 | -------------------------------------------------------------------------------- /fixtures/yaml/swagger/shared/definitions/page.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Page: 3 | description: A description of a paged result 4 | type: object 5 | properties: 6 | page: 7 | type: integer 8 | description: the page that was requested 9 | pages: 10 | type: integer 11 | description: the total number of pages available 12 | total_items: 13 | type: integer 14 | description: the total number of items available 15 | format: int64 16 | page_items: 17 | type: integer 18 | description: the number of items per page requested 19 | -------------------------------------------------------------------------------- /fixtures/yaml/swagger/shared/something.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | title: Something definitions 4 | contact: 5 | name: Somebody 6 | url: https://url.com 7 | email: email@url.com 8 | description: Something 9 | version: v1 10 | host: security.sonusnet.com 11 | schemes: 12 | - https 13 | - http 14 | basePath: /api/something/definitions 15 | produces: 16 | - application/json 17 | - plain/text 18 | 19 | paths: 20 | /shared: 21 | get: 22 | operationId: Get 23 | tags: 24 | - Shared 25 | responses: 26 | 200: 27 | description: OK 28 | schema: 29 | properties: 30 | name: 31 | type: string 32 | 33 | definitions: 34 | Something: 35 | description: Something 36 | type: object 37 | properties: 38 | p1: 39 | type: string 40 | description: A string 41 | p2: 42 | type: integer 43 | description: An integer 44 | 45 | -------------------------------------------------------------------------------- /fixtures/yaml/swagger/spec.yml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | version: 0.1.1 4 | title: test 1 5 | description: recursively following JSON references 6 | contact: 7 | name: Fred 8 | host: api.example.com 9 | 10 | schemes: 11 | - http 12 | consumes: 13 | - application/json 14 | produces: 15 | - application/json 16 | 17 | paths: 18 | /getAll: 19 | get: 20 | operationId: getAll 21 | parameters: 22 | - name: a 23 | in: body 24 | description: max number of results 25 | required: false 26 | schema: 27 | $ref: '#/definitions/a' 28 | responses: 29 | '200': 30 | description: Success 31 | schema: 32 | $ref: '#/definitions/b' 33 | 34 | definitions: 35 | a: 36 | type: string 37 | b: 38 | $ref: './test3-ter-model-schema.json#/definitions/b' 39 | -------------------------------------------------------------------------------- /fixtures/yaml/swagger/test3-ter-model-schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "id": "./test3-model-schema.json", 4 | "title": "test3-model-schema", 5 | "description": "Test schema responses", 6 | "definitions": { 7 | "b": { 8 | "type": "array", 9 | "items": { 10 | "type": "string" 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /fixtures/yaml/yaml/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/go-openapi/loads/1afdd18ac3d8eee37f59f8e358fb079f246467ae/fixtures/yaml/yaml/.gitkeep -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithArrayRef.yaml: -------------------------------------------------------------------------------- 1 | required: 2 | - id 3 | properties: 4 | id: {type: integer, format: int64} 5 | children: {type: array, items: {$ref: Person}} 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithComposition.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Cat: {description: 'A representation of a cat', allOf: [{$ref: '#/models/Pet'}, {properties: {huntingSkill: {type: string, description: 'The measured skill for hunting', default: lazy, enum: [clueless, lazy, adventerous, aggressive]}}, required: [huntingSkill]}]} 3 | Dog: {description: 'A representation of a dog', allOf: [{$ref: '#/models/Pet'}, {properties: {packSize: {type: integer, format: int32, description: 'the size of the pack the dog is from', default: 0}}, required: [name, packSize]}]} 4 | Fish: {description: 'A representation of a fish', allOf: [{$ref: '#/models/Pet'}, {properties: {fins: {type: integer, format: int32, description: 'count of fins'}}, required: [fins]}]} 5 | Pet: {discriminator: petType, properties: {name: {type: string}, petType: {type: string}}, required: [name, petType]} 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithDateTimeMap.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | additionalProperties: 3 | type: string 4 | format: date-time 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithExamples.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Pet: {properties: {name: {type: string}}, required: [name]} 3 | Dog: {properties: {id: {type: integer, format: int64}, name: {type: string}}, required: [name]} 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithInt32Map.yaml: -------------------------------------------------------------------------------- 1 | description: 'This is a Map[String, Integer]' 2 | additionalProperties: 3 | type: integer 4 | format: int32 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithInt64Map.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | additionalProperties: 3 | type: integer 4 | format: int64 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithMultipleProperties.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | properties: 3 | booleanValue: {type: boolean} 4 | byteValue: {type: string, format: byte} 5 | dateTimeValue: {type: string, format: date-time} 6 | int32Value: {type: integer, format: int32} 7 | int64Value: {type: integer, format: int64} 8 | stringValue: {type: string} 9 | booleanArrayValue: {type: array, items: {type: boolean}} 10 | byteArrayValue: {type: array, items: {type: string, format: byte}} 11 | dateTimeArrayValue: {type: array, items: {type: string, format: date-time}} 12 | int32ArrayValue: {type: array, items: {type: integer, format: int32}} 13 | int64ArrayValue: {type: array, items: {type: integer, format: int64}} 14 | stringArrayValue: {type: array, items: {type: string}} 15 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithObjectMap.yaml: -------------------------------------------------------------------------------- 1 | description: "This is a Map[String, { id: Long, name: String}]" 2 | additionalProperties: 3 | type: "object" 4 | properties: 5 | id: 6 | type: "integer" 7 | format: "int64" 8 | name: 9 | type: "string" 10 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithPrimitiveArray.yaml: -------------------------------------------------------------------------------- 1 | required: 2 | - id 3 | properties: 4 | id: {type: integer, format: int64} 5 | childrensAges: {type: array, items: {type: integer, format: int32}} 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithStringProperty.yaml: -------------------------------------------------------------------------------- 1 | description: 'true' 2 | properties: 3 | name: {type: string} 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/modelWithXmlAttributes.yaml: -------------------------------------------------------------------------------- 1 | description: 'this model serves xml and json structures' 2 | xml: 3 | name: XMLModel 4 | properties: 5 | id: {type: integer, format: int64, xml: {attribute: true, namespace: ns1, prefix: urn1}} 6 | items: {type: array, items: {type: string}, xml: {wrapped: true}} 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/models.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Pet: {properties: {name: {type: string}}, required: [name]} 3 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/multipleModels.yaml: -------------------------------------------------------------------------------- 1 | definitions: 2 | Pet: {properties: {name: {type: string}}, required: [name]} 3 | Dog: {properties: {id: {type: integer, format: int64}, name: {type: string}}, required: [name]} 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithBooleanArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: boolean 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithByteArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: string 4 | format: byte 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithComplexArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | $ref: ComplexType 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithDateTimeArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: string 4 | format: date-time 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithInt32Array.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: integer 4 | format: int32 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithInt64Array.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: integer 4 | format: int64 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithRef.yaml: -------------------------------------------------------------------------------- 1 | $ref: Foo 2 | description: 'a boolean' 3 | readOnly: true 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/propertyWithStringArray.yaml: -------------------------------------------------------------------------------- 1 | type: array 2 | items: 3 | type: string 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/simpleBooleanProperty.yaml: -------------------------------------------------------------------------------- 1 | type: boolean 2 | description: 'a boolean' 3 | readOnly: true 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/simpleByteProperty.yaml: -------------------------------------------------------------------------------- 1 | type: string 2 | format: byte 3 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/simpleDateTimeProperty.yaml: -------------------------------------------------------------------------------- 1 | type: string 2 | format: date-time 3 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/simpleInt32Property.yaml: -------------------------------------------------------------------------------- 1 | type: integer 2 | format: int32 3 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/simpleInt64Property.yaml: -------------------------------------------------------------------------------- 1 | type: integer 2 | format: int64 3 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/models/properties/simpleStringProperty.yaml: -------------------------------------------------------------------------------- 1 | type: string 2 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/cascadingSchemes.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {get: {description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}, schemes: [https]}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/commonParameters.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/multipleMimeTypes.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - 'text/plain; charset=utf-8' 16 | - application/json 17 | - application/vnd.github+json 18 | - application/vnd.github.v3+json 19 | - application/vnd.github.v3.raw+json 20 | - application/vnd.github.v3.text+json 21 | - application/vnd.github.v3.html+json 22 | - application/vnd.github.v3.full+json 23 | - application/vnd.github.v3.diff 24 | - application/vnd.github.v3.patch 25 | produces: 26 | - application/json 27 | - application/xml 28 | paths: 29 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 30 | definitions: 31 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 32 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 33 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/operations/operationWithTags.yaml: -------------------------------------------------------------------------------- 1 | description: 'Returns a pet based on ID' 2 | summary: 'Find pet by ID' 3 | operationId: getPetsById 4 | tags: 5 | - foo 6 | - bar 7 | produces: 8 | - application/json 9 | - text/html 10 | parameters: 11 | - {name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: integer, format: int64} 12 | responses: 13 | '200': {description: 'a pet to be returned', schema: {$ref: Pet}} 14 | default: {description: 'Unexpected error', schema: {$ref: ErrorModel}} 15 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/operations/stringPathAndBoolQueryParamResource.yaml: -------------------------------------------------------------------------------- 1 | description: 'Returns a pet based on ID' 2 | summary: 'Find pet by ID' 3 | operationId: getPetsById 4 | produces: 5 | - application/json 6 | - text/html 7 | parameters: 8 | - {name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: integer, format: int64} 9 | - {name: includeDetails, in: query, description: 'include details in response', required: true, type: boolean} 10 | responses: 11 | '200': {description: 'a pet to be returned', schema: {$ref: Pet}} 12 | default: {description: 'Unexpected error', schema: {$ref: ErrorModel}} 13 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/operations/stringPathParamResource.yaml: -------------------------------------------------------------------------------- 1 | description: 'Returns a pet based on ID' 2 | summary: 'Find pet by ID' 3 | operationId: getPetsById 4 | produces: 5 | - application/json 6 | - text/html 7 | parameters: 8 | - {name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: integer, format: int64} 9 | responses: 10 | '200': {description: fun, schema: {$ref: Pet}} 11 | '400': {description: 'Invalid ID supplied <= this is purely for documentation', schema: {$ref: ErrorModel}} 12 | default: {description: 'Unexpected error', schema: {$ref: ErrorModel}} 13 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/bodyComplexArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | type: array 7 | items: {type: string} 8 | format: csv 9 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/bodyComplexParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | $ref: User 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/bodyInt64Parameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: body 3 | description: 'id to add' 4 | required: true 5 | schema: 6 | type: integer 7 | format: int64 8 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/bodyStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | type: array 7 | items: {type: string} 8 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/bodyStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: body 3 | description: 'user to add to the system' 4 | required: true 5 | schema: 6 | type: string 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/formDataComplexParameter.yaml: -------------------------------------------------------------------------------- 1 | name: firstName 2 | in: formData 3 | description: 'users first name' 4 | required: true 5 | $ref: Nothing 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/formDataInt64Parameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: formData 3 | description: 'username to fetch' 4 | required: true 5 | type: integer 6 | format: int64 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/formDataStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: user 2 | in: formData 3 | description: 'user to add to the system' 4 | required: true 5 | type: array 6 | items: 7 | type: string 8 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/formDataStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: firstName 2 | in: formData 3 | description: 'users first name' 4 | required: true 5 | type: string 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/headerInt64ArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: token 2 | in: header 3 | description: 'token to be passed as a header' 4 | required: true 5 | type: array 6 | items: 7 | type: integer 8 | format: int64 9 | collectionFormat: csv 10 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/headerStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: token 2 | in: header 3 | description: 'token to be passed as a header' 4 | required: true 5 | type: array 6 | items: 7 | type: string 8 | collectionFormat: csv 9 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/headerStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: token 2 | in: header 3 | description: 'token to be passed as a header' 4 | required: true 5 | type: string 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/pathInt64Parameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: path 3 | description: 'username to fetch' 4 | required: true 5 | type: integer 6 | format: int64 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/pathStringArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: usernames 2 | in: path 3 | description: 'usernames to pass' 4 | required: true 5 | type: array 6 | items: 7 | type: string 8 | collectionFormat: csv 9 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/pathStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: username 2 | in: path 3 | description: 'username to fetch' 4 | required: true 5 | type: string 6 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/queryInt64ArrayParameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: query 3 | description: 'ID of the object to fetch' 4 | required: true 5 | type: array 6 | items: 7 | type: integer 8 | format: int64 9 | collectionFormat: csv 10 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/queryStringParameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: query 3 | description: 'ID of the object to fetch' 4 | required: true 5 | type: integer 6 | format: int64 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/parameters/queryWithComplexParameter.yaml: -------------------------------------------------------------------------------- 1 | name: id 2 | in: query 3 | description: 'a complex object which should not validate' 4 | required: true 5 | schema: 6 | $ref: Pet 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/resourceWithExamplePayload.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {get: {description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}, examples: {application/json: {id: 9, category: {name: domestic}, name: monster, tags: [{name: 'for sale'}], status: alive}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string, example: cat}, tag: {type: string, example: 'for sale'}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/resourceWithLinkedDefinitions.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {$ref: 'https://raw.githubusercontent.com/reverb/swagger-spec/master/fixtures/v2.0/json/resources/resourceWithLinkedDefinitions_part1.json'} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/resourceWithLinkedDefinitions_part1.yaml: -------------------------------------------------------------------------------- 1 | get: 2 | description: 'Returns a pet based on ID' 3 | summary: 'Find pet by ID' 4 | operationId: getPetsById 5 | produces: [application/json, text/html] 6 | parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}] 7 | responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}} 8 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/resourceWithRelativeHost.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | basePath: /v1 10 | schemes: 11 | - http 12 | - https 13 | consumes: 14 | - application/json 15 | produces: 16 | - application/json 17 | - application/xml 18 | paths: 19 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 20 | definitions: 21 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 22 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 23 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/reusableParameters.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{id}': {get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, parameters: [{$ref: '#/parameters/skipParam'}, {$ref: '#/parameters/limitParam'}], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | parameters: 22 | skipParam: {name: skip, in: query, description: 'number of items to skip', required: true, type: integer, format: int32} 23 | limitParam: {name: limit, in: query, description: 'max records to return', required: true, type: integer, format: int32} 24 | definitions: 25 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 26 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 27 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/securityExample.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | basePath: /v1 10 | schemes: 11 | - http 12 | - https 13 | consumes: 14 | - application/json 15 | produces: 16 | - application/json 17 | - application/xml 18 | security: 19 | - {githubAccessCode: [user, gist]} 20 | - {internalApiKey: []} 21 | paths: 22 | '/pets/{id}': {parameters: [{name: id, in: path, description: 'ID of pet to use', required: true, type: array, items: {type: string}, collectionFormat: csv}], get: {description: 'Returns pets based on ID', summary: 'Find pets by ID', operationId: getPetsById, security: [{githubAuth: ['user:read', 'user:write']}, {internalApiKey: []}], produces: [application/json, text/html], responses: {'200': {description: 'pet response', schema: {type: array, items: {$ref: Pet}}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 23 | securityDefinitions: 24 | githubAccessCode: {type: oauth2, scopes: {user: 'Grants read/write access to profile info only. Note that this scope includes user:email and user:follow.', 'user:email': 'Grants read access to a user’s email addresses.', 'user:follow': 'Grants access to follow or unfollow other users.', public_repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations.', repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations.', repo_deployment: 'Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.', 'repo:status': 'Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.', delete_repo: 'Grants access to delete adminable repositories.', notifications: 'Grants read access to a user’s notifications. repo also provides this access.', gist: 'Grants write access to gists.', 'read:repo_hook': 'Grants read and ping access to hooks in public or private repositories.', 'write:repo_hook': 'Grants read, write, and ping access to hooks in public or private repositories.', 'admin:repo_hook': 'Grants read, write, ping, and delete access to hooks in public or private repositories.', 'read:org': 'Read-only access to organization, teams, and membership.', 'write:org': 'Publicize and unpublicize organization membership.', 'admin:org': 'Fully manage organization, teams, and memberships.', 'read:public_key': 'List and view details for public keys.', 'write:public_key': 'Create, list, and view details for public keys.', 'admin:public_key': 'Fully manage public keys.'}, flow: accessCode, authorizationUrl: 'https://github.com/login/oauth/authorize', tokenUrl: 'https://github.com/login/oauth/access_token'} 25 | petstoreImplicit: {type: oauth2, scopes: {user: 'Grants read/write access to profile info only. Note that this scope includes user:email and user:follow.', 'user:email': 'Grants read access to a user’s email addresses.', 'user:follow': 'Grants access to follow or unfollow other users.', public_repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations.', repo: 'Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations.', repo_deployment: 'Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code.', 'repo:status': 'Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code.', delete_repo: 'Grants access to delete adminable repositories.', notifications: 'Grants read access to a user’s notifications. repo also provides this access.', gist: 'Grants write access to gists.', 'read:repo_hook': 'Grants read and ping access to hooks in public or private repositories.', 'write:repo_hook': 'Grants read, write, and ping access to hooks in public or private repositories.', 'admin:repo_hook': 'Grants read, write, ping, and delete access to hooks in public or private repositories.', 'read:org': 'Read-only access to organization, teams, and membership.', 'write:org': 'Publicize and unpublicize organization membership.', 'admin:org': 'Fully manage organization, teams, and memberships.', 'read:public_key': 'List and view details for public keys.', 'write:public_key': 'Create, list, and view details for public keys.', 'admin:public_key': 'Fully manage public keys.'}, flow: implicit, authorizationUrl: 'http://petstore.swagger.wordnik.com/oauth/dialog'} 26 | internalApiKey: {type: apiKey, in: header, name: api_key} 27 | definitions: 28 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 29 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 30 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/stringPathParamResource.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | info: 3 | version: 1.0.9-abcd 4 | title: 'Swagger Sample API' 5 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 6 | termsOfService: 'http://helloreverb.com/terms/' 7 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 8 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 9 | host: my.api.com 10 | basePath: /v1 11 | schemes: 12 | - http 13 | - https 14 | consumes: 15 | - application/json 16 | produces: 17 | - application/json 18 | - application/xml 19 | paths: 20 | '/pets/{petId}': {get: {description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 21 | definitions: 22 | Pet: {required: [name], properties: {name: {type: string}, tag: {type: string}}} 23 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 24 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/taggedResource.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | x-reverb: 3 | addAnythingYouWant: true 4 | info: 5 | x-reverb-info: 'this is an example' 6 | version: 1.0.9-abcd 7 | title: 'Swagger Sample API' 8 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 9 | termsOfService: 'http://helloreverb.com/terms/' 10 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 11 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 12 | host: my.api.com 13 | basePath: /v1 14 | schemes: 15 | - http 16 | - https 17 | consumes: 18 | - application/json 19 | produces: 20 | - application/json 21 | - application/xml 22 | tags: 23 | - {name: pets} 24 | paths: 25 | x-reverb-path-info: 'vendor info' 26 | /pets: {x-vendor-method: {}, get: {x-vendor-operation-property: {}, description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{x-vendor-parameter-property: {}, name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, x-vendor-operation-response-property: {}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 27 | definitions: 28 | Pet: {x-vendor-model-property: {}, required: [name], properties: {name: {type: string}, tag: {type: string}}} 29 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 30 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/resources/vendorExtensionExamples.yaml: -------------------------------------------------------------------------------- 1 | swagger: '2.0' 2 | x-reverb: 3 | addAnythingYouWant: true 4 | info: 5 | x-reverb-info: 'this is an example' 6 | version: 1.0.9-abcd 7 | title: 'Swagger Sample API' 8 | description: 'A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification' 9 | termsOfService: 'http://helloreverb.com/terms/' 10 | contact: {name: 'wordnik api team', url: 'http://developer.wordnik.com'} 11 | license: {name: 'Creative Commons 4.0 International', url: 'http://creativecommons.org/licenses/by/4.0/'} 12 | host: my.api.com 13 | basePath: /v1 14 | schemes: 15 | - http 16 | - https 17 | consumes: 18 | - application/json 19 | produces: 20 | - application/json 21 | - application/xml 22 | paths: 23 | x-reverb-path-info: 'vendor info' 24 | /pets: {x-vendor-method: {}, get: {x-vendor-operation-property: {}, description: 'Returns a pet based on ID', summary: 'Find pet by ID', operationId: getPetsById, produces: [application/json, text/html], parameters: [{x-vendor-parameter-property: {}, name: petId, in: path, description: 'ID of pet that needs to be fetched', required: true, type: array, items: {type: string}, collectionFormat: csv}], responses: {'200': {description: 'pet response', schema: {$ref: Pet}}, x-vendor-operation-response-property: {}, default: {description: 'error payload', schema: {$ref: ErrorModel}}}}} 25 | definitions: 26 | Pet: {x-vendor-model-property: {}, required: [name], properties: {name: {type: string}, tag: {type: string}}} 27 | ErrorModel: {required: [code, message], properties: {code: {type: integer, format: int32}, message: {type: string}}} 28 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/complexArrayResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A complex object array response' 2 | schema: 3 | type: array 4 | items: {$ref: VeryComplexType} 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/dateTimeResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A date-time response' 2 | schema: 3 | type: string 4 | format: date-time 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/int32Response.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: integer 4 | format: int32 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/int64Response.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: integer 4 | format: int64 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/multipleResponses.yaml: -------------------------------------------------------------------------------- 1 | '200': 2 | description: 'simple string response' 3 | schema: {type: string} 4 | '201': 5 | description: 'object created' 6 | default: 7 | description: oops 8 | schema: {type: integer, format: int32} 9 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/stringArrayResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A string array response' 2 | schema: 3 | type: array 4 | items: {type: string} 5 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/stringResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: string 4 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/stringResponseWithHeader.yaml: -------------------------------------------------------------------------------- 1 | description: 'A simple string response' 2 | schema: 3 | type: string 4 | headers: 5 | is-dog: {type: boolean} 6 | is-cat: {type: boolean} 7 | -------------------------------------------------------------------------------- /fixtures/yaml/yaml/responses/voidResponse.yaml: -------------------------------------------------------------------------------- 1 | description: 'object created' 2 | -------------------------------------------------------------------------------- /fmts/fixture_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 go-swagger maintainers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package fmts 16 | 17 | import ( 18 | "encoding/json" 19 | "os" 20 | "path/filepath" 21 | "strings" 22 | "testing" 23 | 24 | "github.com/go-openapi/spec" 25 | "github.com/stretchr/testify/assert" 26 | "github.com/stretchr/testify/require" 27 | ) 28 | 29 | var extensions = []string{"json"} 30 | 31 | //nolint:unparam 32 | func assertSpecJSON(t testing.TB, specJSON []byte) bool { 33 | var expected map[string]interface{} 34 | require.NoError(t, json.Unmarshal(specJSON, &expected)) 35 | 36 | obj := spec.Swagger{} 37 | require.NoError(t, json.Unmarshal(specJSON, &obj)) 38 | 39 | cb, err := json.MarshalIndent(obj, "", " ") 40 | require.NoError(t, err) 41 | 42 | var actual map[string]interface{} 43 | require.NoError(t, json.Unmarshal(cb, &actual)) 44 | 45 | return assertSpecMaps(t, actual, expected) 46 | } 47 | 48 | func assertSpecMaps(t testing.TB, actual, expected map[string]interface{}) bool { 49 | res := true 50 | if id, ok := expected["id"]; ok { 51 | res = assert.Equal(t, id, actual["id"]) 52 | } 53 | res = res && assert.Equal(t, expected["consumes"], actual["consumes"]) 54 | res = res && assert.Equal(t, expected["produces"], actual["produces"]) 55 | res = res && assert.Equal(t, expected["schemes"], actual["schemes"]) 56 | res = res && assert.Equal(t, expected["swagger"], actual["swagger"]) 57 | res = res && assert.Equal(t, expected["info"], actual["info"]) 58 | res = res && assert.Equal(t, expected["host"], actual["host"]) 59 | res = res && assert.Equal(t, expected["basePath"], actual["basePath"]) 60 | res = res && assert.Equal(t, expected["paths"], actual["paths"]) 61 | res = res && assert.Equal(t, expected["definitions"], actual["definitions"]) 62 | res = res && assert.Equal(t, expected["responses"], actual["responses"]) 63 | res = res && assert.Equal(t, expected["securityDefinitions"], actual["securityDefinitions"]) 64 | res = res && assert.Equal(t, expected["tags"], actual["tags"]) 65 | res = res && assert.Equal(t, expected["externalDocs"], actual["externalDocs"]) 66 | res = res && assert.Equal(t, expected["x-some-extension"], actual["x-some-extension"]) 67 | res = res && assert.Equal(t, expected["x-schemes"], actual["x-schemes"]) 68 | 69 | return res 70 | } 71 | 72 | //nolint:unparam 73 | func roundTripTest(t *testing.T, fixtureType, extension, fileName string, schema interface{}) bool { 74 | if extension == "yaml" { 75 | return roundTripTestYAML(t, fixtureType, fileName, schema) 76 | } 77 | return roundTripTestJSON(t, fixtureType, fileName, schema) 78 | } 79 | 80 | func roundTripTestJSON(t *testing.T, fixtureType, fileName string, schema interface{}) bool { 81 | specName := strings.TrimSuffix(fileName, filepath.Ext(fileName)) 82 | t.Logf("verifying %s JSON fixture %q", fixtureType, specName) 83 | 84 | b, err := os.ReadFile(fileName) 85 | require.NoError(t, err) 86 | 87 | var expected map[string]interface{} 88 | require.NoError(t, json.Unmarshal(b, &expected)) 89 | 90 | require.NoError(t, json.Unmarshal(b, schema)) 91 | 92 | cb, err := json.MarshalIndent(schema, "", " ") 93 | require.NoError(t, err) 94 | 95 | var actual map[string]interface{} 96 | require.NoError(t, json.Unmarshal(cb, &actual)) 97 | 98 | return assert.EqualValues(t, expected, actual) 99 | } 100 | 101 | func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema interface{}) bool { 102 | specName := strings.TrimSuffix(fileName, filepath.Ext(fileName)) 103 | t.Logf("verifying %s YAML fixture %q", fixtureType, specName) 104 | 105 | b, err := YAMLDoc(fileName) 106 | require.NoError(t, err) 107 | 108 | var expected map[string]interface{} 109 | require.NoError(t, json.Unmarshal(b, &expected)) 110 | 111 | require.NoError(t, json.Unmarshal(b, schema)) 112 | 113 | cb, err := json.MarshalIndent(schema, "", " ") 114 | require.NoError(t, err) 115 | 116 | var actual map[string]interface{} 117 | require.NoError(t, json.Unmarshal(cb, &actual)) 118 | 119 | return assert.EqualValues(t, expected, actual) 120 | } 121 | 122 | func TestPropertyFixtures(t *testing.T) { 123 | for _, extension := range extensions { 124 | path := filepath.Join("..", "fixtures", extension, "models", "properties") 125 | files, err := os.ReadDir(path) 126 | if err != nil { 127 | t.Fatal(err) 128 | } 129 | 130 | // for _, f := range files { 131 | // roundTripTest(t, "property", extension, filepath.Join(path, f.Name()), &Schema{}) 132 | // } 133 | f := files[0] 134 | roundTripTest(t, "property", extension, filepath.Join(path, f.Name()), &spec.Schema{}) 135 | } 136 | } 137 | 138 | func TestAdditionalPropertiesWithObject(t *testing.T) { 139 | schema := new(spec.Schema) 140 | b, err := YAMLDoc("../fixtures/yaml/models/modelWithObjectMap.yaml") 141 | require.NoError(t, err) 142 | var expected map[string]interface{} 143 | require.NoError(t, json.Unmarshal(b, &expected)) 144 | require.NoError(t, json.Unmarshal(b, schema)) 145 | 146 | cb, err := json.MarshalIndent(schema, "", " ") 147 | require.NoError(t, err) 148 | 149 | var actual map[string]interface{} 150 | require.NoError(t, json.Unmarshal(cb, &actual)) 151 | assert.Equal(t, expected, actual) 152 | } 153 | 154 | func TestModelFixtures(t *testing.T) { 155 | path := filepath.Join("..", "fixtures", "json", "models") 156 | files, err := os.ReadDir(path) 157 | require.NoError(t, err) 158 | specs := []string{"modelWithObjectMap", "models", "modelWithComposition", "modelWithExamples", "multipleModels"} 159 | FILES: 160 | for _, f := range files { 161 | if f.IsDir() { 162 | continue 163 | } 164 | for _, sp := range specs { 165 | if strings.HasPrefix(f.Name(), sp) { 166 | roundTripTest(t, "model", "json", filepath.Join(path, f.Name()), &spec.Schema{}) 167 | continue FILES 168 | } 169 | } 170 | roundTripTest(t, "model", "json", filepath.Join(path, f.Name()), &spec.Schema{}) 171 | } 172 | path = filepath.Join("..", "fixtures", "yaml", "models") 173 | files, err = os.ReadDir(path) 174 | require.NoError(t, err) 175 | 176 | YAMLFILES: 177 | for _, f := range files { 178 | if f.IsDir() { 179 | continue 180 | } 181 | for _, sp := range specs { 182 | if strings.HasPrefix(f.Name(), sp) { 183 | roundTripTest(t, "model", "yaml", filepath.Join(path, f.Name()), &spec.Schema{}) 184 | continue YAMLFILES 185 | } 186 | } 187 | roundTripTest(t, "model", "yaml", filepath.Join(path, f.Name()), &spec.Schema{}) 188 | } 189 | } 190 | 191 | func TestParameterFixtures(t *testing.T) { 192 | path := filepath.Join("..", "fixtures", "json", "resources", "parameters") 193 | files, err := os.ReadDir(path) 194 | require.NoError(t, err) 195 | 196 | for _, f := range files { 197 | roundTripTest(t, "parameter", "json", filepath.Join(path, f.Name()), &spec.Parameter{}) 198 | } 199 | } 200 | 201 | func TestOperationFixtures(t *testing.T) { 202 | path := filepath.Join("..", "fixtures", "json", "resources", "operations") 203 | files, err := os.ReadDir(path) 204 | require.NoError(t, err) 205 | 206 | for _, f := range files { 207 | roundTripTest(t, "operation", "json", filepath.Join(path, f.Name()), &spec.Operation{}) 208 | } 209 | } 210 | 211 | func TestResponseFixtures(t *testing.T) { 212 | path := filepath.Join("..", "fixtures", "json", "responses") 213 | files, err := os.ReadDir(path) 214 | require.NoError(t, err) 215 | 216 | for _, f := range files { 217 | if !strings.HasPrefix(f.Name(), "multiple") { 218 | roundTripTest(t, "response", "json", filepath.Join(path, f.Name()), &spec.Response{}) 219 | } else { 220 | roundTripTest(t, "responses", "json", filepath.Join(path, f.Name()), &spec.Responses{}) 221 | } 222 | } 223 | } 224 | 225 | func TestResourcesFixtures(t *testing.T) { 226 | path := filepath.Join("..", "fixtures", "json", "resources") 227 | files, err := os.ReadDir(path) 228 | require.NoError(t, err) 229 | 230 | pathItems := []string{"resourceWithLinkedDefinitions_part1"} 231 | toSkip := []string{} 232 | FILES: 233 | for _, f := range files { 234 | if f.IsDir() { 235 | continue 236 | } 237 | for _, ts := range toSkip { 238 | if strings.HasPrefix(f.Name(), ts) { 239 | t.Log("verifying resource" + strings.TrimSuffix(f.Name(), filepath.Ext(f.Name()))) 240 | b, err := os.ReadFile(filepath.Join(path, f.Name())) 241 | require.NoError(t, err) 242 | assertSpecJSON(t, b) 243 | continue FILES 244 | } 245 | } 246 | for _, pi := range pathItems { 247 | if strings.HasPrefix(f.Name(), pi) { 248 | roundTripTest(t, "path items", "json", filepath.Join(path, f.Name()), &spec.PathItem{}) 249 | continue FILES 250 | } 251 | } 252 | 253 | t.Logf("verifying resource %q", strings.TrimSuffix(f.Name(), filepath.Ext(f.Name()))) 254 | b2, err := os.ReadFile(filepath.Join(path, f.Name())) 255 | require.NoError(t, err) 256 | assertSpecJSON(t, b2) 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /fmts/yaml.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 go-swagger maintainers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package fmts 16 | 17 | import "github.com/go-openapi/swag" 18 | 19 | var ( 20 | // YAMLMatcher matches yaml 21 | YAMLMatcher = swag.YAMLMatcher 22 | // YAMLToJSON converts YAML unmarshaled data into json compatible data 23 | YAMLToJSON = swag.YAMLToJSON 24 | // BytesToYAMLDoc converts raw bytes to a map[string]interface{} 25 | BytesToYAMLDoc = swag.BytesToYAMLDoc 26 | // YAMLDoc loads a yaml document from either http or a file and converts it to json 27 | YAMLDoc = swag.YAMLDoc 28 | // YAMLData loads a yaml document from either http or a file 29 | YAMLData = swag.YAMLData 30 | ) 31 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/go-openapi/loads 2 | 3 | require ( 4 | github.com/go-openapi/analysis v0.23.0 5 | github.com/go-openapi/spec v0.21.0 6 | github.com/go-openapi/swag v0.23.1 7 | github.com/stretchr/testify v1.10.0 8 | gopkg.in/yaml.v3 v3.0.1 9 | ) 10 | 11 | require ( 12 | github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect 13 | github.com/davecgh/go-spew v1.1.1 // indirect 14 | github.com/go-openapi/errors v0.22.0 // indirect 15 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 16 | github.com/go-openapi/jsonreference v0.21.0 // indirect 17 | github.com/go-openapi/strfmt v0.23.0 // indirect 18 | github.com/google/uuid v1.6.0 // indirect 19 | github.com/josharian/intern v1.0.0 // indirect 20 | github.com/mailru/easyjson v0.9.0 // indirect 21 | github.com/mitchellh/mapstructure v1.5.0 // indirect 22 | github.com/oklog/ulid v1.3.1 // indirect 23 | github.com/pmezard/go-difflib v1.0.0 // indirect 24 | go.mongodb.org/mongo-driver v1.14.0 // indirect 25 | ) 26 | 27 | go 1.20 28 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= 2 | github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= 3 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 4 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU= 6 | github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo= 7 | github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w= 8 | github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE= 9 | github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= 10 | github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= 11 | github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= 12 | github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= 13 | github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY= 14 | github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= 15 | github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= 16 | github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= 17 | github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU= 18 | github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0= 19 | github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= 20 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 21 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 22 | github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= 23 | github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= 24 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 25 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 26 | github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= 27 | github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= 28 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 29 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 30 | github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= 31 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 32 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 33 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 34 | github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= 35 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 36 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 37 | go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= 38 | go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= 39 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 40 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 41 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 42 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 43 | -------------------------------------------------------------------------------- /json_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 go-swagger maintainers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package loads 16 | 17 | import ( 18 | "net/http" 19 | "net/http/httptest" 20 | "testing" 21 | 22 | "github.com/stretchr/testify/require" 23 | ) 24 | 25 | func TestLoadJSON(t *testing.T) { 26 | serv := httptest.NewServer(http.HandlerFunc(jsonPestoreServer)) 27 | defer serv.Close() 28 | 29 | s, err := JSONSpec(serv.URL) 30 | require.NoError(t, err) 31 | require.NotNil(t, s) 32 | 33 | ts2 := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { 34 | rw.WriteHeader(http.StatusNotFound) 35 | _, _ = rw.Write([]byte("{}")) 36 | })) 37 | defer ts2.Close() 38 | _, err = JSONSpec(ts2.URL) 39 | require.Error(t, err) 40 | } 41 | 42 | var jsonPestoreServer = func(rw http.ResponseWriter, _ *http.Request) { 43 | rw.WriteHeader(http.StatusOK) 44 | _, _ = rw.Write([]byte(petstoreJSON)) 45 | } 46 | 47 | const petstoreJSON = `{ 48 | "swagger": "2.0", 49 | "info": { 50 | "version": "1.0.0", 51 | "title": "Swagger Petstore", 52 | "contact": { 53 | "name": "Wordnik API Team", 54 | "url": "http://developer.wordnik.com" 55 | }, 56 | "license": { 57 | "name": "Creative Commons 4.0 International", 58 | "url": "http://creativecommons.org/licenses/by/4.0/" 59 | } 60 | }, 61 | "host": "petstore.swagger.wordnik.com", 62 | "basePath": "/api", 63 | "schemes": [ 64 | "http" 65 | ], 66 | "paths": { 67 | "/pets": { 68 | "get": { 69 | "security": [ 70 | { 71 | "oauth2": ["read"] 72 | } 73 | ], 74 | "tags": [ "Pet Operations" ], 75 | "operationId": "getAllPets", 76 | "parameters": [ 77 | { 78 | "name": "status", 79 | "in": "query", 80 | "description": "The status to filter by", 81 | "type": "string" 82 | } 83 | ], 84 | "summary": "Finds all pets in the system", 85 | "responses": { 86 | "200": { 87 | "description": "Pet response", 88 | "schema": { 89 | "type": "array", 90 | "items": { 91 | "$ref": "#/definitions/Pet" 92 | } 93 | } 94 | }, 95 | "default": { 96 | "description": "Unexpected error", 97 | "schema": { 98 | "$ref": "#/definitions/Error" 99 | } 100 | } 101 | } 102 | }, 103 | "post": { 104 | "security": [ 105 | { 106 | "oauth2": ["write"] 107 | } 108 | ], 109 | "tags": [ "Pet Operations" ], 110 | "operationId": "createPet", 111 | "summary": "Creates a new pet", 112 | "parameters": [ 113 | { 114 | "name": "pet", 115 | "in": "body", 116 | "description": "The Pet to create", 117 | "required": true, 118 | "schema": { 119 | "$ref": "#/definitions/newPet" 120 | } 121 | } 122 | ], 123 | "responses": { 124 | "200": { 125 | "description": "Created Pet response", 126 | "schema": { 127 | "$ref": "#/definitions/Pet" 128 | } 129 | }, 130 | "default": { 131 | "description": "Unexpected error", 132 | "schema": { 133 | "$ref": "#/definitions/Error" 134 | } 135 | } 136 | } 137 | } 138 | }, 139 | "/pets/{id}": { 140 | "delete": { 141 | "security": [ 142 | { 143 | "oauth2": ["write"] 144 | } 145 | ], 146 | "description": "Deletes the Pet by id", 147 | "operationId": "deletePet", 148 | "parameters": [ 149 | { 150 | "name": "id", 151 | "in": "path", 152 | "description": "ID of pet to delete", 153 | "required": true, 154 | "type": "integer", 155 | "format": "int64" 156 | } 157 | ], 158 | "responses": { 159 | "204": { 160 | "description": "pet deleted" 161 | }, 162 | "default": { 163 | "description": "unexpected error", 164 | "schema": { 165 | "$ref": "#/definitions/Error" 166 | } 167 | } 168 | } 169 | }, 170 | "get": { 171 | "security": [ 172 | { 173 | "oauth2": ["read"] 174 | } 175 | ], 176 | "tags": [ "Pet Operations" ], 177 | "operationId": "getPetById", 178 | "summary": "Finds the pet by id", 179 | "responses": { 180 | "200": { 181 | "description": "Pet response", 182 | "schema": { 183 | "$ref": "#/definitions/Pet" 184 | } 185 | }, 186 | "default": { 187 | "description": "Unexpected error", 188 | "schema": { 189 | "$ref": "#/definitions/Error" 190 | } 191 | } 192 | } 193 | }, 194 | "parameters": [ 195 | { 196 | "name": "id", 197 | "in": "path", 198 | "description": "ID of pet", 199 | "required": true, 200 | "type": "integer", 201 | "format": "int64" 202 | } 203 | ] 204 | } 205 | }, 206 | "definitions": { 207 | "Category": { 208 | "id": "Category", 209 | "properties": { 210 | "id": { 211 | "format": "int64", 212 | "type": "integer" 213 | }, 214 | "name": { 215 | "type": "string" 216 | } 217 | } 218 | }, 219 | "Pet": { 220 | "id": "Pet", 221 | "properties": { 222 | "category": { 223 | "$ref": "#/definitions/Category" 224 | }, 225 | "id": { 226 | "description": "unique identifier for the pet", 227 | "format": "int64", 228 | "maximum": 100.0, 229 | "minimum": 0.0, 230 | "type": "integer" 231 | }, 232 | "name": { 233 | "type": "string" 234 | }, 235 | "photoUrls": { 236 | "items": { 237 | "type": "string" 238 | }, 239 | "type": "array" 240 | }, 241 | "status": { 242 | "description": "pet status in the store", 243 | "enum": [ 244 | "available", 245 | "pending", 246 | "sold" 247 | ], 248 | "type": "string" 249 | }, 250 | "tags": { 251 | "items": { 252 | "$ref": "#/definitions/Tag" 253 | }, 254 | "type": "array" 255 | } 256 | }, 257 | "required": [ 258 | "id", 259 | "name" 260 | ] 261 | }, 262 | "newPet": { 263 | "allOf": [ 264 | { 265 | "$ref": "#/definitions/Pet" 266 | } 267 | ], 268 | "required": [ 269 | "name" 270 | ] 271 | }, 272 | "Tag": { 273 | "id": "Tag", 274 | "properties": { 275 | "id": { 276 | "format": "int64", 277 | "type": "integer" 278 | }, 279 | "name": { 280 | "type": "string" 281 | } 282 | } 283 | }, 284 | "Error": { 285 | "required": [ 286 | "code", 287 | "message" 288 | ], 289 | "properties": { 290 | "code": { 291 | "type": "integer", 292 | "format": "int32" 293 | }, 294 | "message": { 295 | "type": "string" 296 | } 297 | } 298 | } 299 | }, 300 | "produces": [ 301 | "application/json", 302 | "application/xml", 303 | "text/plain", 304 | "text/html" 305 | ], 306 | "securityDefinitions": { 307 | "oauth2": { 308 | "type": "oauth2", 309 | "scopes": { 310 | "read": "Read access.", 311 | "write": "Write access" 312 | }, 313 | "flow": "accessCode", 314 | "authorizationUrl": "http://petstore.swagger.wordnik.com/oauth/authorize", 315 | "tokenUrl": "http://petstore.swagger.wordnik.com/oauth/token" 316 | } 317 | } 318 | }` 319 | -------------------------------------------------------------------------------- /loaders.go: -------------------------------------------------------------------------------- 1 | package loads 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "net/url" 7 | 8 | "github.com/go-openapi/spec" 9 | "github.com/go-openapi/swag" 10 | ) 11 | 12 | var ( 13 | // Default chain of loaders, defined at the package level. 14 | // 15 | // By default this matches json and yaml documents. 16 | // 17 | // May be altered with AddLoader(). 18 | loaders *loader 19 | ) 20 | 21 | func init() { 22 | jsonLoader := &loader{ 23 | DocLoaderWithMatch: DocLoaderWithMatch{ 24 | Match: func(_ string) bool { 25 | return true 26 | }, 27 | Fn: JSONDoc, 28 | }, 29 | } 30 | 31 | loaders = jsonLoader.WithHead(&loader{ 32 | DocLoaderWithMatch: DocLoaderWithMatch{ 33 | Match: swag.YAMLMatcher, 34 | Fn: swag.YAMLDoc, 35 | }, 36 | }) 37 | 38 | // sets the global default loader for go-openapi/spec 39 | spec.PathLoader = loaders.Load 40 | } 41 | 42 | // DocLoader represents a doc loader type 43 | type DocLoader func(string) (json.RawMessage, error) 44 | 45 | // DocMatcher represents a predicate to check if a loader matches 46 | type DocMatcher func(string) bool 47 | 48 | // DocLoaderWithMatch describes a loading function for a given extension match. 49 | type DocLoaderWithMatch struct { 50 | Fn DocLoader 51 | Match DocMatcher 52 | } 53 | 54 | // NewDocLoaderWithMatch builds a DocLoaderWithMatch to be used in load options 55 | func NewDocLoaderWithMatch(fn DocLoader, matcher DocMatcher) DocLoaderWithMatch { 56 | return DocLoaderWithMatch{ 57 | Fn: fn, 58 | Match: matcher, 59 | } 60 | } 61 | 62 | type loader struct { 63 | DocLoaderWithMatch 64 | Next *loader 65 | } 66 | 67 | // WithHead adds a loader at the head of the current stack 68 | func (l *loader) WithHead(head *loader) *loader { 69 | if head == nil { 70 | return l 71 | } 72 | head.Next = l 73 | return head 74 | } 75 | 76 | // WithNext adds a loader at the trail of the current stack 77 | func (l *loader) WithNext(next *loader) *loader { 78 | l.Next = next 79 | return next 80 | } 81 | 82 | // Load the raw document from path 83 | func (l *loader) Load(path string) (json.RawMessage, error) { 84 | _, erp := url.Parse(path) 85 | if erp != nil { 86 | return nil, errors.Join(erp, ErrLoads) 87 | } 88 | 89 | var lastErr error = ErrNoLoader // default error if no match was found 90 | for ldr := l; ldr != nil; ldr = ldr.Next { 91 | if ldr.Match != nil && !ldr.Match(path) { 92 | continue 93 | } 94 | 95 | // try then move to next one if there is an error 96 | b, err := ldr.Fn(path) 97 | if err == nil { 98 | return b, nil 99 | } 100 | 101 | lastErr = err 102 | } 103 | 104 | return nil, errors.Join(lastErr, ErrLoads) 105 | } 106 | 107 | // JSONDoc loads a json document from either a file or a remote url 108 | func JSONDoc(path string) (json.RawMessage, error) { 109 | data, err := swag.LoadFromFileOrHTTP(path) 110 | if err != nil { 111 | return nil, errors.Join(err, ErrLoads) 112 | } 113 | return json.RawMessage(data), nil 114 | } 115 | 116 | // AddLoader for a document, executed before other previously set loaders. 117 | // 118 | // This sets the configuration at the package level. 119 | // 120 | // NOTE: 121 | // - this updates the default loader used by github.com/go-openapi/spec 122 | // - since this sets package level globals, you shouln't call this concurrently 123 | func AddLoader(predicate DocMatcher, load DocLoader) { 124 | loaders = loaders.WithHead(&loader{ 125 | DocLoaderWithMatch: DocLoaderWithMatch{ 126 | Match: predicate, 127 | Fn: load, 128 | }, 129 | }) 130 | 131 | // sets the global default loader for go-openapi/spec 132 | spec.PathLoader = loaders.Load 133 | } 134 | -------------------------------------------------------------------------------- /loaders_test.go: -------------------------------------------------------------------------------- 1 | package loads 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/require" 7 | ) 8 | 9 | func TestLoader_EdgeCases(t *testing.T) { 10 | ldr := &loader{} 11 | ldr.Fn = JSONDoc 12 | 13 | // chaining with nil is a no op 14 | next := ldr.WithHead(nil) 15 | require.Equal(t, ldr, next) 16 | 17 | _, err := ldr.Load(`d\::invalid uri\`) 18 | require.Error(t, err) 19 | } 20 | -------------------------------------------------------------------------------- /options.go: -------------------------------------------------------------------------------- 1 | package loads 2 | 3 | type options struct { 4 | loader *loader 5 | } 6 | 7 | func defaultOptions() *options { 8 | return &options{ 9 | loader: loaders, 10 | } 11 | } 12 | 13 | func loaderFromOptions(options []LoaderOption) *loader { 14 | opts := defaultOptions() 15 | for _, apply := range options { 16 | apply(opts) 17 | } 18 | 19 | return opts.loader 20 | } 21 | 22 | // LoaderOption allows to fine-tune the spec loader behavior 23 | type LoaderOption func(*options) 24 | 25 | // WithDocLoader sets a custom loader for loading specs 26 | func WithDocLoader(l DocLoader) LoaderOption { 27 | return func(opt *options) { 28 | if l == nil { 29 | return 30 | } 31 | opt.loader = &loader{ 32 | DocLoaderWithMatch: DocLoaderWithMatch{ 33 | Fn: l, 34 | }, 35 | } 36 | } 37 | } 38 | 39 | // WithDocLoaderMatches sets a chain of custom loaders for loading specs 40 | // for different extension matches. 41 | // 42 | // Loaders are executed in the order of provided DocLoaderWithMatch'es. 43 | func WithDocLoaderMatches(l ...DocLoaderWithMatch) LoaderOption { 44 | return func(opt *options) { 45 | var final, prev *loader 46 | for _, ldr := range l { 47 | if ldr.Fn == nil { 48 | continue 49 | } 50 | 51 | if prev == nil { 52 | final = &loader{DocLoaderWithMatch: ldr} 53 | prev = final 54 | continue 55 | } 56 | 57 | prev = prev.WithNext(&loader{DocLoaderWithMatch: ldr}) 58 | } 59 | opt.loader = final 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /options_test.go: -------------------------------------------------------------------------------- 1 | package loads 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "os" 7 | "path/filepath" 8 | "testing" 9 | 10 | "github.com/go-openapi/swag" 11 | "github.com/stretchr/testify/assert" 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | const optionFixture = "fixtures/json/resources/pathLoaderIssue.json" 16 | 17 | var errTest = errors.New("test") 18 | 19 | func TestOptionsWithDocLoader(t *testing.T) { 20 | document, err := Spec(optionFixture, WithDocLoader(func(pth string) (json.RawMessage, error) { 21 | buf, err := os.ReadFile(pth) 22 | return json.RawMessage(buf), err 23 | })) 24 | require.NoError(t, err) 25 | require.NotNil(t, document) 26 | require.NotNil(t, document.pathLoader) 27 | 28 | b, err := document.pathLoader.Load(optionFixture) 29 | require.NoError(t, err) 30 | 31 | trimmed, err := trimData(b) 32 | require.NoError(t, err) 33 | 34 | assert.EqualValues(t, trimmed, document.Raw()) 35 | 36 | // a nil loader is a no op 37 | _, err = Spec(optionFixture, WithDocLoader(nil)) 38 | require.NoError(t, err) 39 | } 40 | 41 | func TestOptionsLoaderFromOptions(t *testing.T) { 42 | var called int 43 | 44 | // not chaining here, just replacing with the last one 45 | l := loaderFromOptions([]LoaderOption{ 46 | WithDocLoader(func(pth string) (json.RawMessage, error) { 47 | called = 1 48 | buf, err := os.ReadFile(pth) 49 | return json.RawMessage(buf), err 50 | }), 51 | WithDocLoader(func(pth string) (json.RawMessage, error) { 52 | called = 2 53 | buf, err := os.ReadFile(pth) 54 | return json.RawMessage(buf), err 55 | }), 56 | }) 57 | require.NotNil(t, l) 58 | 59 | b, err := l.Load(optionFixture) 60 | require.NoError(t, err) 61 | require.NotNil(t, b) 62 | 63 | require.Equal(t, 2, called) 64 | } 65 | 66 | func TestOptionsWithDocLoaderMatches(t *testing.T) { 67 | jsonLoader := NewDocLoaderWithMatch( 68 | func(pth string) (json.RawMessage, error) { 69 | buf, err := os.ReadFile(pth) 70 | return json.RawMessage(buf), err 71 | }, 72 | func(pth string) bool { 73 | return filepath.Ext(pth) == ".json" 74 | }, 75 | ) 76 | 77 | document, err := Spec(optionFixture, WithDocLoaderMatches(jsonLoader)) 78 | require.NoError(t, err) 79 | require.NotNil(t, document) 80 | require.NotNil(t, document.pathLoader) 81 | 82 | yamlLoader := NewDocLoaderWithMatch( 83 | swag.YAMLDoc, 84 | func(pth string) bool { 85 | return filepath.Ext(pth) == ".yaml" 86 | }, 87 | ) 88 | 89 | document, err = Spec(optionFixture, WithDocLoaderMatches(yamlLoader)) 90 | require.Error(t, err) 91 | require.Nil(t, document) 92 | 93 | // chained loaders, with different ordering 94 | document, err = Spec(optionFixture, WithDocLoaderMatches(yamlLoader, jsonLoader)) 95 | require.NoError(t, err) 96 | require.NotNil(t, document) 97 | 98 | document, err = Spec(optionFixture, WithDocLoaderMatches(jsonLoader, yamlLoader)) 99 | require.NoError(t, err) 100 | require.NotNil(t, document) 101 | 102 | // the nil loader is a no op 103 | nilLoader := NewDocLoaderWithMatch(nil, nil) 104 | document, err = Spec(optionFixture, WithDocLoaderMatches(nilLoader, jsonLoader, yamlLoader)) 105 | require.NoError(t, err) 106 | require.NotNil(t, document) 107 | 108 | // the nil matcher always matches 109 | nilMatcher := NewDocLoaderWithMatch(func(_ string) (json.RawMessage, error) { 110 | return nil, errTest 111 | }, nil) 112 | _, err = Spec(optionFixture, WithDocLoaderMatches(nilMatcher)) 113 | require.Error(t, err) 114 | require.ErrorIs(t, err, errTest) 115 | 116 | // when a matcher returns an errors, the next one is tried 117 | document, err = Spec(optionFixture, WithDocLoaderMatches(nilMatcher, jsonLoader, yamlLoader)) 118 | require.NoError(t, err) 119 | require.NotNil(t, document) 120 | } 121 | -------------------------------------------------------------------------------- /spec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 go-swagger maintainers 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package loads 16 | 17 | import ( 18 | "bytes" 19 | "encoding/gob" 20 | "encoding/json" 21 | "errors" 22 | "fmt" 23 | 24 | "github.com/go-openapi/analysis" 25 | "github.com/go-openapi/spec" 26 | "github.com/go-openapi/swag" 27 | ) 28 | 29 | func init() { 30 | gob.Register(map[string]interface{}{}) 31 | gob.Register([]interface{}{}) 32 | } 33 | 34 | // Document represents a swagger spec document 35 | type Document struct { 36 | // specAnalyzer 37 | Analyzer *analysis.Spec 38 | spec *spec.Swagger 39 | specFilePath string 40 | origSpec *spec.Swagger 41 | schema *spec.Schema 42 | pathLoader *loader 43 | raw json.RawMessage 44 | } 45 | 46 | // JSONSpec loads a spec from a json document 47 | func JSONSpec(path string, options ...LoaderOption) (*Document, error) { 48 | data, err := JSONDoc(path) 49 | if err != nil { 50 | return nil, err 51 | } 52 | // convert to json 53 | doc, err := Analyzed(data, "", options...) 54 | if err != nil { 55 | return nil, err 56 | } 57 | 58 | doc.specFilePath = path 59 | 60 | return doc, nil 61 | } 62 | 63 | // Embedded returns a Document based on embedded specs. No analysis is required 64 | func Embedded(orig, flat json.RawMessage, options ...LoaderOption) (*Document, error) { 65 | var origSpec, flatSpec spec.Swagger 66 | if err := json.Unmarshal(orig, &origSpec); err != nil { 67 | return nil, err 68 | } 69 | if err := json.Unmarshal(flat, &flatSpec); err != nil { 70 | return nil, err 71 | } 72 | return &Document{ 73 | raw: orig, 74 | origSpec: &origSpec, 75 | spec: &flatSpec, 76 | pathLoader: loaderFromOptions(options), 77 | }, nil 78 | } 79 | 80 | // Spec loads a new spec document from a local or remote path 81 | func Spec(path string, options ...LoaderOption) (*Document, error) { 82 | ldr := loaderFromOptions(options) 83 | 84 | b, err := ldr.Load(path) 85 | if err != nil { 86 | return nil, err 87 | } 88 | 89 | document, err := Analyzed(b, "", options...) 90 | if err != nil { 91 | return nil, err 92 | } 93 | 94 | document.specFilePath = path 95 | document.pathLoader = ldr 96 | 97 | return document, nil 98 | } 99 | 100 | // Analyzed creates a new analyzed spec document for a root json.RawMessage. 101 | func Analyzed(data json.RawMessage, version string, options ...LoaderOption) (*Document, error) { 102 | if version == "" { 103 | version = "2.0" 104 | } 105 | if version != "2.0" { 106 | return nil, fmt.Errorf("spec version %q is not supported: %w", version, ErrLoads) 107 | } 108 | 109 | raw, err := trimData(data) // trim blanks, then convert yaml docs into json 110 | if err != nil { 111 | return nil, err 112 | } 113 | 114 | swspec := new(spec.Swagger) 115 | if err = json.Unmarshal(raw, swspec); err != nil { 116 | return nil, errors.Join(err, ErrLoads) 117 | } 118 | 119 | origsqspec, err := cloneSpec(swspec) 120 | if err != nil { 121 | return nil, errors.Join(err, ErrLoads) 122 | } 123 | 124 | d := &Document{ 125 | Analyzer: analysis.New(swspec), // NOTE: at this moment, analysis does not follow $refs to documents outside the root doc 126 | schema: spec.MustLoadSwagger20Schema(), 127 | spec: swspec, 128 | raw: raw, 129 | origSpec: origsqspec, 130 | pathLoader: loaderFromOptions(options), 131 | } 132 | 133 | return d, nil 134 | } 135 | 136 | func trimData(in json.RawMessage) (json.RawMessage, error) { 137 | trimmed := bytes.TrimSpace(in) 138 | if len(trimmed) == 0 { 139 | return in, nil 140 | } 141 | 142 | if trimmed[0] == '{' || trimmed[0] == '[' { 143 | return trimmed, nil 144 | } 145 | 146 | // assume yaml doc: convert it to json 147 | yml, err := swag.BytesToYAMLDoc(trimmed) 148 | if err != nil { 149 | return nil, fmt.Errorf("analyzed: %v: %w", err, ErrLoads) 150 | } 151 | 152 | d, err := swag.YAMLToJSON(yml) 153 | if err != nil { 154 | return nil, fmt.Errorf("analyzed: %v: %w", err, ErrLoads) 155 | } 156 | 157 | return d, nil 158 | } 159 | 160 | // Expanded expands the $ref fields in the spec document and returns a new spec document 161 | func (d *Document) Expanded(options ...*spec.ExpandOptions) (*Document, error) { 162 | swspec := new(spec.Swagger) 163 | if err := json.Unmarshal(d.raw, swspec); err != nil { 164 | return nil, err 165 | } 166 | 167 | var expandOptions *spec.ExpandOptions 168 | if len(options) > 0 { 169 | expandOptions = options[0] 170 | if expandOptions.RelativeBase == "" { 171 | expandOptions.RelativeBase = d.specFilePath 172 | } 173 | } else { 174 | expandOptions = &spec.ExpandOptions{ 175 | RelativeBase: d.specFilePath, 176 | } 177 | } 178 | 179 | if expandOptions.PathLoader == nil { 180 | if d.pathLoader != nil { 181 | // use loader from Document options 182 | expandOptions.PathLoader = d.pathLoader.Load 183 | } else { 184 | // use package level loader 185 | expandOptions.PathLoader = loaders.Load 186 | } 187 | } 188 | 189 | if err := spec.ExpandSpec(swspec, expandOptions); err != nil { 190 | return nil, err 191 | } 192 | 193 | dd := &Document{ 194 | Analyzer: analysis.New(swspec), 195 | spec: swspec, 196 | specFilePath: d.specFilePath, 197 | schema: spec.MustLoadSwagger20Schema(), 198 | raw: d.raw, 199 | origSpec: d.origSpec, 200 | } 201 | return dd, nil 202 | } 203 | 204 | // BasePath the base path for the API specified by this spec 205 | func (d *Document) BasePath() string { 206 | return d.spec.BasePath 207 | } 208 | 209 | // Version returns the version of this spec 210 | func (d *Document) Version() string { 211 | return d.spec.Swagger 212 | } 213 | 214 | // Schema returns the swagger 2.0 schema 215 | func (d *Document) Schema() *spec.Schema { 216 | return d.schema 217 | } 218 | 219 | // Spec returns the swagger spec object model 220 | func (d *Document) Spec() *spec.Swagger { 221 | return d.spec 222 | } 223 | 224 | // Host returns the host for the API 225 | func (d *Document) Host() string { 226 | return d.spec.Host 227 | } 228 | 229 | // Raw returns the raw swagger spec as json bytes 230 | func (d *Document) Raw() json.RawMessage { 231 | return d.raw 232 | } 233 | 234 | // OrigSpec yields the original spec 235 | func (d *Document) OrigSpec() *spec.Swagger { 236 | return d.origSpec 237 | } 238 | 239 | // ResetDefinitions gives a shallow copy with the models reset to the original spec 240 | func (d *Document) ResetDefinitions() *Document { 241 | defs := make(map[string]spec.Schema, len(d.origSpec.Definitions)) 242 | for k, v := range d.origSpec.Definitions { 243 | defs[k] = v 244 | } 245 | 246 | d.spec.Definitions = defs 247 | return d 248 | } 249 | 250 | // Pristine creates a new pristine document instance based on the input data 251 | func (d *Document) Pristine() *Document { 252 | raw, _ := json.Marshal(d.Spec()) 253 | dd, _ := Analyzed(raw, d.Version()) 254 | dd.pathLoader = d.pathLoader 255 | dd.specFilePath = d.specFilePath 256 | 257 | return dd 258 | } 259 | 260 | // SpecFilePath returns the file path of the spec if one is defined 261 | func (d *Document) SpecFilePath() string { 262 | return d.specFilePath 263 | } 264 | 265 | func cloneSpec(src *spec.Swagger) (*spec.Swagger, error) { 266 | var b bytes.Buffer 267 | if err := gob.NewEncoder(&b).Encode(src); err != nil { 268 | return nil, err 269 | } 270 | 271 | var dst spec.Swagger 272 | if err := gob.NewDecoder(&b).Decode(&dst); err != nil { 273 | return nil, err 274 | } 275 | 276 | return &dst, nil 277 | } 278 | --------------------------------------------------------------------------------