Replace godep with dep
This commit is contained in:
parent
1e7489927c
commit
bf5616c65b
14883 changed files with 3937406 additions and 361781 deletions
35
vendor/github.com/go-openapi/spec/.drone.yml
generated
vendored
35
vendor/github.com/go-openapi/spec/.drone.yml
generated
vendored
|
|
@ -1,35 +0,0 @@
|
|||
clone:
|
||||
path: github.com/go-openapi/spec
|
||||
|
||||
matrix:
|
||||
GO_VERSION:
|
||||
- "1.6"
|
||||
|
||||
build:
|
||||
integration:
|
||||
image: golang:$$GO_VERSION
|
||||
pull: true
|
||||
commands:
|
||||
- go get -u github.com/stretchr/testify/assert
|
||||
- go get -u gopkg.in/yaml.v2
|
||||
- go get -u github.com/go-openapi/swag
|
||||
- go get -u github.com/go-openapi/jsonpointer
|
||||
- go get -u github.com/go-openapi/jsonreference
|
||||
- go test -race
|
||||
- go test -v -cover -coverprofile=coverage.out -covermode=count ./...
|
||||
|
||||
notify:
|
||||
slack:
|
||||
channel: bots
|
||||
webhook_url: $$SLACK_URL
|
||||
username: drone
|
||||
|
||||
publish:
|
||||
coverage:
|
||||
server: https://coverage.vmware.run
|
||||
token: $$GITHUB_TOKEN
|
||||
# threshold: 70
|
||||
# must_increase: true
|
||||
when:
|
||||
matrix:
|
||||
GO_VERSION: "1.6"
|
||||
26
vendor/github.com/go-openapi/spec/.editorconfig
generated
vendored
Normal file
26
vendor/github.com/go-openapi/spec/.editorconfig
generated
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Set default charset
|
||||
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}]
|
||||
charset = utf-8
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
# Matches the exact files either package.json or .travis.yml
|
||||
[{package.json,.travis.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
117
vendor/github.com/go-openapi/spec/.github/CONTRIBUTING.md
generated
vendored
Normal file
117
vendor/github.com/go-openapi/spec/.github/CONTRIBUTING.md
generated
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
## Contribution Guidelines
|
||||
|
||||
### Pull requests are always welcome
|
||||
|
||||
We are always thrilled to receive pull requests, and do our best to
|
||||
process them as fast as possible. Not sure if that typo is worth a pull
|
||||
request? Do it! We will appreciate it.
|
||||
|
||||
If your pull request is not accepted on the first try, don't be
|
||||
discouraged! If there's a problem with the implementation, hopefully you
|
||||
received feedback on what to improve.
|
||||
|
||||
We're trying very hard to keep go-swagger lean and focused. We don't want it
|
||||
to do everything for everybody. This means that we might decide against
|
||||
incorporating a new feature. However, there might be a way to implement
|
||||
that feature *on top of* go-swagger.
|
||||
|
||||
|
||||
### Conventions
|
||||
|
||||
Fork the repo and make changes on your fork in a feature branch:
|
||||
|
||||
- If it's a bugfix branch, name it XXX-something where XXX is the number of the
|
||||
issue
|
||||
- If it's a feature branch, create an enhancement issue to announce your
|
||||
intentions, and name it XXX-something where XXX is the number of the issue.
|
||||
|
||||
Submit unit tests for your changes. Go has a great test framework built in; use
|
||||
it! Take a look at existing tests for inspiration. Run the full test suite on
|
||||
your branch before submitting a pull request.
|
||||
|
||||
Update the documentation when creating or modifying features. Test
|
||||
your documentation changes for clarity, concision, and correctness, as
|
||||
well as a clean documentation build. See ``docs/README.md`` for more
|
||||
information on building the docs and how docs get released.
|
||||
|
||||
Write clean code. Universally formatted code promotes ease of writing, reading,
|
||||
and maintenance. Always run `gofmt -s -w file.go` on each changed file before
|
||||
committing your changes. Most editors have plugins that do this automatically.
|
||||
|
||||
Pull requests descriptions should be as clear as possible and include a
|
||||
reference to all the issues that they address.
|
||||
|
||||
Pull requests must not contain commits from other users or branches.
|
||||
|
||||
Commit messages must start with a capitalized and short summary (max. 50
|
||||
chars) written in the imperative, followed by an optional, more detailed
|
||||
explanatory text which is separated from the summary by an empty line.
|
||||
|
||||
Code review comments may be added to your pull request. Discuss, then make the
|
||||
suggested modifications and push additional commits to your feature branch. Be
|
||||
sure to post a comment after pushing. The new commits will show up in the pull
|
||||
request automatically, but the reviewers will not be notified unless you
|
||||
comment.
|
||||
|
||||
Before the pull request is merged, make sure that you squash your commits into
|
||||
logical units of work using `git rebase -i` and `git push -f`. After every
|
||||
commit the test suite should be passing. Include documentation changes in the
|
||||
same commit so that a revert would remove all traces of the feature or fix.
|
||||
|
||||
Commits that fix or close an issue should include a reference like `Closes #XXX`
|
||||
or `Fixes #XXX`, which will automatically close the issue when merged.
|
||||
|
||||
### Sign your work
|
||||
|
||||
The sign-off is a simple line at the end of the explanation for the
|
||||
patch, which certifies that you wrote it or otherwise have the right to
|
||||
pass it on as an open-source patch. The rules are pretty simple: if you
|
||||
can certify the below (from
|
||||
[developercertificate.org](http://developercertificate.org/)):
|
||||
|
||||
```
|
||||
Developer Certificate of Origin
|
||||
Version 1.1
|
||||
|
||||
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
||||
660 York Street, Suite 102,
|
||||
San Francisco, CA 94110 USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
||||
```
|
||||
|
||||
then you just add a line to every git commit message:
|
||||
|
||||
Signed-off-by: Joe Smith <joe@gmail.com>
|
||||
|
||||
using your real name (sorry, no pseudonyms or anonymous contributions.)
|
||||
|
||||
You can add the sign off when creating the git commit via `git commit -s`.
|
||||
13
vendor/github.com/go-openapi/spec/.pullapprove.yml
generated
vendored
13
vendor/github.com/go-openapi/spec/.pullapprove.yml
generated
vendored
|
|
@ -1,13 +0,0 @@
|
|||
approve_by_comment: true
|
||||
approve_regex: '^(:shipit:|:\+1:|\+1|LGTM|lgtm|Approved)'
|
||||
reject_regex: ^[Rr]ejected
|
||||
reset_on_push: false
|
||||
reviewers:
|
||||
members:
|
||||
- casualjim
|
||||
- chancez
|
||||
- frapposelli
|
||||
- vburenin
|
||||
- pytlesk4
|
||||
name: pullapprove
|
||||
required: 1
|
||||
16
vendor/github.com/go-openapi/spec/.travis.yml
generated
vendored
Normal file
16
vendor/github.com/go-openapi/spec/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.7
|
||||
install:
|
||||
- go get -u github.com/stretchr/testify
|
||||
- go get -u github.com/go-openapi/swag
|
||||
- go get -u gopkg.in/yaml.v2
|
||||
- go get -u github.com/go-openapi/jsonpointer
|
||||
- go get -u github.com/go-openapi/jsonreference
|
||||
script:
|
||||
- go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
notifications:
|
||||
slack:
|
||||
secure: QUWvCkBBK09GF7YtEvHHVt70JOkdlNBG0nIKu/5qc4/nW5HP8I2w0SEf/XR2je0eED1Qe3L/AfMCWwrEj+IUZc3l4v+ju8X8R3Lomhme0Eb0jd1MTMCuPcBT47YCj0M7RON7vXtbFfm1hFJ/jLe5+9FXz0hpXsR24PJc5ZIi/ogNwkaPqG4BmndzecpSh0vc2FJPZUD9LT0I09REY/vXR0oQAalLkW0asGD5taHZTUZq/kBpsNxaAFrLM23i4mUcf33M5fjLpvx5LRICrX/57XpBrDh2TooBU6Qj3CgoY0uPRYUmSNxbVx1czNzl2JtEpb5yjoxfVPQeg0BvQM00G8LJINISR+ohrjhkZmAqchDupAX+yFrxTtORa78CtnIL6z/aTNlgwwVD8kvL/1pFA/JWYmKDmz93mV/+6wubGzNSQCstzjkFA4/iZEKewKUoRIAi/fxyscP6L/rCpmY/4llZZvrnyTqVbt6URWpopUpH4rwYqreXAtJxJsfBJIeSmUIiDIOMGkCTvyTEW3fWGmGoqWtSHLoaWDyAIGb7azb+KvfpWtEcoPFWfSWU+LGee0A/YsUhBl7ADB9A0CJEuR8q4BPpKpfLwPKSiKSAXL7zDkyjExyhtgqbSl2jS+rKIHOZNL8JkCcTP2MKMVd563C5rC5FMKqu3S9m2b6380E=
|
||||
4
vendor/github.com/go-openapi/spec/README.md
generated
vendored
4
vendor/github.com/go-openapi/spec/README.md
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
# OAI object model [](https://ci.vmware.run/go-openapi/spec) [](https://coverage.vmware.run/go-openapi/spec) [](https://slackin.goswagger.io)
|
||||
# OAI object model [](https://travis-ci.org/go-openapi/spec) [](https://codecov.io/gh/go-openapi/spec) [](https://slackin.goswagger.io)
|
||||
|
||||
[](https://raw.githubusercontent.com/go-openapi/spec/master/LICENSE) [](http://godoc.org/github.com/go-openapi/spec)
|
||||
|
||||
The object model for OpenAPI specification documents
|
||||
The object model for OpenAPI specification documents
|
||||
|
|
|
|||
128
vendor/github.com/go-openapi/spec/auth_test.go
generated
vendored
Normal file
128
vendor/github.com/go-openapi/spec/auth_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSerialization_AuthSerialization(t *testing.T) {
|
||||
assertSerializeJSON(t, BasicAuth(), `{"type":"basic"}`)
|
||||
|
||||
assertSerializeJSON(t, APIKeyAuth("api-key", "header"), `{"type":"apiKey","name":"api-key","in":"header"}`)
|
||||
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
OAuth2Implicit("http://foo.com/authorization"),
|
||||
`{"type":"oauth2","flow":"implicit","authorizationUrl":"http://foo.com/authorization"}`)
|
||||
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
OAuth2Password("http://foo.com/token"),
|
||||
`{"type":"oauth2","flow":"password","tokenUrl":"http://foo.com/token"}`)
|
||||
|
||||
assertSerializeJSON(t,
|
||||
OAuth2Application("http://foo.com/token"),
|
||||
`{"type":"oauth2","flow":"application","tokenUrl":"http://foo.com/token"}`)
|
||||
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
OAuth2AccessToken("http://foo.com/authorization", "http://foo.com/token"),
|
||||
`{"type":"oauth2","flow":"accessCode","authorizationUrl":"http://foo.com/authorization","tokenUrl":"http://foo.com/token"}`)
|
||||
|
||||
auth1 := OAuth2Implicit("http://foo.com/authorization")
|
||||
auth1.AddScope("email", "read your email")
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
auth1,
|
||||
`{"type":"oauth2","flow":"implicit","authorizationUrl":"http://foo.com/authorization","scopes":{"email":"read your email"}}`)
|
||||
|
||||
auth2 := OAuth2Password("http://foo.com/authorization")
|
||||
auth2.AddScope("email", "read your email")
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
auth2,
|
||||
`{"type":"oauth2","flow":"password","tokenUrl":"http://foo.com/authorization","scopes":{"email":"read your email"}}`)
|
||||
|
||||
auth3 := OAuth2Application("http://foo.com/token")
|
||||
auth3.AddScope("email", "read your email")
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
auth3,
|
||||
`{"type":"oauth2","flow":"application","tokenUrl":"http://foo.com/token","scopes":{"email":"read your email"}}`)
|
||||
|
||||
auth4 := OAuth2AccessToken("http://foo.com/authorization", "http://foo.com/token")
|
||||
auth4.AddScope("email", "read your email")
|
||||
assertSerializeJSON(
|
||||
t,
|
||||
auth4,
|
||||
`{"type":"oauth2","flow":"accessCode","authorizationUrl":"http://foo.com/authorization","tokenUrl":"http://foo.com/token","scopes":{"email":"read your email"}}`)
|
||||
}
|
||||
|
||||
func TestSerialization_AuthDeserialization(t *testing.T) {
|
||||
|
||||
assertParsesJSON(t, `{"type":"basic"}`, BasicAuth())
|
||||
|
||||
assertParsesJSON(
|
||||
t,
|
||||
`{"in":"header","name":"api-key","type":"apiKey"}`,
|
||||
APIKeyAuth("api-key", "header"))
|
||||
|
||||
assertParsesJSON(
|
||||
t,
|
||||
`{"authorizationUrl":"http://foo.com/authorization","flow":"implicit","type":"oauth2"}`,
|
||||
OAuth2Implicit("http://foo.com/authorization"))
|
||||
|
||||
assertParsesJSON(
|
||||
t,
|
||||
`{"flow":"password","tokenUrl":"http://foo.com/token","type":"oauth2"}`,
|
||||
OAuth2Password("http://foo.com/token"))
|
||||
|
||||
assertParsesJSON(
|
||||
t,
|
||||
`{"flow":"application","tokenUrl":"http://foo.com/token","type":"oauth2"}`,
|
||||
OAuth2Application("http://foo.com/token"))
|
||||
|
||||
assertParsesJSON(
|
||||
t,
|
||||
`{"authorizationUrl":"http://foo.com/authorization","flow":"accessCode","tokenUrl":"http://foo.com/token","type":"oauth2"}`,
|
||||
OAuth2AccessToken("http://foo.com/authorization", "http://foo.com/token"))
|
||||
|
||||
auth1 := OAuth2Implicit("http://foo.com/authorization")
|
||||
auth1.AddScope("email", "read your email")
|
||||
assertParsesJSON(t,
|
||||
`{"authorizationUrl":"http://foo.com/authorization","flow":"implicit","scopes":{"email":"read your email"},"type":"oauth2"}`,
|
||||
auth1)
|
||||
|
||||
auth2 := OAuth2Password("http://foo.com/token")
|
||||
auth2.AddScope("email", "read your email")
|
||||
assertParsesJSON(t,
|
||||
`{"flow":"password","scopes":{"email":"read your email"},"tokenUrl":"http://foo.com/token","type":"oauth2"}`,
|
||||
auth2)
|
||||
|
||||
auth3 := OAuth2Application("http://foo.com/token")
|
||||
auth3.AddScope("email", "read your email")
|
||||
assertParsesJSON(t,
|
||||
`{"flow":"application","scopes":{"email":"read your email"},"tokenUrl":"http://foo.com/token","type":"oauth2"}`,
|
||||
auth3)
|
||||
|
||||
auth4 := OAuth2AccessToken("http://foo.com/authorization", "http://foo.com/token")
|
||||
auth4.AddScope("email", "read your email")
|
||||
assertParsesJSON(
|
||||
t,
|
||||
`{"authorizationUrl":"http://foo.com/authorization","flow":"accessCode","scopes":{"email":"read your email"},"tokenUrl":"http://foo.com/token","type":"oauth2"}`,
|
||||
auth4)
|
||||
|
||||
}
|
||||
26
vendor/github.com/go-openapi/spec/bindata.go
generated
vendored
26
vendor/github.com/go-openapi/spec/bindata.go
generated
vendored
File diff suppressed because one or more lines are too long
37
vendor/github.com/go-openapi/spec/contact_info_test.go
generated
vendored
Normal file
37
vendor/github.com/go-openapi/spec/contact_info_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var contactInfoJSON = `{"name":"wordnik api team","url":"http://developer.wordnik.com","email":"some@mailayada.dkdkd"}`
|
||||
var contactInfoYAML = `name: wordnik api team
|
||||
url: http://developer.wordnik.com
|
||||
email: some@mailayada.dkdkd
|
||||
`
|
||||
var contactInfo = ContactInfo{
|
||||
Name: "wordnik api team",
|
||||
URL: "http://developer.wordnik.com",
|
||||
Email: "some@mailayada.dkdkd",
|
||||
}
|
||||
|
||||
func TestIntegrationContactInfo(t *testing.T) {
|
||||
assertSerializeJSON(t, contactInfo, contactInfoJSON)
|
||||
assertSerializeYAML(t, contactInfo, contactInfoYAML)
|
||||
assertParsesJSON(t, contactInfoJSON, contactInfo)
|
||||
assertParsesYAML(t, contactInfoYAML, contactInfo)
|
||||
}
|
||||
570
vendor/github.com/go-openapi/spec/expander.go
generated
vendored
570
vendor/github.com/go-openapi/spec/expander.go
generated
vendored
|
|
@ -17,7 +17,10 @@ package spec
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -26,6 +29,18 @@ import (
|
|||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
var (
|
||||
// Debug enables logging when SWAGGER_DEBUG env var is not empty
|
||||
Debug = os.Getenv("SWAGGER_DEBUG") != ""
|
||||
)
|
||||
|
||||
// ExpandOptions provides options for expand.
|
||||
type ExpandOptions struct {
|
||||
RelativeBase string
|
||||
SkipSchemas bool
|
||||
ContinueOnError bool
|
||||
}
|
||||
|
||||
// ResolutionCache a cache for resolving urls
|
||||
type ResolutionCache interface {
|
||||
Get(string) (interface{}, bool)
|
||||
|
|
@ -37,7 +52,11 @@ type simpleCache struct {
|
|||
store map[string]interface{}
|
||||
}
|
||||
|
||||
var resCache = initResolutionCache()
|
||||
var resCache ResolutionCache
|
||||
|
||||
func init() {
|
||||
resCache = initResolutionCache()
|
||||
}
|
||||
|
||||
func initResolutionCache() ResolutionCache {
|
||||
return &simpleCache{store: map[string]interface{}{
|
||||
|
|
@ -47,8 +66,11 @@ func initResolutionCache() ResolutionCache {
|
|||
}
|
||||
|
||||
func (s *simpleCache) Get(uri string) (interface{}, bool) {
|
||||
debugLog("getting %q from resolution cache", uri)
|
||||
s.lock.Lock()
|
||||
v, ok := s.store[uri]
|
||||
debugLog("got %q from resolution cache: %t", uri, ok)
|
||||
|
||||
s.lock.Unlock()
|
||||
return v, ok
|
||||
}
|
||||
|
|
@ -59,9 +81,9 @@ func (s *simpleCache) Set(uri string, data interface{}) {
|
|||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
// ResolveRef resolves a reference against a context root
|
||||
func ResolveRef(root interface{}, ref *Ref) (*Schema, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, nil)
|
||||
// ResolveRefWithBase resolves a reference against a context root with preservation of base path
|
||||
func ResolveRefWithBase(root interface{}, ref *Ref, opts *ExpandOptions) (*Schema, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, opts, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -73,9 +95,19 @@ func ResolveRef(root interface{}, ref *Ref) (*Schema, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// ResolveRef resolves a reference against a context root
|
||||
func ResolveRef(root interface{}, ref *Ref) (*Schema, error) {
|
||||
return ResolveRefWithBase(root, ref, nil)
|
||||
}
|
||||
|
||||
// ResolveParameter resolves a paramter reference against a context root
|
||||
func ResolveParameter(root interface{}, ref Ref) (*Parameter, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, nil)
|
||||
return ResolveParameterWithBase(root, ref, nil)
|
||||
}
|
||||
|
||||
// ResolveParameterWithBase resolves a paramter reference against a context root and base path
|
||||
func ResolveParameterWithBase(root interface{}, ref Ref, opts *ExpandOptions) (*Parameter, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, opts, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -89,7 +121,12 @@ func ResolveParameter(root interface{}, ref Ref) (*Parameter, error) {
|
|||
|
||||
// ResolveResponse resolves response a reference against a context root
|
||||
func ResolveResponse(root interface{}, ref Ref) (*Response, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, nil)
|
||||
return ResolveResponseWithBase(root, ref, nil)
|
||||
}
|
||||
|
||||
// ResolveResponseWithBase resolves response a reference against a context root and base path
|
||||
func ResolveResponseWithBase(root interface{}, ref Ref, opts *ExpandOptions) (*Response, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, opts, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -101,23 +138,72 @@ func ResolveResponse(root interface{}, ref Ref) (*Response, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// ResolveItems resolves header and parameter items reference against a context root and base path
|
||||
func ResolveItems(root interface{}, ref Ref, opts *ExpandOptions) (*Items, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, opts, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := new(Items)
|
||||
if err := resolver.Resolve(&ref, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ResolvePathItem resolves response a path item against a context root and base path
|
||||
func ResolvePathItem(root interface{}, ref Ref, opts *ExpandOptions) (*PathItem, error) {
|
||||
resolver, err := defaultSchemaLoader(root, nil, opts, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := new(PathItem)
|
||||
if err := resolver.Resolve(&ref, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type schemaLoader struct {
|
||||
loadingRef *Ref
|
||||
startingRef *Ref
|
||||
currentRef *Ref
|
||||
root interface{}
|
||||
options *ExpandOptions
|
||||
cache ResolutionCache
|
||||
loadDoc func(string) (json.RawMessage, error)
|
||||
}
|
||||
|
||||
var idPtr, _ = jsonpointer.New("/id")
|
||||
var schemaPtr, _ = jsonpointer.New("/$schema")
|
||||
var refPtr, _ = jsonpointer.New("/$ref")
|
||||
|
||||
func defaultSchemaLoader(root interface{}, ref *Ref, cache ResolutionCache) (*schemaLoader, error) {
|
||||
// PathLoader function to use when loading remote refs
|
||||
var PathLoader func(string) (json.RawMessage, error)
|
||||
|
||||
func init() {
|
||||
PathLoader = func(path string) (json.RawMessage, error) {
|
||||
data, err := swag.LoadFromFileOrHTTP(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.RawMessage(data), nil
|
||||
}
|
||||
}
|
||||
|
||||
func defaultSchemaLoader(
|
||||
root interface{},
|
||||
ref *Ref,
|
||||
expandOptions *ExpandOptions,
|
||||
cache ResolutionCache) (*schemaLoader, error) {
|
||||
|
||||
if cache == nil {
|
||||
cache = resCache
|
||||
}
|
||||
if expandOptions == nil {
|
||||
expandOptions = &ExpandOptions{}
|
||||
}
|
||||
|
||||
var ptr *jsonpointer.Pointer
|
||||
if ref != nil {
|
||||
|
|
@ -127,18 +213,16 @@ func defaultSchemaLoader(root interface{}, ref *Ref, cache ResolutionCache) (*sc
|
|||
currentRef := nextRef(root, ref, ptr)
|
||||
|
||||
return &schemaLoader{
|
||||
root: root,
|
||||
loadingRef: ref,
|
||||
startingRef: ref,
|
||||
currentRef: currentRef,
|
||||
root: root,
|
||||
options: expandOptions,
|
||||
cache: cache,
|
||||
loadDoc: func(path string) (json.RawMessage, error) {
|
||||
data, err := swag.LoadFromFileOrHTTP(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.RawMessage(data), nil
|
||||
debugLog("fetching document at %q", path)
|
||||
return PathLoader(path)
|
||||
},
|
||||
currentRef: currentRef,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -159,6 +243,7 @@ func nextRef(startingNode interface{}, startingRef *Ref, ptr *jsonpointer.Pointe
|
|||
if startingRef == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ptr == nil {
|
||||
return startingRef
|
||||
}
|
||||
|
|
@ -184,32 +269,111 @@ func nextRef(startingNode interface{}, startingRef *Ref, ptr *jsonpointer.Pointe
|
|||
|
||||
refRef, _, _ := refPtr.Get(node)
|
||||
if refRef != nil {
|
||||
rf, _ := NewRef(refRef.(string))
|
||||
var rf Ref
|
||||
switch value := refRef.(type) {
|
||||
case string:
|
||||
rf, _ = NewRef(value)
|
||||
}
|
||||
nw, err := ret.Inherits(rf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
nwURL := nw.GetURL()
|
||||
if nwURL.Scheme == "file" || (nwURL.Scheme == "" && nwURL.Host == "") {
|
||||
nwpt := filepath.ToSlash(nwURL.Path)
|
||||
if filepath.IsAbs(nwpt) {
|
||||
_, err := os.Stat(nwpt)
|
||||
if err != nil {
|
||||
nwURL.Path = filepath.Join(".", nwpt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = nw
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func debugLog(msg string, args ...interface{}) {
|
||||
if Debug {
|
||||
log.Printf(msg, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeFileRef(ref *Ref, relativeBase string) *Ref {
|
||||
refURL := ref.GetURL()
|
||||
debugLog("normalizing %s against %s (%s)", ref.String(), relativeBase, refURL.String())
|
||||
if strings.HasPrefix(refURL.String(), "#") {
|
||||
return ref
|
||||
}
|
||||
|
||||
if refURL.Scheme == "file" || (refURL.Scheme == "" && refURL.Host == "") {
|
||||
filePath := refURL.Path
|
||||
debugLog("normalizing file path: %s", filePath)
|
||||
|
||||
if !filepath.IsAbs(filepath.FromSlash(filePath)) && len(relativeBase) != 0 {
|
||||
debugLog("joining %s with %s", relativeBase, filePath)
|
||||
if fi, err := os.Stat(filepath.FromSlash(relativeBase)); err == nil {
|
||||
if !fi.IsDir() {
|
||||
relativeBase = filepath.Dir(filepath.FromSlash(relativeBase))
|
||||
}
|
||||
}
|
||||
filePath = filepath.Join(filepath.FromSlash(relativeBase), filepath.FromSlash(filePath))
|
||||
}
|
||||
if !filepath.IsAbs(filepath.FromSlash(filePath)) {
|
||||
pwd, err := os.Getwd()
|
||||
if err == nil {
|
||||
debugLog("joining cwd %s with %s", pwd, filePath)
|
||||
filePath = filepath.Join(pwd, filepath.FromSlash(filePath))
|
||||
}
|
||||
}
|
||||
|
||||
debugLog("cleaning %s", filePath)
|
||||
filePath = filepath.Clean(filepath.FromSlash(filePath))
|
||||
_, err := os.Stat(filepath.FromSlash(filePath))
|
||||
if err == nil {
|
||||
debugLog("rewriting url %s to scheme \"\" path %s", refURL.String(), filePath)
|
||||
slp := filepath.FromSlash(filePath)
|
||||
if filepath.IsAbs(slp) && filepath.Separator == '\\' && len(slp) > 1 && slp[1] == ':' && ('a' <= slp[0] && slp[0] <= 'z' || 'A' <= slp[0] && slp[0] <= 'Z') {
|
||||
slp = slp[2:]
|
||||
}
|
||||
refURL.Scheme = ""
|
||||
refURL.Path = filepath.ToSlash(slp)
|
||||
debugLog("new url with joined filepath: %s", refURL.String())
|
||||
*ref = MustCreateRef(refURL.String())
|
||||
}
|
||||
}
|
||||
|
||||
debugLog("refurl: %s", ref.GetURL().String())
|
||||
return ref
|
||||
}
|
||||
|
||||
func (r *schemaLoader) resolveRef(currentRef, ref *Ref, node, target interface{}) error {
|
||||
|
||||
tgt := reflect.ValueOf(target)
|
||||
if tgt.Kind() != reflect.Ptr {
|
||||
return fmt.Errorf("resolve ref: target needs to be a pointer")
|
||||
}
|
||||
|
||||
oldRef := currentRef
|
||||
|
||||
if currentRef != nil {
|
||||
debugLog("resolve ref current %s new %s", currentRef.String(), ref.String())
|
||||
nextRef := nextRef(node, ref, currentRef.GetPointer())
|
||||
if nextRef == nil || nextRef.GetURL() == nil {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
currentRef, err = currentRef.Inherits(*nextRef(node, ref, currentRef.GetPointer()))
|
||||
currentRef, err = currentRef.Inherits(*nextRef)
|
||||
debugLog("resolved ref current %s", currentRef.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if currentRef == nil {
|
||||
currentRef = ref
|
||||
}
|
||||
|
|
@ -245,42 +409,71 @@ func (r *schemaLoader) resolveRef(currentRef, ref *Ref, node, target interface{}
|
|||
return nil
|
||||
}
|
||||
|
||||
if refURL.Scheme != "" && refURL.Host != "" {
|
||||
// most definitely take the red pill
|
||||
data, _, _, err := r.load(refURL)
|
||||
relativeBase := ""
|
||||
if r.options != nil && r.options.RelativeBase != "" {
|
||||
relativeBase = r.options.RelativeBase
|
||||
}
|
||||
normalizeFileRef(currentRef, relativeBase)
|
||||
debugLog("current ref normalized file: %s", currentRef.String())
|
||||
normalizeFileRef(ref, relativeBase)
|
||||
debugLog("ref normalized file: %s", currentRef.String())
|
||||
|
||||
data, _, _, err := r.load(currentRef.GetURL())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ((oldRef == nil && currentRef != nil) ||
|
||||
(oldRef != nil && currentRef == nil) ||
|
||||
oldRef.String() != currentRef.String()) &&
|
||||
((oldRef == nil && ref != nil) ||
|
||||
(oldRef != nil && ref == nil) ||
|
||||
(oldRef.String() != ref.String())) {
|
||||
|
||||
return r.resolveRef(currentRef, ref, data, target)
|
||||
}
|
||||
|
||||
var res interface{}
|
||||
if currentRef.String() != "" {
|
||||
res, _, err = currentRef.GetPointer().Get(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.HasPrefix(ref.String(), "#") {
|
||||
if r.loadingRef != nil {
|
||||
rr, er := r.loadingRef.Inherits(*ref)
|
||||
if er != nil {
|
||||
return er
|
||||
}
|
||||
refURL = rr.GetURL()
|
||||
|
||||
if ((oldRef == nil && currentRef != nil) ||
|
||||
(oldRef != nil && currentRef == nil) ||
|
||||
oldRef.String() != currentRef.String()) &&
|
||||
((oldRef == nil && ref != nil) ||
|
||||
(oldRef != nil && ref == nil) ||
|
||||
(oldRef.String() != ref.String())) {
|
||||
data, _, _, err = r.load(refURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
data = r.root
|
||||
}
|
||||
}
|
||||
|
||||
return r.resolveRef(currentRef, ref, data, target)
|
||||
}
|
||||
|
||||
var res interface{}
|
||||
if currentRef.String() != "" {
|
||||
res, _, err = currentRef.GetPointer().Get(data)
|
||||
res, _, err = ref.GetPointer().Get(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
res = data
|
||||
}
|
||||
|
||||
if err := swag.DynamicJSONToStruct(res, target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else {
|
||||
res = data
|
||||
}
|
||||
|
||||
if err := swag.DynamicJSONToStruct(res, target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.currentRef = currentRef
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error) {
|
||||
debugLog("loading schema from url: %s", refURL)
|
||||
toFetch := *refURL
|
||||
toFetch.Fragment = ""
|
||||
|
||||
|
|
@ -299,44 +492,51 @@ func (r *schemaLoader) load(refURL *url.URL) (interface{}, url.URL, bool, error)
|
|||
|
||||
return data, toFetch, fromCache, nil
|
||||
}
|
||||
func (r *schemaLoader) Resolve(ref *Ref, target interface{}) error {
|
||||
if err := r.resolveRef(r.currentRef, ref, r.root, target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
func (r *schemaLoader) Resolve(ref *Ref, target interface{}) error {
|
||||
return r.resolveRef(r.currentRef, ref, r.root, target)
|
||||
}
|
||||
|
||||
type specExpander struct {
|
||||
spec *Swagger
|
||||
resolver *schemaLoader
|
||||
func (r *schemaLoader) reset() {
|
||||
ref := r.startingRef
|
||||
|
||||
var ptr *jsonpointer.Pointer
|
||||
if ref != nil {
|
||||
ptr = ref.GetPointer()
|
||||
}
|
||||
|
||||
r.currentRef = nextRef(r.root, ref, ptr)
|
||||
}
|
||||
|
||||
// ExpandSpec expands the references in a swagger spec
|
||||
func ExpandSpec(spec *Swagger) error {
|
||||
resolver, err := defaultSchemaLoader(spec, nil, nil)
|
||||
if err != nil {
|
||||
func ExpandSpec(spec *Swagger, options *ExpandOptions) error {
|
||||
resolver, err := defaultSchemaLoader(spec, nil, options, nil)
|
||||
// Just in case this ever returns an error.
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, defintition := range spec.Definitions {
|
||||
var def *Schema
|
||||
var err error
|
||||
if def, err = expandSchema(defintition, []string{"#/definitions/" + key}, resolver); err != nil {
|
||||
return err
|
||||
if options == nil || !options.SkipSchemas {
|
||||
for key, definition := range spec.Definitions {
|
||||
var def *Schema
|
||||
var err error
|
||||
if def, err = expandSchema(definition, []string{"#/definitions/" + key}, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
resolver.reset()
|
||||
spec.Definitions[key] = *def
|
||||
}
|
||||
spec.Definitions[key] = *def
|
||||
}
|
||||
|
||||
for key, parameter := range spec.Parameters {
|
||||
if err := expandParameter(¶meter, resolver); err != nil {
|
||||
if err := expandParameter(¶meter, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
spec.Parameters[key] = parameter
|
||||
}
|
||||
|
||||
for key, response := range spec.Responses {
|
||||
if err := expandResponse(&response, resolver); err != nil {
|
||||
if err := expandResponse(&response, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
spec.Responses[key] = response
|
||||
|
|
@ -344,7 +544,7 @@ func ExpandSpec(spec *Swagger) error {
|
|||
|
||||
if spec.Paths != nil {
|
||||
for key, path := range spec.Paths.Paths {
|
||||
if err := expandPathItem(&path, resolver); err != nil {
|
||||
if err := expandPathItem(&path, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
spec.Paths.Paths[key] = path
|
||||
|
|
@ -354,9 +554,25 @@ func ExpandSpec(spec *Swagger) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func shouldStopOnError(err error, opts *ExpandOptions) bool {
|
||||
if err != nil && !opts.ContinueOnError {
|
||||
return true
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ExpandSchema expands the refs in the schema object
|
||||
func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error {
|
||||
return ExpandSchemaWithBasePath(schema, root, cache, nil)
|
||||
}
|
||||
|
||||
// ExpandSchemaWithBasePath expands the refs in the schema object, base path configured through expand options
|
||||
func ExpandSchemaWithBasePath(schema *Schema, root interface{}, cache ResolutionCache, opts *ExpandOptions) error {
|
||||
if schema == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -367,18 +583,17 @@ func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error
|
|||
nrr, _ := NewRef(schema.ID)
|
||||
var rrr *Ref
|
||||
if nrr.String() != "" {
|
||||
switch root.(type) {
|
||||
switch rt := root.(type) {
|
||||
case *Schema:
|
||||
rid, _ := NewRef(root.(*Schema).ID)
|
||||
rid, _ := NewRef(rt.ID)
|
||||
rrr, _ = rid.Inherits(nrr)
|
||||
case *Swagger:
|
||||
rid, _ := NewRef(root.(*Swagger).ID)
|
||||
rid, _ := NewRef(rt.ID)
|
||||
rrr, _ = rid.Inherits(nrr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resolver, err := defaultSchemaLoader(root, rrr, cache)
|
||||
resolver, err := defaultSchemaLoader(root, rrr, opts, cache)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -389,7 +604,7 @@ func ExpandSchema(schema *Schema, root interface{}, cache ResolutionCache) error
|
|||
}
|
||||
var s *Schema
|
||||
if s, err = expandSchema(*schema, refs, resolver); err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
*schema = *s
|
||||
return nil
|
||||
|
|
@ -400,7 +615,15 @@ func expandItems(target Schema, parentRefs []string, resolver *schemaLoader) (*S
|
|||
if target.Items.Schema != nil {
|
||||
t, err := expandSchema(*target.Items.Schema, parentRefs, resolver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if target.Items.Schema.ID == "" {
|
||||
target.Items.Schema.ID = target.ID
|
||||
if err != nil {
|
||||
t, err = expandSchema(*target.Items.Schema, parentRefs, resolver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*target.Items.Schema = *t
|
||||
}
|
||||
|
|
@ -415,137 +638,173 @@ func expandItems(target Schema, parentRefs []string, resolver *schemaLoader) (*S
|
|||
return &target, nil
|
||||
}
|
||||
|
||||
func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader) (schema *Schema, err error) {
|
||||
defer func() {
|
||||
schema = &target
|
||||
}()
|
||||
func expandSchema(target Schema, parentRefs []string, resolver *schemaLoader) (*Schema, error) {
|
||||
if target.Ref.String() == "" && target.Ref.IsRoot() {
|
||||
target = *resolver.root.(*Schema)
|
||||
return
|
||||
debugLog("skipping expand schema for no ref and root: %v", resolver.root)
|
||||
|
||||
return resolver.root.(*Schema), nil
|
||||
}
|
||||
|
||||
// t is the new expanded schema
|
||||
var t *Schema
|
||||
|
||||
for target.Ref.String() != "" {
|
||||
// var newTarget Schema
|
||||
pRefs := strings.Join(parentRefs, ",")
|
||||
pRefs += ","
|
||||
if strings.Contains(pRefs, target.Ref.String()+",") {
|
||||
err = nil
|
||||
return
|
||||
if swag.ContainsStringsCI(parentRefs, target.Ref.String()) {
|
||||
return &target, nil
|
||||
}
|
||||
|
||||
if err = resolver.Resolve(&target.Ref, &t); err != nil {
|
||||
return
|
||||
if err := resolver.Resolve(&target.Ref, &t); shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
|
||||
if swag.ContainsStringsCI(parentRefs, target.Ref.String()) {
|
||||
debugLog("ref already exists in parent")
|
||||
return &target, nil
|
||||
}
|
||||
parentRefs = append(parentRefs, target.Ref.String())
|
||||
if t != nil {
|
||||
target = *t
|
||||
}
|
||||
}
|
||||
|
||||
t, err := expandItems(target, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
target = *t
|
||||
}
|
||||
|
||||
if t, err = expandItems(target, parentRefs, resolver); err != nil {
|
||||
return
|
||||
}
|
||||
target = *t
|
||||
|
||||
for i := range target.AllOf {
|
||||
if t, err = expandSchema(target.AllOf[i], parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(target.AllOf[i], parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
target.AllOf[i] = *t
|
||||
}
|
||||
target.AllOf[i] = *t
|
||||
}
|
||||
for i := range target.AnyOf {
|
||||
if t, err = expandSchema(target.AnyOf[i], parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(target.AnyOf[i], parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
target.AnyOf[i] = *t
|
||||
}
|
||||
for i := range target.OneOf {
|
||||
if t, err = expandSchema(target.OneOf[i], parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(target.OneOf[i], parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
target.OneOf[i] = *t
|
||||
}
|
||||
target.OneOf[i] = *t
|
||||
}
|
||||
if target.Not != nil {
|
||||
if t, err = expandSchema(*target.Not, parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(*target.Not, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
*target.Not = *t
|
||||
}
|
||||
*target.Not = *t
|
||||
}
|
||||
for k, _ := range target.Properties {
|
||||
if t, err = expandSchema(target.Properties[k], parentRefs, resolver); err != nil {
|
||||
return
|
||||
for k := range target.Properties {
|
||||
t, err := expandSchema(target.Properties[k], parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
target.Properties[k] = *t
|
||||
}
|
||||
target.Properties[k] = *t
|
||||
}
|
||||
if target.AdditionalProperties != nil && target.AdditionalProperties.Schema != nil {
|
||||
if t, err = expandSchema(*target.AdditionalProperties.Schema, parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(*target.AdditionalProperties.Schema, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
*target.AdditionalProperties.Schema = *t
|
||||
}
|
||||
for k, _ := range target.PatternProperties {
|
||||
if t, err = expandSchema(target.PatternProperties[k], parentRefs, resolver); err != nil {
|
||||
return
|
||||
if t != nil {
|
||||
*target.AdditionalProperties.Schema = *t
|
||||
}
|
||||
target.PatternProperties[k] = *t
|
||||
}
|
||||
for k, _ := range target.Dependencies {
|
||||
for k := range target.PatternProperties {
|
||||
t, err := expandSchema(target.PatternProperties[k], parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
target.PatternProperties[k] = *t
|
||||
}
|
||||
}
|
||||
for k := range target.Dependencies {
|
||||
if target.Dependencies[k].Schema != nil {
|
||||
if t, err = expandSchema(*target.Dependencies[k].Schema, parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(*target.Dependencies[k].Schema, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
*target.Dependencies[k].Schema = *t
|
||||
}
|
||||
*target.Dependencies[k].Schema = *t
|
||||
}
|
||||
}
|
||||
if target.AdditionalItems != nil && target.AdditionalItems.Schema != nil {
|
||||
if t, err = expandSchema(*target.AdditionalItems.Schema, parentRefs, resolver); err != nil {
|
||||
return
|
||||
t, err := expandSchema(*target.AdditionalItems.Schema, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
*target.AdditionalItems.Schema = *t
|
||||
}
|
||||
for k, _ := range target.Definitions {
|
||||
if t, err = expandSchema(target.Definitions[k], parentRefs, resolver); err != nil {
|
||||
return
|
||||
if t != nil {
|
||||
*target.AdditionalItems.Schema = *t
|
||||
}
|
||||
target.Definitions[k] = *t
|
||||
}
|
||||
return
|
||||
for k := range target.Definitions {
|
||||
t, err := expandSchema(target.Definitions[k], parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return &target, err
|
||||
}
|
||||
if t != nil {
|
||||
target.Definitions[k] = *t
|
||||
}
|
||||
}
|
||||
return &target, nil
|
||||
}
|
||||
|
||||
func expandPathItem(pathItem *PathItem, resolver *schemaLoader) error {
|
||||
if pathItem == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if pathItem.Ref.String() != "" {
|
||||
if err := resolver.Resolve(&pathItem.Ref, &pathItem); err != nil {
|
||||
return err
|
||||
}
|
||||
resolver.reset()
|
||||
pathItem.Ref = Ref{}
|
||||
}
|
||||
|
||||
for idx := range pathItem.Parameters {
|
||||
if err := expandParameter(&(pathItem.Parameters[idx]), resolver); err != nil {
|
||||
if err := expandParameter(&(pathItem.Parameters[idx]), resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := expandOperation(pathItem.Get, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Get, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if err := expandOperation(pathItem.Head, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Head, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if err := expandOperation(pathItem.Options, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Options, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if err := expandOperation(pathItem.Put, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Put, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if err := expandOperation(pathItem.Post, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Post, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if err := expandOperation(pathItem.Patch, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Patch, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if err := expandOperation(pathItem.Delete, resolver); err != nil {
|
||||
if err := expandOperation(pathItem.Delete, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
@ -555,8 +814,9 @@ func expandOperation(op *Operation, resolver *schemaLoader) error {
|
|||
if op == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for i, param := range op.Parameters {
|
||||
if err := expandParameter(¶m, resolver); err != nil {
|
||||
if err := expandParameter(¶m, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
op.Parameters[i] = param
|
||||
|
|
@ -564,11 +824,11 @@ func expandOperation(op *Operation, resolver *schemaLoader) error {
|
|||
|
||||
if op.Responses != nil {
|
||||
responses := op.Responses
|
||||
if err := expandResponse(responses.Default, resolver); err != nil {
|
||||
if err := expandResponse(responses.Default, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
for code, response := range responses.StatusCodeResponses {
|
||||
if err := expandResponse(&response, resolver); err != nil {
|
||||
if err := expandResponse(&response, resolver); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
responses.StatusCodeResponses[code] = response
|
||||
|
|
@ -582,22 +842,29 @@ func expandResponse(response *Response, resolver *schemaLoader) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var parentRefs []string
|
||||
|
||||
if response.Ref.String() != "" {
|
||||
if err := resolver.Resolve(&response.Ref, response); err != nil {
|
||||
parentRefs = append(parentRefs, response.Ref.String())
|
||||
if err := resolver.Resolve(&response.Ref, response); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
resolver.reset()
|
||||
response.Ref = Ref{}
|
||||
}
|
||||
|
||||
if response.Schema != nil {
|
||||
parentRefs := []string{response.Schema.Ref.String()}
|
||||
if err := resolver.Resolve(&response.Schema.Ref, &response.Schema); err != nil {
|
||||
if !resolver.options.SkipSchemas && response.Schema != nil {
|
||||
parentRefs = append(parentRefs, response.Schema.Ref.String())
|
||||
debugLog("response ref: %s", response.Schema.Ref)
|
||||
if err := resolver.Resolve(&response.Schema.Ref, &response.Schema); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if s, err := expandSchema(*response.Schema, parentRefs, resolver); err != nil {
|
||||
s, err := expandSchema(*response.Schema, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
} else {
|
||||
*response.Schema = *s
|
||||
}
|
||||
resolver.reset()
|
||||
*response.Schema = *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -606,21 +873,28 @@ func expandParameter(parameter *Parameter, resolver *schemaLoader) error {
|
|||
if parameter == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var parentRefs []string
|
||||
|
||||
if parameter.Ref.String() != "" {
|
||||
if err := resolver.Resolve(¶meter.Ref, parameter); err != nil {
|
||||
parentRefs = append(parentRefs, parameter.Ref.String())
|
||||
if err := resolver.Resolve(¶meter.Ref, parameter); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
resolver.reset()
|
||||
parameter.Ref = Ref{}
|
||||
}
|
||||
if parameter.Schema != nil {
|
||||
parentRefs := []string{parameter.Schema.Ref.String()}
|
||||
if err := resolver.Resolve(¶meter.Schema.Ref, ¶meter.Schema); err != nil {
|
||||
if !resolver.options.SkipSchemas && parameter.Schema != nil {
|
||||
parentRefs = append(parentRefs, parameter.Schema.Ref.String())
|
||||
if err := resolver.Resolve(¶meter.Schema.Ref, ¶meter.Schema); shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
}
|
||||
if s, err := expandSchema(*parameter.Schema, parentRefs, resolver); err != nil {
|
||||
s, err := expandSchema(*parameter.Schema, parentRefs, resolver)
|
||||
if shouldStopOnError(err, resolver.options) {
|
||||
return err
|
||||
} else {
|
||||
*parameter.Schema = *s
|
||||
}
|
||||
resolver.reset()
|
||||
*parameter.Schema = *s
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
1162
vendor/github.com/go-openapi/spec/expander_test.go
generated
vendored
Normal file
1162
vendor/github.com/go-openapi/spec/expander_test.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
29
vendor/github.com/go-openapi/spec/external_docs_test.go
generated
vendored
Normal file
29
vendor/github.com/go-openapi/spec/external_docs_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIntegrationExternalDocs(t *testing.T) {
|
||||
var extDocs = ExternalDocumentation{"the name", "the url"}
|
||||
const extDocsYAML = "description: the name\nurl: the url\n"
|
||||
const extDocsJSON = `{"description":"the name","url":"the url"}`
|
||||
assertSerializeJSON(t, extDocs, extDocsJSON)
|
||||
assertSerializeYAML(t, extDocs, extDocsYAML)
|
||||
assertParsesJSON(t, extDocsJSON, extDocs)
|
||||
assertParsesYAML(t, extDocsYAML, extDocs)
|
||||
}
|
||||
254
vendor/github.com/go-openapi/spec/fixtures/expansion/all-the-things.json
generated
vendored
Normal file
254
vendor/github.com/go-openapi/spec/fixtures/expansion/all-the-things.json
generated
vendored
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"contact": {
|
||||
"name": "Wordnik API Team"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"basePath": "/api",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": {
|
||||
"idParam": {
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of pet to fetch",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
"query": {
|
||||
"$ref": "#/parameters/tag"
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"petResponse": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/pet"
|
||||
}
|
||||
},
|
||||
"stringResponse": {
|
||||
"descripion": "string response",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"anotherPet": {
|
||||
"$ref": "#/responses/petResponse"
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"operationId": "indexStuff",
|
||||
"responses": {
|
||||
"default": {
|
||||
"$ref": "#/responses/stringResponse"
|
||||
},
|
||||
"200": {
|
||||
"$ref": "#/responses/anotherPet"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pets": {
|
||||
"get": {
|
||||
"description": "Returns all pets from the system that the user has access to",
|
||||
"operationId": "findPets",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "csv"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "maximum number of results to return",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Creates a new pet in the store. Duplicates are allowed",
|
||||
"operationId": "addPet",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "pet",
|
||||
"in": "body",
|
||||
"description": "Pet to add to the store",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/petInput"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": { "$ref": "#/responses/petResponse" },
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pets/{id}": {
|
||||
"get": {
|
||||
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
|
||||
"operationId": "findPetById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/idParam"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/petResponse"
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "deletes a single pet based on the ID supplied",
|
||||
"operationId": "deletePet",
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/idParam"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "pet deleted"
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"pet": {
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"petInput": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/pet"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"errorModel": {
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
54
vendor/github.com/go-openapi/spec/fixtures/expansion/circularRefs.json
generated
vendored
Normal file
54
vendor/github.com/go-openapi/spec/fixtures/expansion/circularRefs.json
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"definitions": {
|
||||
"brand": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"category": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"children": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/category"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"car": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"make": {
|
||||
"type": "string"
|
||||
},
|
||||
"similar": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/car"
|
||||
}
|
||||
},
|
||||
"notSimilar": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/car"
|
||||
}
|
||||
},
|
||||
"oneCar": {
|
||||
"$ref": "#/definitions/car"
|
||||
},
|
||||
"category": {
|
||||
"$ref": "#/definitions/category"
|
||||
},
|
||||
"brand": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.json
generated
vendored
Normal file
1
vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.json
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"swagger":"2.0","info":{"title":"Swagger Sample","description":"Sample API Playground.","version":"1.0.0"},"basePath":"/v1","schemes":["http"],"consumes":["application/vdn.sample.v1+json"],"produces":["application/vdn.sample.v1+json"],"paths":{"/books":{"get":{"summary":"List all books","operationId":"listBooks","tags":["books"],"responses":{"200":{"headers":{"Link":{"type":"string"}},"description":"An array of books","schema":{"type":"array","items":{"$ref":"#/definitions/Book"}}},"default":{"description":"generic error response","schema":{"$ref":"#/definitions/Error"}}}}}},"definitions":{"Book":{"type":"object","required":["title","summary"],"properties":{"title":{"type":"string","example":"Winnie the Pooh"},"summary":{"type":"string","example":"Famous children's book"},"related_books":{"type":"array","items":{"$ref":"#/definitions/Book"}}}},"Error":{"type":"object","readOnly":true,"properties":{"code":{"type":"integer","format":"int64","example":400},"message":{"type":"string","example":"Unexpected error"}},"required":["message"]}}}
|
||||
67
vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.yaml
generated
vendored
Normal file
67
vendor/github.com/go-openapi/spec/fixtures/expansion/circularSpec.yaml
generated
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
---
|
||||
swagger: "2.0"
|
||||
info:
|
||||
title: Swagger Sample
|
||||
description: Sample API Playground.
|
||||
version: 1.0.0
|
||||
basePath: /v1
|
||||
schemes:
|
||||
- http
|
||||
consumes:
|
||||
- application/vdn.sample.v1+json
|
||||
produces:
|
||||
- application/vdn.sample.v1+json
|
||||
|
||||
paths:
|
||||
/books:
|
||||
get:
|
||||
summary: List all books
|
||||
operationId: listBooks
|
||||
tags:
|
||||
- books
|
||||
responses:
|
||||
200:
|
||||
headers:
|
||||
Link:
|
||||
type: string
|
||||
description: An array of books
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/Book"
|
||||
default:
|
||||
description: generic error response
|
||||
schema:
|
||||
$ref: "#/definitions/Error"
|
||||
|
||||
definitions:
|
||||
Book:
|
||||
type: object
|
||||
required:
|
||||
- title
|
||||
- summary
|
||||
properties:
|
||||
title:
|
||||
type: string
|
||||
example: Winnie the Pooh
|
||||
summary:
|
||||
type: string
|
||||
example: Famous children's book
|
||||
related_books:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/definitions/Book"
|
||||
|
||||
Error:
|
||||
type: object
|
||||
readOnly: true
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 400
|
||||
message:
|
||||
type: string
|
||||
example: Unexpected error
|
||||
required:
|
||||
- message
|
||||
1
vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.json
generated
vendored
Normal file
1
vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
6461
vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.yaml
generated
vendored
Normal file
6461
vendor/github.com/go-openapi/spec/fixtures/expansion/clickmeter.yaml
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
85
vendor/github.com/go-openapi/spec/fixtures/expansion/invalid-refs.json
generated
vendored
Normal file
85
vendor/github.com/go-openapi/spec/fixtures/expansion/invalid-refs.json
generated
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"contact": {
|
||||
"name": "wordnik api team",
|
||||
"url": "http://developer.wordnik.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "Creative Commons 4.0 International",
|
||||
"url": "http://creativecommons.org/licenses/by/4.0/"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"basePath": "/api",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"get": {
|
||||
"tags": [ "Pet Operations" ],
|
||||
"summary": "finds pets in the system",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "NotCorrectRef"
|
||||
}
|
||||
},
|
||||
"headers": {
|
||||
"x-expires": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "NotCorrectRef"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Pet": {
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/go-openapi/spec/fixtures/expansion/missingItemRef.json
generated
vendored
Normal file
31
vendor/github.com/go-openapi/spec/fixtures/expansion/missingItemRef.json
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "2.1.0",
|
||||
"title": "Missing Item API"
|
||||
},
|
||||
"host": "item.com",
|
||||
"basePath": "/missing/ref",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"paths": {
|
||||
"/employees": {
|
||||
"get": {
|
||||
"operationId": "LIST-Employees",
|
||||
"summary": "List Employee Types",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/employees-output"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
165
vendor/github.com/go-openapi/spec/fixtures/expansion/missingRef.json
generated
vendored
Normal file
165
vendor/github.com/go-openapi/spec/fixtures/expansion/missingRef.json
generated
vendored
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
{
|
||||
"input": {
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "1.0",
|
||||
"title": "Continue On Error"
|
||||
},
|
||||
"paths": {
|
||||
"/todos": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "List Todos",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/todo-full"
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"$ref": "#/responses/404"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"todo-partial": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"completed": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"todo-full": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/todo-partial"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"completed_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Continue On Error",
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/todos": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "List Todos",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"allOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"404": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"todo-full": {
|
||||
"allOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"todo-partial": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
124
vendor/github.com/go-openapi/spec/fixtures/expansion/overflow.json
generated
vendored
Normal file
124
vendor/github.com/go-openapi/spec/fixtures/expansion/overflow.json
generated
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Swagger Sample",
|
||||
"description": "Sample API Playground.",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"basePath": "/v1",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"consumes": [
|
||||
"application/vdn.sample.v1+json"
|
||||
],
|
||||
"produces": [
|
||||
"application/vdn.sample.v1+json"
|
||||
],
|
||||
"paths": {
|
||||
"/books": {
|
||||
"get": {
|
||||
"summary": "List all books",
|
||||
"operationId": "listBooks",
|
||||
"tags": [
|
||||
"books"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"headers": {
|
||||
"Link": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"description": "An array of books",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Book"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "generic error response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Store": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"example": "Book Shop"
|
||||
},
|
||||
"categories": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Category"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Category": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"example": "Drama"
|
||||
},
|
||||
"books": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Book"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Book": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"title",
|
||||
"summary"
|
||||
],
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"example": "Winnie the Pooh"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"example": "Famous children's book"
|
||||
},
|
||||
"related_books": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Book"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"readOnly": true,
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"example": 400
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "Unexpected error"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"message"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
25
vendor/github.com/go-openapi/spec/fixtures/expansion/params.json
generated
vendored
Normal file
25
vendor/github.com/go-openapi/spec/fixtures/expansion/params.json
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"parameters": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
"tag": {
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
"query": {
|
||||
"$ref": "#/parameters/tag"
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"/cars/{id}": {
|
||||
"parameters": [
|
||||
{ "$ref": "#/parameters/id"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
127
vendor/github.com/go-openapi/spec/fixtures/expansion/schemas1.json
generated
vendored
Normal file
127
vendor/github.com/go-openapi/spec/fixtures/expansion/schemas1.json
generated
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
{
|
||||
"definitions": {
|
||||
"car": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"make": {
|
||||
"type": "string"
|
||||
},
|
||||
"brand": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tag": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"brand": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"truck": {
|
||||
"$ref": "#/definitions/car"
|
||||
},
|
||||
"batch": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
},
|
||||
"batch2": {
|
||||
"items": [
|
||||
{
|
||||
"$ref": "#/definitions/brand"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
]
|
||||
},
|
||||
"allofBoth": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/brand"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
]
|
||||
},
|
||||
"anyofBoth": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/brand"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
]
|
||||
},
|
||||
"oneofBoth": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/brand"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
]
|
||||
},
|
||||
"notSomething": {
|
||||
"not": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
},
|
||||
"withAdditional": {
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
},
|
||||
"withPattern": {
|
||||
"patternProperties": {
|
||||
"^x-ab": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
},
|
||||
"withAdditionalItems": {
|
||||
"additionalItems": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
},
|
||||
"deps": {
|
||||
"dependencies": {
|
||||
"something": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
},
|
||||
"defined": {
|
||||
"definitions": {
|
||||
"something": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
161
vendor/github.com/go-openapi/spec/fixtures/expansion/schemas2.json
generated
vendored
Normal file
161
vendor/github.com/go-openapi/spec/fixtures/expansion/schemas2.json
generated
vendored
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
{
|
||||
"definitions": {
|
||||
"car": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"make": {
|
||||
"type": "string"
|
||||
},
|
||||
"brand": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tag": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"brand": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"truck": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/car"
|
||||
}
|
||||
},
|
||||
"batch": {
|
||||
"items": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
}
|
||||
},
|
||||
"batch2": {
|
||||
"items": [
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
},
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"allofBoth": {
|
||||
"allOf": [
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
},
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"anyofBoth": {
|
||||
"anyOf": [
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
},
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"oneofBoth": {
|
||||
"oneOf": [
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/brand"
|
||||
}
|
||||
},
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"notSomething": {
|
||||
"not": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
},
|
||||
"withAdditional": {
|
||||
"additionalProperties": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
},
|
||||
"withPattern": {
|
||||
"patternProperties": {
|
||||
"^x-ab": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"withAdditionalItems": {
|
||||
"additionalItems": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
},
|
||||
"deps": {
|
||||
"dependencies": {
|
||||
"something": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"defined": {
|
||||
"definitions": {
|
||||
"something": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/tag"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
vendor/github.com/go-openapi/spec/fixtures/local_expansion/item.json
generated
vendored
Normal file
18
vendor/github.com/go-openapi/spec/fixtures/local_expansion/item.json
generated
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"properties": {
|
||||
"id": {
|
||||
"format": "int64",
|
||||
"readOnly": true,
|
||||
"type": "integer"
|
||||
},
|
||||
"title": {
|
||||
"maxLength": 80,
|
||||
"minLength": 2,
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"title"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
46
vendor/github.com/go-openapi/spec/fixtures/local_expansion/spec.json
generated
vendored
Normal file
46
vendor/github.com/go-openapi/spec/fixtures/local_expansion/spec.json
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"basePath": "/v1",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"host": "item.api.local",
|
||||
"info": {
|
||||
"description": "Item API",
|
||||
"title": "Item API",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"paths": {
|
||||
"/item": {
|
||||
"get": {
|
||||
"operationId": "GetItem",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "item detail response",
|
||||
"schema": {
|
||||
"$ref": "item.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"key": []
|
||||
}
|
||||
],
|
||||
"securityDefinitions": {
|
||||
"key": {
|
||||
"in": "header",
|
||||
"name": "x-item-token",
|
||||
"type": "apiKey"
|
||||
}
|
||||
},
|
||||
"swagger": "2.0"
|
||||
}
|
||||
6
vendor/github.com/go-openapi/spec/fixtures/specs/deeper/arrayProp.json
generated
vendored
Normal file
6
vendor/github.com/go-openapi/spec/fixtures/specs/deeper/arrayProp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"type":"array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
3
vendor/github.com/go-openapi/spec/fixtures/specs/deeper/stringProp.json
generated
vendored
Normal file
3
vendor/github.com/go-openapi/spec/fixtures/specs/deeper/stringProp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "string"
|
||||
}
|
||||
224
vendor/github.com/go-openapi/spec/fixtures/specs/refed.json
generated
vendored
Normal file
224
vendor/github.com/go-openapi/spec/fixtures/specs/refed.json
generated
vendored
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"contact": {
|
||||
"name": "Wordnik API Team"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"basePath": "/api",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": {
|
||||
"idParam": {
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of pet to fetch",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"petResponse": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"get": {
|
||||
"description": "Returns all pets from the system that the user has access to",
|
||||
"operationId": "findPets",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "csv"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "maximum number of results to return",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Creates a new pet in the store. Duplicates are allowed",
|
||||
"operationId": "addPet",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "pet",
|
||||
"in": "body",
|
||||
"description": "Pet to add to the store",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/petInput"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": { "$ref": "#/responses/petResponse" },
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pets/{id}": {
|
||||
"get": {
|
||||
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
|
||||
"operationId": "findPetById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/idParam"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/petResponse"
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "deletes a single pet based on the ID supplied",
|
||||
"operationId": "deletePet",
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/parameters/idParam"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "pet deleted"
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/errorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"pet": {
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"petInput": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "pet"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"errorModel": {
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
vendor/github.com/go-openapi/spec/fixtures/specs/resolution.json
generated
vendored
Normal file
14
vendor/github.com/go-openapi/spec/fixtures/specs/resolution.json
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"id": "http://localhost:1234",
|
||||
"items": {
|
||||
"id": "deeper/",
|
||||
"items": {
|
||||
"$ref": "stringProp.json"
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"bool": {
|
||||
"$ref": "boolProp.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
vendor/github.com/go-openapi/spec/fixtures/specs/resolution2.json
generated
vendored
Normal file
9
vendor/github.com/go-openapi/spec/fixtures/specs/resolution2.json
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"id": "http://localhost:1234",
|
||||
"items": {
|
||||
"id": "deeper/",
|
||||
"items": {
|
||||
"$ref": "arrayProp.json#/items"
|
||||
}
|
||||
}
|
||||
}
|
||||
30
vendor/github.com/go-openapi/spec/header.go
generated
vendored
30
vendor/github.com/go-openapi/spec/header.go
generated
vendored
|
|
@ -16,7 +16,9 @@ package spec
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/jsonpointer"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
|
|
@ -30,6 +32,7 @@ type HeaderProps struct {
|
|||
type Header struct {
|
||||
CommonValidations
|
||||
SimpleSchema
|
||||
VendorExtensible
|
||||
HeaderProps
|
||||
}
|
||||
|
||||
|
|
@ -158,8 +161,35 @@ func (h *Header) UnmarshalJSON(data []byte) error {
|
|||
if err := json.Unmarshal(data, &h.SimpleSchema); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(data, &h.VendorExtensible); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(data, &h.HeaderProps); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// JSONLookup look up a value by the json property name
|
||||
func (p Header) JSONLookup(token string) (interface{}, error) {
|
||||
if ex, ok := p.Extensions[token]; ok {
|
||||
return &ex, nil
|
||||
}
|
||||
|
||||
r, _, err := jsonpointer.GetForToken(p.CommonValidations, token)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
||||
return nil, err
|
||||
}
|
||||
if r != nil {
|
||||
return r, nil
|
||||
}
|
||||
r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
||||
return nil, err
|
||||
}
|
||||
if r != nil {
|
||||
return r, nil
|
||||
}
|
||||
r, _, err = jsonpointer.GetForToken(p.HeaderProps, token)
|
||||
return r, err
|
||||
}
|
||||
|
|
|
|||
90
vendor/github.com/go-openapi/spec/header_test.go
generated
vendored
Normal file
90
vendor/github.com/go-openapi/spec/header_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func float64Ptr(f float64) *float64 {
|
||||
return &f
|
||||
}
|
||||
func int64Ptr(f int64) *int64 {
|
||||
return &f
|
||||
}
|
||||
|
||||
var header = Header{
|
||||
VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{
|
||||
"x-framework": "swagger-go",
|
||||
}},
|
||||
HeaderProps: HeaderProps{Description: "the description of this header"},
|
||||
SimpleSchema: SimpleSchema{
|
||||
Items: &Items{
|
||||
Refable: Refable{Ref: MustCreateRef("Cat")},
|
||||
},
|
||||
Type: "string",
|
||||
Format: "date",
|
||||
Default: "8",
|
||||
},
|
||||
CommonValidations: CommonValidations{
|
||||
Maximum: float64Ptr(100),
|
||||
ExclusiveMaximum: true,
|
||||
ExclusiveMinimum: true,
|
||||
Minimum: float64Ptr(5),
|
||||
MaxLength: int64Ptr(100),
|
||||
MinLength: int64Ptr(5),
|
||||
Pattern: "\\w{1,5}\\w+",
|
||||
MaxItems: int64Ptr(100),
|
||||
MinItems: int64Ptr(5),
|
||||
UniqueItems: true,
|
||||
MultipleOf: float64Ptr(5),
|
||||
Enum: []interface{}{"hello", "world"},
|
||||
},
|
||||
}
|
||||
|
||||
var headerJSON = `{
|
||||
"items": {
|
||||
"$ref": "Cat"
|
||||
},
|
||||
"x-framework": "swagger-go",
|
||||
"description": "the description of this header",
|
||||
"maximum": 100,
|
||||
"minimum": 5,
|
||||
"exclusiveMaximum": true,
|
||||
"exclusiveMinimum": true,
|
||||
"maxLength": 100,
|
||||
"minLength": 5,
|
||||
"pattern": "\\w{1,5}\\w+",
|
||||
"maxItems": 100,
|
||||
"minItems": 5,
|
||||
"uniqueItems": true,
|
||||
"multipleOf": 5,
|
||||
"enum": ["hello", "world"],
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"default": "8"
|
||||
}`
|
||||
|
||||
func TestIntegrationHeader(t *testing.T) {
|
||||
var actual Header
|
||||
if assert.NoError(t, json.Unmarshal([]byte(headerJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, header)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, headerJSON, header)
|
||||
}
|
||||
65
vendor/github.com/go-openapi/spec/info_test.go
generated
vendored
Normal file
65
vendor/github.com/go-openapi/spec/info_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var infoJSON = `{
|
||||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
"title": "Swagger Sample API",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"contact": {
|
||||
"name": "wordnik api team",
|
||||
"url": "http://developer.wordnik.com"
|
||||
},
|
||||
"license": {
|
||||
"name": "Creative Commons 4.0 International",
|
||||
"url": "http://creativecommons.org/licenses/by/4.0/"
|
||||
},
|
||||
"version": "1.0.9-abcd",
|
||||
"x-framework": "go-swagger"
|
||||
}`
|
||||
|
||||
var info = Info{
|
||||
InfoProps: InfoProps{
|
||||
Version: "1.0.9-abcd",
|
||||
Title: "Swagger Sample API",
|
||||
Description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
TermsOfService: "http://helloreverb.com/terms/",
|
||||
Contact: &ContactInfo{Name: "wordnik api team", URL: "http://developer.wordnik.com"},
|
||||
License: &License{Name: "Creative Commons 4.0 International", URL: "http://creativecommons.org/licenses/by/4.0/"},
|
||||
},
|
||||
VendorExtensible: VendorExtensible{map[string]interface{}{"x-framework": "go-swagger"}},
|
||||
}
|
||||
|
||||
func TestIntegrationInfo_Serialize(t *testing.T) {
|
||||
b, err := json.MarshalIndent(info, "", "\t")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, infoJSON, string(b))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegrationInfo_Deserialize(t *testing.T) {
|
||||
actual := Info{}
|
||||
err := json.Unmarshal([]byte(infoJSON), &actual)
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, info, actual)
|
||||
}
|
||||
}
|
||||
33
vendor/github.com/go-openapi/spec/items.go
generated
vendored
33
vendor/github.com/go-openapi/spec/items.go
generated
vendored
|
|
@ -16,7 +16,9 @@ package spec
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/jsonpointer"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
|
|
@ -60,11 +62,12 @@ type CommonValidations struct {
|
|||
// Items a limited subset of JSON-Schema's items object.
|
||||
// It is used by parameter definitions that are not located in "body".
|
||||
//
|
||||
// For more information: http://goo.gl/8us55a#items-object-
|
||||
// For more information: http://goo.gl/8us55a#items-object
|
||||
type Items struct {
|
||||
Refable
|
||||
CommonValidations
|
||||
SimpleSchema
|
||||
VendorExtensible
|
||||
}
|
||||
|
||||
// NewItems creates a new instance of items
|
||||
|
|
@ -175,9 +178,14 @@ func (i *Items) UnmarshalJSON(data []byte) error {
|
|||
if err := json.Unmarshal(data, &simpleSchema); err != nil {
|
||||
return err
|
||||
}
|
||||
var vendorExtensible VendorExtensible
|
||||
if err := json.Unmarshal(data, &vendorExtensible); err != nil {
|
||||
return err
|
||||
}
|
||||
i.Refable = ref
|
||||
i.CommonValidations = validations
|
||||
i.SimpleSchema = simpleSchema
|
||||
i.VendorExtensible = vendorExtensible
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -195,5 +203,26 @@ func (i Items) MarshalJSON() ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return swag.ConcatJSON(b3, b1, b2), nil
|
||||
b4, err := json.Marshal(i.VendorExtensible)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return swag.ConcatJSON(b4, b3, b1, b2), nil
|
||||
}
|
||||
|
||||
// JSONLookup look up a value by the json property name
|
||||
func (p Items) JSONLookup(token string) (interface{}, error) {
|
||||
if token == "$ref" {
|
||||
return &p.Ref, nil
|
||||
}
|
||||
|
||||
r, _, err := jsonpointer.GetForToken(p.CommonValidations, token)
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
||||
return nil, err
|
||||
}
|
||||
if r != nil {
|
||||
return r, nil
|
||||
}
|
||||
r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token)
|
||||
return r, err
|
||||
}
|
||||
|
|
|
|||
81
vendor/github.com/go-openapi/spec/items_test.go
generated
vendored
Normal file
81
vendor/github.com/go-openapi/spec/items_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var items = Items{
|
||||
Refable: Refable{Ref: MustCreateRef("Dog")},
|
||||
CommonValidations: CommonValidations{
|
||||
Maximum: float64Ptr(100),
|
||||
ExclusiveMaximum: true,
|
||||
ExclusiveMinimum: true,
|
||||
Minimum: float64Ptr(5),
|
||||
MaxLength: int64Ptr(100),
|
||||
MinLength: int64Ptr(5),
|
||||
Pattern: "\\w{1,5}\\w+",
|
||||
MaxItems: int64Ptr(100),
|
||||
MinItems: int64Ptr(5),
|
||||
UniqueItems: true,
|
||||
MultipleOf: float64Ptr(5),
|
||||
Enum: []interface{}{"hello", "world"},
|
||||
},
|
||||
SimpleSchema: SimpleSchema{
|
||||
Type: "string",
|
||||
Format: "date",
|
||||
Items: &Items{
|
||||
Refable: Refable{Ref: MustCreateRef("Cat")},
|
||||
},
|
||||
CollectionFormat: "csv",
|
||||
Default: "8",
|
||||
},
|
||||
}
|
||||
|
||||
var itemsJSON = `{
|
||||
"items": {
|
||||
"$ref": "Cat"
|
||||
},
|
||||
"$ref": "Dog",
|
||||
"maximum": 100,
|
||||
"minimum": 5,
|
||||
"exclusiveMaximum": true,
|
||||
"exclusiveMinimum": true,
|
||||
"maxLength": 100,
|
||||
"minLength": 5,
|
||||
"pattern": "\\w{1,5}\\w+",
|
||||
"maxItems": 100,
|
||||
"minItems": 5,
|
||||
"uniqueItems": true,
|
||||
"multipleOf": 5,
|
||||
"enum": ["hello", "world"],
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"collectionFormat": "csv",
|
||||
"default": "8"
|
||||
}`
|
||||
|
||||
func TestIntegrationItems(t *testing.T) {
|
||||
var actual Items
|
||||
if assert.NoError(t, json.Unmarshal([]byte(itemsJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, items)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, itemsJSON, items)
|
||||
}
|
||||
28
vendor/github.com/go-openapi/spec/license_test.go
generated
vendored
Normal file
28
vendor/github.com/go-openapi/spec/license_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIntegrationLicense(t *testing.T) {
|
||||
license := License{"the name", "the url"}
|
||||
const licenseJSON = `{"name":"the name","url":"the url"}`
|
||||
const licenseYAML = "name: the name\nurl: the url\n"
|
||||
|
||||
assertSerializeJSON(t, license, licenseJSON)
|
||||
assertSerializeYAML(t, license, licenseYAML)
|
||||
assertParsesJSON(t, licenseJSON, license)
|
||||
assertParsesYAML(t, licenseYAML, license)
|
||||
}
|
||||
85
vendor/github.com/go-openapi/spec/operation_test.go
generated
vendored
Normal file
85
vendor/github.com/go-openapi/spec/operation_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var operation = Operation{
|
||||
VendorExtensible: VendorExtensible{
|
||||
Extensions: map[string]interface{}{
|
||||
"x-framework": "go-swagger",
|
||||
},
|
||||
},
|
||||
OperationProps: OperationProps{
|
||||
Description: "operation description",
|
||||
Consumes: []string{"application/json", "application/x-yaml"},
|
||||
Produces: []string{"application/json", "application/x-yaml"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Tags: []string{"dogs"},
|
||||
Summary: "the summary of the operation",
|
||||
ID: "sendCat",
|
||||
Deprecated: true,
|
||||
Security: []map[string][]string{
|
||||
map[string][]string{
|
||||
"apiKey": []string{},
|
||||
},
|
||||
},
|
||||
Parameters: []Parameter{
|
||||
Parameter{Refable: Refable{Ref: MustCreateRef("Cat")}},
|
||||
},
|
||||
Responses: &Responses{
|
||||
ResponsesProps: ResponsesProps{
|
||||
Default: &Response{
|
||||
ResponseProps: ResponseProps{
|
||||
Description: "void response",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var operationJSON = `{
|
||||
"description": "operation description",
|
||||
"x-framework": "go-swagger",
|
||||
"consumes": [ "application/json", "application/x-yaml" ],
|
||||
"produces": [ "application/json", "application/x-yaml" ],
|
||||
"schemes": ["http", "https"],
|
||||
"tags": ["dogs"],
|
||||
"summary": "the summary of the operation",
|
||||
"operationId": "sendCat",
|
||||
"deprecated": true,
|
||||
"security": [ { "apiKey": [] } ],
|
||||
"parameters": [{"$ref":"Cat"}],
|
||||
"responses": {
|
||||
"default": {
|
||||
"description": "void response"
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
func TestIntegrationOperation(t *testing.T) {
|
||||
var actual Operation
|
||||
if assert.NoError(t, json.Unmarshal([]byte(operationJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, operation)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, operationJSON, operation)
|
||||
}
|
||||
6
vendor/github.com/go-openapi/spec/parameter.go
generated
vendored
6
vendor/github.com/go-openapi/spec/parameter.go
generated
vendored
|
|
@ -16,6 +16,7 @@ package spec
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/jsonpointer"
|
||||
"github.com/go-openapi/swag"
|
||||
|
|
@ -100,15 +101,16 @@ func (p Parameter) JSONLookup(token string) (interface{}, error) {
|
|||
if token == "$ref" {
|
||||
return &p.Ref, nil
|
||||
}
|
||||
|
||||
r, _, err := jsonpointer.GetForToken(p.CommonValidations, token)
|
||||
if err != nil {
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
||||
return nil, err
|
||||
}
|
||||
if r != nil {
|
||||
return r, nil
|
||||
}
|
||||
r, _, err = jsonpointer.GetForToken(p.SimpleSchema, token)
|
||||
if err != nil {
|
||||
if err != nil && !strings.HasPrefix(err.Error(), "object has no field") {
|
||||
return nil, err
|
||||
}
|
||||
if r != nil {
|
||||
|
|
|
|||
156
vendor/github.com/go-openapi/spec/parameters_test.go
generated
vendored
Normal file
156
vendor/github.com/go-openapi/spec/parameters_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var parameter = Parameter{
|
||||
VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{
|
||||
"x-framework": "swagger-go",
|
||||
}},
|
||||
Refable: Refable{Ref: MustCreateRef("Dog")},
|
||||
CommonValidations: CommonValidations{
|
||||
Maximum: float64Ptr(100),
|
||||
ExclusiveMaximum: true,
|
||||
ExclusiveMinimum: true,
|
||||
Minimum: float64Ptr(5),
|
||||
MaxLength: int64Ptr(100),
|
||||
MinLength: int64Ptr(5),
|
||||
Pattern: "\\w{1,5}\\w+",
|
||||
MaxItems: int64Ptr(100),
|
||||
MinItems: int64Ptr(5),
|
||||
UniqueItems: true,
|
||||
MultipleOf: float64Ptr(5),
|
||||
Enum: []interface{}{"hello", "world"},
|
||||
},
|
||||
SimpleSchema: SimpleSchema{
|
||||
Type: "string",
|
||||
Format: "date",
|
||||
CollectionFormat: "csv",
|
||||
Items: &Items{
|
||||
Refable: Refable{Ref: MustCreateRef("Cat")},
|
||||
},
|
||||
Default: "8",
|
||||
},
|
||||
ParamProps: ParamProps{
|
||||
Name: "param-name",
|
||||
In: "header",
|
||||
Required: true,
|
||||
Schema: &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
Description: "the description of this parameter",
|
||||
},
|
||||
}
|
||||
|
||||
var parameterJSON = `{
|
||||
"items": {
|
||||
"$ref": "Cat"
|
||||
},
|
||||
"x-framework": "swagger-go",
|
||||
"$ref": "Dog",
|
||||
"description": "the description of this parameter",
|
||||
"maximum": 100,
|
||||
"minimum": 5,
|
||||
"exclusiveMaximum": true,
|
||||
"exclusiveMinimum": true,
|
||||
"maxLength": 100,
|
||||
"minLength": 5,
|
||||
"pattern": "\\w{1,5}\\w+",
|
||||
"maxItems": 100,
|
||||
"minItems": 5,
|
||||
"uniqueItems": true,
|
||||
"multipleOf": 5,
|
||||
"enum": ["hello", "world"],
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"name": "param-name",
|
||||
"in": "header",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "csv",
|
||||
"default": "8"
|
||||
}`
|
||||
|
||||
func TestIntegrationParameter(t *testing.T) {
|
||||
var actual Parameter
|
||||
if assert.NoError(t, json.Unmarshal([]byte(parameterJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, parameter)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, parameterJSON, parameter)
|
||||
}
|
||||
|
||||
func TestParameterSerialization(t *testing.T) {
|
||||
items := &Items{
|
||||
SimpleSchema: SimpleSchema{Type: "string"},
|
||||
}
|
||||
|
||||
intItems := &Items{
|
||||
SimpleSchema: SimpleSchema{Type: "int", Format: "int32"},
|
||||
}
|
||||
|
||||
assertSerializeJSON(t, QueryParam("").Typed("string", ""), `{"type":"string","in":"query"}`)
|
||||
|
||||
assertSerializeJSON(t,
|
||||
QueryParam("").CollectionOf(items, "multi"),
|
||||
`{"type":"array","items":{"type":"string"},"collectionFormat":"multi","in":"query"}`)
|
||||
|
||||
assertSerializeJSON(t, PathParam("").Typed("string", ""), `{"type":"string","in":"path","required":true}`)
|
||||
|
||||
assertSerializeJSON(t,
|
||||
PathParam("").CollectionOf(items, "multi"),
|
||||
`{"type":"array","items":{"type":"string"},"collectionFormat":"multi","in":"path","required":true}`)
|
||||
|
||||
assertSerializeJSON(t,
|
||||
PathParam("").CollectionOf(intItems, "multi"),
|
||||
`{"type":"array","items":{"type":"int","format":"int32"},"collectionFormat":"multi","in":"path","required":true}`)
|
||||
|
||||
assertSerializeJSON(t, HeaderParam("").Typed("string", ""), `{"type":"string","in":"header","required":true}`)
|
||||
|
||||
assertSerializeJSON(t,
|
||||
HeaderParam("").CollectionOf(items, "multi"),
|
||||
`{"type":"array","items":{"type":"string"},"collectionFormat":"multi","in":"header","required":true}`)
|
||||
schema := &Schema{SchemaProps: SchemaProps{
|
||||
Properties: map[string]Schema{
|
||||
"name": Schema{SchemaProps: SchemaProps{
|
||||
Type: []string{"string"},
|
||||
}},
|
||||
},
|
||||
}}
|
||||
|
||||
refSchema := &Schema{
|
||||
SchemaProps: SchemaProps{Ref: MustCreateRef("Cat")},
|
||||
}
|
||||
|
||||
assertSerializeJSON(t,
|
||||
BodyParam("", schema),
|
||||
`{"type":"object","in":"body","schema":{"properties":{"name":{"type":"string"}}}}`)
|
||||
|
||||
assertSerializeJSON(t,
|
||||
BodyParam("", refSchema),
|
||||
`{"type":"object","in":"body","schema":{"$ref":"Cat"}}`)
|
||||
|
||||
// array body param
|
||||
assertSerializeJSON(t,
|
||||
BodyParam("", ArrayProperty(RefProperty("Cat"))),
|
||||
`{"type":"object","in":"body","schema":{"type":"array","items":{"$ref":"Cat"}}}`)
|
||||
|
||||
}
|
||||
81
vendor/github.com/go-openapi/spec/path_item_test.go
generated
vendored
Normal file
81
vendor/github.com/go-openapi/spec/path_item_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var pathItem = PathItem{
|
||||
Refable: Refable{Ref: MustCreateRef("Dog")},
|
||||
VendorExtensible: VendorExtensible{
|
||||
Extensions: map[string]interface{}{
|
||||
"x-framework": "go-swagger",
|
||||
},
|
||||
},
|
||||
PathItemProps: PathItemProps{
|
||||
Get: &Operation{
|
||||
OperationProps: OperationProps{Description: "get operation description"},
|
||||
},
|
||||
Put: &Operation{
|
||||
OperationProps: OperationProps{Description: "put operation description"},
|
||||
},
|
||||
Post: &Operation{
|
||||
OperationProps: OperationProps{Description: "post operation description"},
|
||||
},
|
||||
Delete: &Operation{
|
||||
OperationProps: OperationProps{Description: "delete operation description"},
|
||||
},
|
||||
Options: &Operation{
|
||||
OperationProps: OperationProps{Description: "options operation description"},
|
||||
},
|
||||
Head: &Operation{
|
||||
OperationProps: OperationProps{Description: "head operation description"},
|
||||
},
|
||||
Patch: &Operation{
|
||||
OperationProps: OperationProps{Description: "patch operation description"},
|
||||
},
|
||||
Parameters: []Parameter{
|
||||
Parameter{
|
||||
ParamProps: ParamProps{In: "path"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var pathItemJSON = `{
|
||||
"$ref": "Dog",
|
||||
"x-framework": "go-swagger",
|
||||
"get": { "description": "get operation description" },
|
||||
"put": { "description": "put operation description" },
|
||||
"post": { "description": "post operation description" },
|
||||
"delete": { "description": "delete operation description" },
|
||||
"options": { "description": "options operation description" },
|
||||
"head": { "description": "head operation description" },
|
||||
"patch": { "description": "patch operation description" },
|
||||
"parameters": [{"in":"path"}]
|
||||
}`
|
||||
|
||||
func TestIntegrationPathItem(t *testing.T) {
|
||||
var actual PathItem
|
||||
if assert.NoError(t, json.Unmarshal([]byte(pathItemJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, pathItem)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, pathItemJSON, pathItem)
|
||||
}
|
||||
43
vendor/github.com/go-openapi/spec/paths_test.go
generated
vendored
Normal file
43
vendor/github.com/go-openapi/spec/paths_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var paths = Paths{
|
||||
VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-framework": "go-swagger"}},
|
||||
Paths: map[string]PathItem{
|
||||
"/": PathItem{
|
||||
Refable: Refable{Ref: MustCreateRef("cats")},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var pathsJSON = `{"x-framework":"go-swagger","/":{"$ref":"cats"}}`
|
||||
|
||||
func TestIntegrationPaths(t *testing.T) {
|
||||
var actual Paths
|
||||
if assert.NoError(t, json.Unmarshal([]byte(pathsJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, paths)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, pathsJSON, paths)
|
||||
|
||||
}
|
||||
58
vendor/github.com/go-openapi/spec/properties_test.go
generated
vendored
Normal file
58
vendor/github.com/go-openapi/spec/properties_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPropertySerialization(t *testing.T) {
|
||||
strProp := StringProperty()
|
||||
strProp.Enum = append(strProp.Enum, "a", "b")
|
||||
|
||||
prop := &Schema{SchemaProps: SchemaProps{
|
||||
Items: &SchemaOrArray{Schemas: []Schema{
|
||||
Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
}},
|
||||
}}
|
||||
|
||||
var propSerData = []struct {
|
||||
Schema *Schema
|
||||
JSON string
|
||||
}{
|
||||
{BooleanProperty(), `{"type":"boolean"}`},
|
||||
{DateProperty(), `{"type":"string","format":"date"}`},
|
||||
{DateTimeProperty(), `{"type":"string","format":"date-time"}`},
|
||||
{Float64Property(), `{"type":"number","format":"double"}`},
|
||||
{Float32Property(), `{"type":"number","format":"float"}`},
|
||||
{Int32Property(), `{"type":"integer","format":"int32"}`},
|
||||
{Int64Property(), `{"type":"integer","format":"int64"}`},
|
||||
{MapProperty(StringProperty()), `{"type":"object","additionalProperties":{"type":"string"}}`},
|
||||
{MapProperty(Int32Property()), `{"type":"object","additionalProperties":{"type":"integer","format":"int32"}}`},
|
||||
{RefProperty("Dog"), `{"$ref":"Dog"}`},
|
||||
{StringProperty(), `{"type":"string"}`},
|
||||
{strProp, `{"type":"string","enum":["a","b"]}`},
|
||||
{ArrayProperty(StringProperty()), `{"type":"array","items":{"type":"string"}}`},
|
||||
{prop, `{"items":[{"type":"string"},{"type":"string"}]}`},
|
||||
}
|
||||
|
||||
for _, v := range propSerData {
|
||||
t.Log("roundtripping for", v.JSON)
|
||||
assertSerializeJSON(t, v.Schema, v.JSON)
|
||||
assertParsesJSON(t, v.JSON, v.Schema)
|
||||
}
|
||||
|
||||
}
|
||||
23
vendor/github.com/go-openapi/spec/ref.go
generated
vendored
23
vendor/github.com/go-openapi/spec/ref.go
generated
vendored
|
|
@ -55,7 +55,7 @@ func (r *Ref) RemoteURI() string {
|
|||
}
|
||||
|
||||
// IsValidURI returns true when the url the ref points to can be found
|
||||
func (r *Ref) IsValidURI() bool {
|
||||
func (r *Ref) IsValidURI(basepaths ...string) bool {
|
||||
if r.String() == "" {
|
||||
return true
|
||||
}
|
||||
|
|
@ -81,14 +81,18 @@ func (r *Ref) IsValidURI() bool {
|
|||
// check for local file
|
||||
pth := v
|
||||
if r.HasURLPathOnly {
|
||||
p, e := filepath.Abs(pth)
|
||||
base := "."
|
||||
if len(basepaths) > 0 {
|
||||
base = filepath.Dir(filepath.Join(basepaths...))
|
||||
}
|
||||
p, e := filepath.Abs(filepath.ToSlash(filepath.Join(base, pth)))
|
||||
if e != nil {
|
||||
return false
|
||||
}
|
||||
pth = p
|
||||
}
|
||||
|
||||
fi, err := os.Stat(pth)
|
||||
fi, err := os.Stat(filepath.ToSlash(pth))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -116,25 +120,18 @@ func NewRef(refURI string) (Ref, error) {
|
|||
return Ref{Ref: ref}, nil
|
||||
}
|
||||
|
||||
// MustCreateRef creates a ref object but
|
||||
// MustCreateRef creates a ref object but panics when refURI is invalid.
|
||||
// Use the NewRef method for a version that returns an error.
|
||||
func MustCreateRef(refURI string) Ref {
|
||||
return Ref{Ref: jsonreference.MustCreateRef(refURI)}
|
||||
}
|
||||
|
||||
// // NewResolvedRef creates a resolved ref
|
||||
// func NewResolvedRef(refURI string, data interface{}) Ref {
|
||||
// return Ref{
|
||||
// Ref: jsonreference.MustCreateRef(refURI),
|
||||
// Resolved: data,
|
||||
// }
|
||||
// }
|
||||
|
||||
// MarshalJSON marshals this ref into a JSON object
|
||||
func (r Ref) MarshalJSON() ([]byte, error) {
|
||||
str := r.String()
|
||||
if str == "" {
|
||||
if r.IsRoot() {
|
||||
return []byte(`{"$ref":"#"}`), nil
|
||||
return []byte(`{"$ref":""}`), nil
|
||||
}
|
||||
return []byte("{}"), nil
|
||||
}
|
||||
|
|
|
|||
23
vendor/github.com/go-openapi/spec/response.go
generated
vendored
23
vendor/github.com/go-openapi/spec/response.go
generated
vendored
|
|
@ -17,6 +17,7 @@ package spec
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/go-openapi/jsonpointer"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
|
|
@ -34,6 +35,19 @@ type ResponseProps struct {
|
|||
type Response struct {
|
||||
Refable
|
||||
ResponseProps
|
||||
VendorExtensible
|
||||
}
|
||||
|
||||
// JSONLookup look up a value by the json property name
|
||||
func (p Response) JSONLookup(token string) (interface{}, error) {
|
||||
if ex, ok := p.Extensions[token]; ok {
|
||||
return &ex, nil
|
||||
}
|
||||
if token == "$ref" {
|
||||
return &p.Ref, nil
|
||||
}
|
||||
r, _, err := jsonpointer.GetForToken(p.ResponseProps, token)
|
||||
return r, err
|
||||
}
|
||||
|
||||
// UnmarshalJSON hydrates this items instance with the data from JSON
|
||||
|
|
@ -44,6 +58,9 @@ func (r *Response) UnmarshalJSON(data []byte) error {
|
|||
if err := json.Unmarshal(data, &r.Refable); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(data, &r.VendorExtensible); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +74,11 @@ func (r Response) MarshalJSON() ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return swag.ConcatJSON(b1, b2), nil
|
||||
b3, err := json.Marshal(r.VendorExtensible)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return swag.ConcatJSON(b1, b2, b3), nil
|
||||
}
|
||||
|
||||
// NewResponse creates a new response instance
|
||||
|
|
|
|||
53
vendor/github.com/go-openapi/spec/response_test.go
generated
vendored
Normal file
53
vendor/github.com/go-openapi/spec/response_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2017 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var response = Response{
|
||||
Refable: Refable{Ref: MustCreateRef("Dog")},
|
||||
VendorExtensible: VendorExtensible{
|
||||
Extensions: map[string]interface{}{
|
||||
"x-go-name": "PutDogExists",
|
||||
},
|
||||
},
|
||||
ResponseProps: ResponseProps{
|
||||
Description: "Dog exists",
|
||||
Schema: &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
},
|
||||
}
|
||||
|
||||
var responseJSON = `{
|
||||
"$ref": "Dog",
|
||||
"x-go-name": "PutDogExists",
|
||||
"description": "Dog exists",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}`
|
||||
|
||||
func TestIntegrationResponse(t *testing.T) {
|
||||
var actual Response
|
||||
if assert.NoError(t, json.Unmarshal([]byte(responseJSON), &actual)) {
|
||||
assert.EqualValues(t, actual, response)
|
||||
}
|
||||
|
||||
assertParsesJSON(t, responseJSON, response)
|
||||
}
|
||||
2
vendor/github.com/go-openapi/spec/responses.go
generated
vendored
2
vendor/github.com/go-openapi/spec/responses.go
generated
vendored
|
|
@ -51,7 +51,7 @@ func (r Responses) JSONLookup(token string) (interface{}, error) {
|
|||
}
|
||||
if i, err := strconv.Atoi(token); err == nil {
|
||||
if scr, ok := r.StatusCodeResponses[i]; ok {
|
||||
return &scr, nil
|
||||
return scr, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("object has no field %q", token)
|
||||
|
|
|
|||
6
vendor/github.com/go-openapi/spec/schema.go
generated
vendored
6
vendor/github.com/go-openapi/spec/schema.go
generated
vendored
|
|
@ -201,8 +201,8 @@ func (r *SchemaURL) UnmarshalJSON(data []byte) error {
|
|||
|
||||
type SchemaProps struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Ref Ref `json:"-,omitempty"`
|
||||
Schema SchemaURL `json:"-,omitempty"`
|
||||
Ref Ref `json:"-"`
|
||||
Schema SchemaURL `json:"-"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Type StringOrArray `json:"type,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
|
|
@ -269,7 +269,7 @@ func (s Schema) JSONLookup(token string) (interface{}, error) {
|
|||
}
|
||||
|
||||
r, _, err := jsonpointer.GetForToken(s.SchemaProps, token)
|
||||
if r != nil || err != nil {
|
||||
if r != nil || (err != nil && !strings.HasPrefix(err.Error(), "object has no field")) {
|
||||
return r, err
|
||||
}
|
||||
r, _, err = jsonpointer.GetForToken(s.SwaggerSchemaProps, token)
|
||||
|
|
|
|||
205
vendor/github.com/go-openapi/spec/schema_test.go
generated
vendored
Normal file
205
vendor/github.com/go-openapi/spec/schema_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var schema = Schema{
|
||||
VendorExtensible: VendorExtensible{Extensions: map[string]interface{}{"x-framework": "go-swagger"}},
|
||||
SchemaProps: SchemaProps{
|
||||
Ref: MustCreateRef("Cat"),
|
||||
Type: []string{"string"},
|
||||
Format: "date",
|
||||
Description: "the description of this schema",
|
||||
Title: "the title",
|
||||
Default: "blah",
|
||||
Maximum: float64Ptr(100),
|
||||
ExclusiveMaximum: true,
|
||||
ExclusiveMinimum: true,
|
||||
Minimum: float64Ptr(5),
|
||||
MaxLength: int64Ptr(100),
|
||||
MinLength: int64Ptr(5),
|
||||
Pattern: "\\w{1,5}\\w+",
|
||||
MaxItems: int64Ptr(100),
|
||||
MinItems: int64Ptr(5),
|
||||
UniqueItems: true,
|
||||
MultipleOf: float64Ptr(5),
|
||||
Enum: []interface{}{"hello", "world"},
|
||||
MaxProperties: int64Ptr(5),
|
||||
MinProperties: int64Ptr(1),
|
||||
Required: []string{"id", "name"},
|
||||
Items: &SchemaOrArray{Schema: &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}},
|
||||
AllOf: []Schema{Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}},
|
||||
Properties: map[string]Schema{
|
||||
"id": Schema{SchemaProps: SchemaProps{Type: []string{"integer"}, Format: "int64"}},
|
||||
"name": Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
},
|
||||
AdditionalProperties: &SchemaOrBool{Allows: true, Schema: &Schema{SchemaProps: SchemaProps{
|
||||
Type: []string{"integer"},
|
||||
Format: "int32",
|
||||
}}},
|
||||
},
|
||||
SwaggerSchemaProps: SwaggerSchemaProps{
|
||||
Discriminator: "not this",
|
||||
ReadOnly: true,
|
||||
XML: &XMLObject{"sch", "io", "sw", true, true},
|
||||
ExternalDocs: &ExternalDocumentation{
|
||||
Description: "the documentation etc",
|
||||
URL: "http://readthedocs.org/swagger",
|
||||
},
|
||||
Example: []interface{}{
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"name": "a book",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"id": 2,
|
||||
"name": "the thing",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var schemaJSON = `{
|
||||
"x-framework": "go-swagger",
|
||||
"$ref": "Cat",
|
||||
"description": "the description of this schema",
|
||||
"maximum": 100,
|
||||
"minimum": 5,
|
||||
"exclusiveMaximum": true,
|
||||
"exclusiveMinimum": true,
|
||||
"maxLength": 100,
|
||||
"minLength": 5,
|
||||
"pattern": "\\w{1,5}\\w+",
|
||||
"maxItems": 100,
|
||||
"minItems": 5,
|
||||
"uniqueItems": true,
|
||||
"multipleOf": 5,
|
||||
"enum": ["hello", "world"],
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"title": "the title",
|
||||
"default": "blah",
|
||||
"maxProperties": 5,
|
||||
"minProperties": 1,
|
||||
"required": ["id", "name"],
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"allOf": [
|
||||
{
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"discriminator": "not this",
|
||||
"readOnly": true,
|
||||
"xml": {
|
||||
"name": "sch",
|
||||
"namespace": "io",
|
||||
"prefix": "sw",
|
||||
"wrapped": true,
|
||||
"attribute": true
|
||||
},
|
||||
"externalDocs": {
|
||||
"description": "the documentation etc",
|
||||
"url": "http://readthedocs.org/swagger"
|
||||
},
|
||||
"example": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "a book"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "the thing"
|
||||
}
|
||||
],
|
||||
"additionalProperties": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
func TestSchema(t *testing.T) {
|
||||
|
||||
expected := map[string]interface{}{}
|
||||
json.Unmarshal([]byte(schemaJSON), &expected)
|
||||
b, err := json.Marshal(schema)
|
||||
if assert.NoError(t, err) {
|
||||
var actual map[string]interface{}
|
||||
json.Unmarshal(b, &actual)
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
actual2 := Schema{}
|
||||
if assert.NoError(t, json.Unmarshal([]byte(schemaJSON), &actual2)) {
|
||||
assert.Equal(t, schema.Ref, actual2.Ref)
|
||||
assert.Equal(t, schema.Description, actual2.Description)
|
||||
assert.Equal(t, schema.Maximum, actual2.Maximum)
|
||||
assert.Equal(t, schema.Minimum, actual2.Minimum)
|
||||
assert.Equal(t, schema.ExclusiveMinimum, actual2.ExclusiveMinimum)
|
||||
assert.Equal(t, schema.ExclusiveMaximum, actual2.ExclusiveMaximum)
|
||||
assert.Equal(t, schema.MaxLength, actual2.MaxLength)
|
||||
assert.Equal(t, schema.MinLength, actual2.MinLength)
|
||||
assert.Equal(t, schema.Pattern, actual2.Pattern)
|
||||
assert.Equal(t, schema.MaxItems, actual2.MaxItems)
|
||||
assert.Equal(t, schema.MinItems, actual2.MinItems)
|
||||
assert.True(t, actual2.UniqueItems)
|
||||
assert.Equal(t, schema.MultipleOf, actual2.MultipleOf)
|
||||
assert.Equal(t, schema.Enum, actual2.Enum)
|
||||
assert.Equal(t, schema.Type, actual2.Type)
|
||||
assert.Equal(t, schema.Format, actual2.Format)
|
||||
assert.Equal(t, schema.Title, actual2.Title)
|
||||
assert.Equal(t, schema.MaxProperties, actual2.MaxProperties)
|
||||
assert.Equal(t, schema.MinProperties, actual2.MinProperties)
|
||||
assert.Equal(t, schema.Required, actual2.Required)
|
||||
assert.Equal(t, schema.Items, actual2.Items)
|
||||
assert.Equal(t, schema.AllOf, actual2.AllOf)
|
||||
assert.Equal(t, schema.Properties, actual2.Properties)
|
||||
assert.Equal(t, schema.Discriminator, actual2.Discriminator)
|
||||
assert.Equal(t, schema.ReadOnly, actual2.ReadOnly)
|
||||
assert.Equal(t, schema.XML, actual2.XML)
|
||||
assert.Equal(t, schema.ExternalDocs, actual2.ExternalDocs)
|
||||
assert.Equal(t, schema.AdditionalProperties, actual2.AdditionalProperties)
|
||||
assert.Equal(t, schema.Extensions, actual2.Extensions)
|
||||
examples := actual2.Example.([]interface{})
|
||||
expEx := schema.Example.([]interface{})
|
||||
ex1 := examples[0].(map[string]interface{})
|
||||
ex2 := examples[1].(map[string]interface{})
|
||||
exp1 := expEx[0].(map[string]interface{})
|
||||
exp2 := expEx[1].(map[string]interface{})
|
||||
|
||||
assert.EqualValues(t, exp1["id"], ex1["id"])
|
||||
assert.Equal(t, exp1["name"], ex1["name"])
|
||||
assert.EqualValues(t, exp2["id"], ex2["id"])
|
||||
assert.Equal(t, exp2["name"], ex2["name"])
|
||||
}
|
||||
|
||||
}
|
||||
150
vendor/github.com/go-openapi/spec/schemas/jsonschema-draft-04.json
generated
vendored
Normal file
150
vendor/github.com/go-openapi/spec/schemas/jsonschema-draft-04.json
generated
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
{
|
||||
"id": "http://json-schema.org/draft-04/schema#",
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Core schema meta-schema",
|
||||
"definitions": {
|
||||
"schemaArray": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "$ref": "#" }
|
||||
},
|
||||
"positiveInteger": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"positiveIntegerDefault0": {
|
||||
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
|
||||
},
|
||||
"simpleTypes": {
|
||||
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
|
||||
},
|
||||
"stringArray": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"$schema": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"title": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"default": {},
|
||||
"multipleOf": {
|
||||
"type": "number",
|
||||
"minimum": 0,
|
||||
"exclusiveMinimum": true
|
||||
},
|
||||
"maximum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMaximum": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"minimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"exclusiveMinimum": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"maxLength": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"pattern": {
|
||||
"type": "string",
|
||||
"format": "regex"
|
||||
},
|
||||
"additionalItems": {
|
||||
"anyOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "$ref": "#" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/schemaArray" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"maxItems": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"uniqueItems": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
|
||||
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
|
||||
"required": { "$ref": "#/definitions/stringArray" },
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "type": "boolean" },
|
||||
{ "$ref": "#" }
|
||||
],
|
||||
"default": {}
|
||||
},
|
||||
"definitions": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"properties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"patternProperties": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#" },
|
||||
"default": {}
|
||||
},
|
||||
"dependencies": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#" },
|
||||
{ "$ref": "#/definitions/stringArray" }
|
||||
]
|
||||
}
|
||||
},
|
||||
"enum": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
},
|
||||
"type": {
|
||||
"anyOf": [
|
||||
{ "$ref": "#/definitions/simpleTypes" },
|
||||
{
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/definitions/simpleTypes" },
|
||||
"minItems": 1,
|
||||
"uniqueItems": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"allOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"anyOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"oneOf": { "$ref": "#/definitions/schemaArray" },
|
||||
"not": { "$ref": "#" }
|
||||
},
|
||||
"dependencies": {
|
||||
"exclusiveMaximum": [ "maximum" ],
|
||||
"exclusiveMinimum": [ "minimum" ]
|
||||
},
|
||||
"default": {}
|
||||
}
|
||||
5
vendor/github.com/go-openapi/spec/schemas/v2/README.md
generated
vendored
Normal file
5
vendor/github.com/go-openapi/spec/schemas/v2/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Swagger 2.0 specification schema
|
||||
|
||||
This folder contains the Swagger 2.0 specification schema files maintained here:
|
||||
|
||||
https://github.com/reverb/swagger-spec/blob/master/schemas/v2.0
|
||||
1607
vendor/github.com/go-openapi/spec/schemas/v2/schema.json
generated
vendored
Normal file
1607
vendor/github.com/go-openapi/spec/schemas/v2/schema.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
11
vendor/github.com/go-openapi/spec/spec.go
generated
vendored
11
vendor/github.com/go-openapi/spec/spec.go
generated
vendored
|
|
@ -16,6 +16,8 @@ package spec
|
|||
|
||||
import "encoding/json"
|
||||
|
||||
//go:generate curl -L --progress -o ./schemas/v2/schema.json http://swagger.io/v2/schema.json
|
||||
//go:generate curl -L --progress -o ./schemas/jsonschema-draft-04.json http://json-schema.org/draft-04/schema
|
||||
//go:generate go-bindata -pkg=spec -prefix=./schemas -ignore=.*\.md ./schemas/...
|
||||
//go:generate perl -pi -e s,Json,JSON,g bindata.go
|
||||
|
||||
|
|
@ -27,10 +29,15 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
jsonSchema = MustLoadJSONSchemaDraft04()
|
||||
swaggerSchema = MustLoadSwagger20Schema()
|
||||
jsonSchema *Schema
|
||||
swaggerSchema *Schema
|
||||
)
|
||||
|
||||
func init() {
|
||||
jsonSchema = MustLoadJSONSchemaDraft04()
|
||||
swaggerSchema = MustLoadSwagger20Schema()
|
||||
}
|
||||
|
||||
// MustLoadJSONSchemaDraft04 panics when Swagger20Schema returns an error
|
||||
func MustLoadJSONSchemaDraft04() *Schema {
|
||||
d, e := JSONSchemaDraft04()
|
||||
|
|
|
|||
110
vendor/github.com/go-openapi/spec/structs_test.go
generated
vendored
Normal file
110
vendor/github.com/go-openapi/spec/structs_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func assertSerializeJSON(t testing.TB, actual interface{}, expected string) bool {
|
||||
ser, err := json.Marshal(actual)
|
||||
if err != nil {
|
||||
return assert.Fail(t, "unable to marshal to json (%s): %#v", err, actual)
|
||||
}
|
||||
return assert.Equal(t, string(ser), expected)
|
||||
}
|
||||
|
||||
func assertParsesJSON(t testing.TB, actual string, expected interface{}) bool {
|
||||
tpe := reflect.TypeOf(expected)
|
||||
var pointed bool
|
||||
if tpe.Kind() == reflect.Ptr {
|
||||
tpe = tpe.Elem()
|
||||
pointed = true
|
||||
}
|
||||
|
||||
parsed := reflect.New(tpe)
|
||||
err := json.Unmarshal([]byte(actual), parsed.Interface())
|
||||
if err != nil {
|
||||
return assert.Fail(t, "unable to unmarshal from json (%s): %s", err, actual)
|
||||
}
|
||||
act := parsed.Interface()
|
||||
if !pointed {
|
||||
act = reflect.Indirect(parsed).Interface()
|
||||
}
|
||||
return assert.Equal(t, act, expected)
|
||||
}
|
||||
|
||||
func assertSerializeYAML(t testing.TB, actual interface{}, expected string) bool {
|
||||
ser, err := yaml.Marshal(actual)
|
||||
if err != nil {
|
||||
return assert.Fail(t, "unable to marshal to yaml (%s): %#v", err, actual)
|
||||
}
|
||||
return assert.Equal(t, string(ser), expected)
|
||||
}
|
||||
|
||||
func assertParsesYAML(t testing.TB, actual string, expected interface{}) bool {
|
||||
tpe := reflect.TypeOf(expected)
|
||||
var pointed bool
|
||||
if tpe.Kind() == reflect.Ptr {
|
||||
tpe = tpe.Elem()
|
||||
pointed = true
|
||||
}
|
||||
parsed := reflect.New(tpe)
|
||||
err := yaml.Unmarshal([]byte(actual), parsed.Interface())
|
||||
if err != nil {
|
||||
return assert.Fail(t, "unable to unmarshal from yaml (%s): %s", err, actual)
|
||||
}
|
||||
act := parsed.Interface()
|
||||
if !pointed {
|
||||
act = reflect.Indirect(parsed).Interface()
|
||||
}
|
||||
return assert.EqualValues(t, act, expected)
|
||||
}
|
||||
|
||||
func TestSerialization_SerializeJSON(t *testing.T) {
|
||||
assertSerializeJSON(t, []string{"hello"}, "[\"hello\"]")
|
||||
assertSerializeJSON(t, []string{"hello", "world", "and", "stuff"}, "[\"hello\",\"world\",\"and\",\"stuff\"]")
|
||||
assertSerializeJSON(t, StringOrArray(nil), "null")
|
||||
assertSerializeJSON(t, SchemaOrArray{Schemas: []Schema{Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}}}, "[{\"type\":\"string\"}]")
|
||||
assertSerializeJSON(t, SchemaOrArray{
|
||||
Schemas: []Schema{
|
||||
Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
}}, "[{\"type\":\"string\"},{\"type\":\"string\"}]")
|
||||
assertSerializeJSON(t, SchemaOrArray{}, "null")
|
||||
}
|
||||
|
||||
func TestSerialization_DeserializeJSON(t *testing.T) {
|
||||
// String
|
||||
assertParsesJSON(t, "\"hello\"", StringOrArray([]string{"hello"}))
|
||||
assertParsesJSON(t, "[\"hello\",\"world\",\"and\",\"stuff\"]", StringOrArray([]string{"hello", "world", "and", "stuff"}))
|
||||
assertParsesJSON(t, "[\"hello\",\"world\",null,\"stuff\"]", StringOrArray([]string{"hello", "world", "", "stuff"}))
|
||||
assertParsesJSON(t, "null", StringOrArray(nil))
|
||||
|
||||
// Schema
|
||||
assertParsesJSON(t, "{\"type\":\"string\"}", SchemaOrArray{Schema: &Schema{SchemaProps: SchemaProps{Type: []string{"string"}}}})
|
||||
assertParsesJSON(t, "[{\"type\":\"string\"},{\"type\":\"string\"}]", &SchemaOrArray{
|
||||
Schemas: []Schema{
|
||||
Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
Schema{SchemaProps: SchemaProps{Type: []string{"string"}}},
|
||||
},
|
||||
})
|
||||
assertParsesJSON(t, "null", SchemaOrArray{})
|
||||
}
|
||||
4
vendor/github.com/go-openapi/spec/swagger.go
generated
vendored
4
vendor/github.com/go-openapi/spec/swagger.go
generated
vendored
|
|
@ -77,7 +77,7 @@ type SwaggerProps struct {
|
|||
Host string `json:"host,omitempty"`
|
||||
BasePath string `json:"basePath,omitempty"` // must start with a leading "/"
|
||||
Paths *Paths `json:"paths"` // required
|
||||
Definitions Definitions `json:"definitions"`
|
||||
Definitions Definitions `json:"definitions,omitempty"`
|
||||
Parameters map[string]Parameter `json:"parameters,omitempty"`
|
||||
Responses map[string]Response `json:"responses,omitempty"`
|
||||
SecurityDefinitions SecurityDefinitions `json:"securityDefinitions,omitempty"`
|
||||
|
|
@ -156,7 +156,7 @@ func (s SchemaOrStringArray) MarshalJSON() ([]byte, error) {
|
|||
if s.Schema != nil {
|
||||
return json.Marshal(s.Schema)
|
||||
}
|
||||
return nil, nil
|
||||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON converts this schema object or array from a JSON structure
|
||||
|
|
|
|||
365
vendor/github.com/go-openapi/spec/swagger_test.go
generated
vendored
Normal file
365
vendor/github.com/go-openapi/spec/swagger_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,365 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var spec = Swagger{
|
||||
SwaggerProps: SwaggerProps{
|
||||
ID: "http://localhost:3849/api-docs",
|
||||
Swagger: "2.0",
|
||||
Consumes: []string{"application/json", "application/x-yaml"},
|
||||
Produces: []string{"application/json"},
|
||||
Schemes: []string{"http", "https"},
|
||||
Info: &info,
|
||||
Host: "some.api.out.there",
|
||||
BasePath: "/",
|
||||
Paths: &paths,
|
||||
Definitions: map[string]Schema{"Category": {SchemaProps: SchemaProps{Type: []string{"string"}}}},
|
||||
Parameters: map[string]Parameter{
|
||||
"categoryParam": {ParamProps: ParamProps{Name: "category", In: "query"}, SimpleSchema: SimpleSchema{Type: "string"}},
|
||||
},
|
||||
Responses: map[string]Response{
|
||||
"EmptyAnswer": {
|
||||
ResponseProps: ResponseProps{
|
||||
Description: "no data to return for this operation",
|
||||
},
|
||||
},
|
||||
},
|
||||
SecurityDefinitions: map[string]*SecurityScheme{
|
||||
"internalApiKey": APIKeyAuth("api_key", "header"),
|
||||
},
|
||||
Security: []map[string][]string{
|
||||
{"internalApiKey": {}},
|
||||
},
|
||||
Tags: []Tag{NewTag("pets", "", nil)},
|
||||
ExternalDocs: &ExternalDocumentation{"the name", "the url"},
|
||||
},
|
||||
VendorExtensible: VendorExtensible{map[string]interface{}{
|
||||
"x-some-extension": "vendor",
|
||||
"x-schemes": []interface{}{"unix", "amqp"},
|
||||
}},
|
||||
}
|
||||
|
||||
var specJSON = `{
|
||||
"id": "http://localhost:3849/api-docs",
|
||||
"consumes": ["application/json", "application/x-yaml"],
|
||||
"produces": ["application/json"],
|
||||
"schemes": ["http", "https"],
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"contact": {
|
||||
"name": "wordnik api team",
|
||||
"url": "http://developer.wordnik.com"
|
||||
},
|
||||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
"license": {
|
||||
"name": "Creative Commons 4.0 International",
|
||||
"url": "http://creativecommons.org/licenses/by/4.0/"
|
||||
},
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
"title": "Swagger Sample API",
|
||||
"version": "1.0.9-abcd",
|
||||
"x-framework": "go-swagger"
|
||||
},
|
||||
"host": "some.api.out.there",
|
||||
"basePath": "/",
|
||||
"paths": {"x-framework":"go-swagger","/":{"$ref":"cats"}},
|
||||
"definitions": { "Category": { "type": "string"} },
|
||||
"parameters": {
|
||||
"categoryParam": {
|
||||
"name": "category",
|
||||
"in": "query",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"responses": { "EmptyAnswer": { "description": "no data to return for this operation" } },
|
||||
"securityDefinitions": {
|
||||
"internalApiKey": {
|
||||
"type": "apiKey",
|
||||
"in": "header",
|
||||
"name": "api_key"
|
||||
}
|
||||
},
|
||||
"security": [{"internalApiKey":[]}],
|
||||
"tags": [{"name":"pets"}],
|
||||
"externalDocs": {"description":"the name","url":"the url"},
|
||||
"x-some-extension": "vendor",
|
||||
"x-schemes": ["unix","amqp"]
|
||||
}`
|
||||
|
||||
//
|
||||
// func verifySpecSerialize(specJSON []byte, spec Swagger) {
|
||||
// expected := map[string]interface{}{}
|
||||
// json.Unmarshal(specJSON, &expected)
|
||||
// b, err := json.MarshalIndent(spec, "", " ")
|
||||
// So(err, ShouldBeNil)
|
||||
// var actual map[string]interface{}
|
||||
// err = json.Unmarshal(b, &actual)
|
||||
// So(err, ShouldBeNil)
|
||||
// compareSpecMaps(actual, expected)
|
||||
// }
|
||||
|
||||
func assertEquivalent(t testing.TB, actual, expected interface{}) bool {
|
||||
if actual == nil || expected == nil || reflect.DeepEqual(actual, expected) {
|
||||
return true
|
||||
}
|
||||
|
||||
actualType := reflect.TypeOf(actual)
|
||||
expectedType := reflect.TypeOf(expected)
|
||||
if reflect.TypeOf(actual).ConvertibleTo(expectedType) {
|
||||
expectedValue := reflect.ValueOf(expected)
|
||||
if swag.IsZero(expectedValue) && swag.IsZero(reflect.ValueOf(actual)) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Attempt comparison after type conversion
|
||||
if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Last ditch effort
|
||||
if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) {
|
||||
return true
|
||||
}
|
||||
errFmt := "Expected: '%T(%#v)'\nActual: '%T(%#v)'\n(Should be equivalent)!"
|
||||
return assert.Fail(t, errFmt, expected, expected, actual, actual)
|
||||
}
|
||||
|
||||
func ShouldBeEquivalentTo(actual interface{}, expecteds ...interface{}) string {
|
||||
expected := expecteds[0]
|
||||
if actual == nil || expected == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(expected, actual) {
|
||||
return ""
|
||||
}
|
||||
|
||||
actualType := reflect.TypeOf(actual)
|
||||
expectedType := reflect.TypeOf(expected)
|
||||
if reflect.TypeOf(actual).ConvertibleTo(expectedType) {
|
||||
expectedValue := reflect.ValueOf(expected)
|
||||
if swag.IsZero(expectedValue) && swag.IsZero(reflect.ValueOf(actual)) {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Attempt comparison after type conversion
|
||||
if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// Last ditch effort
|
||||
if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) {
|
||||
return ""
|
||||
}
|
||||
errFmt := "Expected: '%T(%#v)'\nActual: '%T(%#v)'\n(Should be equivalent)!"
|
||||
return fmt.Sprintf(errFmt, expected, expected, actual, actual)
|
||||
|
||||
}
|
||||
|
||||
func assertSpecMaps(t testing.TB, actual, expected map[string]interface{}) bool {
|
||||
res := true
|
||||
if id, ok := expected["id"]; ok {
|
||||
res = assert.Equal(t, id, actual["id"])
|
||||
}
|
||||
res = res && assert.Equal(t, expected["consumes"], actual["consumes"])
|
||||
res = res && assert.Equal(t, expected["produces"], actual["produces"])
|
||||
res = res && assert.Equal(t, expected["schemes"], actual["schemes"])
|
||||
res = res && assert.Equal(t, expected["swagger"], actual["swagger"])
|
||||
res = res && assert.Equal(t, expected["info"], actual["info"])
|
||||
res = res && assert.Equal(t, expected["host"], actual["host"])
|
||||
res = res && assert.Equal(t, expected["basePath"], actual["basePath"])
|
||||
res = res && assert.Equal(t, expected["paths"], actual["paths"])
|
||||
res = res && assert.Equal(t, expected["definitions"], actual["definitions"])
|
||||
res = res && assert.Equal(t, expected["responses"], actual["responses"])
|
||||
res = res && assert.Equal(t, expected["securityDefinitions"], actual["securityDefinitions"])
|
||||
res = res && assert.Equal(t, expected["tags"], actual["tags"])
|
||||
res = res && assert.Equal(t, expected["externalDocs"], actual["externalDocs"])
|
||||
res = res && assert.Equal(t, expected["x-some-extension"], actual["x-some-extension"])
|
||||
res = res && assert.Equal(t, expected["x-schemes"], actual["x-schemes"])
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
//
|
||||
// func compareSpecMaps(actual, expected map[string]interface{}) {
|
||||
// if id, ok := expected["id"]; ok {
|
||||
// So(actual["id"], ShouldEqual, id)
|
||||
// }
|
||||
// //So(actual["$schema"], ShouldEqual, SwaggerSchemaURL)
|
||||
// So(actual["consumes"], ShouldResemble, expected["consumes"])
|
||||
// So(actual["produces"], ShouldResemble, expected["produces"])
|
||||
// So(actual["schemes"], ShouldResemble, expected["schemes"])
|
||||
// So(actual["swagger"], ShouldEqual, expected["swagger"])
|
||||
// So(actual["info"], ShouldResemble, expected["info"])
|
||||
// So(actual["host"], ShouldEqual, expected["host"])
|
||||
// So(actual["basePath"], ShouldEqual, expected["basePath"])
|
||||
// So(actual["paths"], ShouldBeEquivalentTo, expected["paths"])
|
||||
// So(actual["definitions"], ShouldBeEquivalentTo, expected["definitions"])
|
||||
// So(actual["responses"], ShouldBeEquivalentTo, expected["responses"])
|
||||
// So(actual["securityDefinitions"], ShouldResemble, expected["securityDefinitions"])
|
||||
// So(actual["tags"], ShouldResemble, expected["tags"])
|
||||
// So(actual["externalDocs"], ShouldResemble, expected["externalDocs"])
|
||||
// So(actual["x-some-extension"], ShouldResemble, expected["x-some-extension"])
|
||||
// So(actual["x-schemes"], ShouldResemble, expected["x-schemes"])
|
||||
// }
|
||||
|
||||
func assertSpecs(t testing.TB, actual, expected Swagger) bool {
|
||||
expected.Swagger = "2.0"
|
||||
return assert.Equal(t, actual, expected)
|
||||
}
|
||||
|
||||
//
|
||||
// func compareSpecs(actual Swagger, spec Swagger) {
|
||||
// spec.Swagger = "2.0"
|
||||
// So(actual, ShouldBeEquivalentTo, spec)
|
||||
// }
|
||||
|
||||
func assertSpecJSON(t testing.TB, specJSON []byte) bool {
|
||||
var expected map[string]interface{}
|
||||
if !assert.NoError(t, json.Unmarshal(specJSON, &expected)) {
|
||||
return false
|
||||
}
|
||||
|
||||
obj := Swagger{}
|
||||
if !assert.NoError(t, json.Unmarshal(specJSON, &obj)) {
|
||||
return false
|
||||
}
|
||||
|
||||
cb, err := json.MarshalIndent(obj, "", " ")
|
||||
if assert.NoError(t, err) {
|
||||
return false
|
||||
}
|
||||
var actual map[string]interface{}
|
||||
if !assert.NoError(t, json.Unmarshal(cb, &actual)) {
|
||||
return false
|
||||
}
|
||||
return assertSpecMaps(t, actual, expected)
|
||||
}
|
||||
|
||||
// func verifySpecJSON(specJSON []byte) {
|
||||
// //Println()
|
||||
// //Println("json to verify", string(specJson))
|
||||
// var expected map[string]interface{}
|
||||
// err := json.Unmarshal(specJSON, &expected)
|
||||
// So(err, ShouldBeNil)
|
||||
//
|
||||
// obj := Swagger{}
|
||||
// err = json.Unmarshal(specJSON, &obj)
|
||||
// So(err, ShouldBeNil)
|
||||
//
|
||||
// //spew.Dump(obj)
|
||||
//
|
||||
// cb, err := json.MarshalIndent(obj, "", " ")
|
||||
// So(err, ShouldBeNil)
|
||||
// //Println()
|
||||
// //Println("Marshalling to json returned", string(cb))
|
||||
//
|
||||
// var actual map[string]interface{}
|
||||
// err = json.Unmarshal(cb, &actual)
|
||||
// So(err, ShouldBeNil)
|
||||
// //Println()
|
||||
// //spew.Dump(expected)
|
||||
// //spew.Dump(actual)
|
||||
// //fmt.Printf("comparing %s\n\t%#v\nto\n\t%#+v\n", fileName, expected, actual)
|
||||
// compareSpecMaps(actual, expected)
|
||||
// }
|
||||
|
||||
func TestSwaggerSpec_Serialize(t *testing.T) {
|
||||
expected := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(specJSON), &expected)
|
||||
b, err := json.MarshalIndent(spec, "", " ")
|
||||
if assert.NoError(t, err) {
|
||||
var actual map[string]interface{}
|
||||
err := json.Unmarshal(b, &actual)
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, actual, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwaggerSpec_Deserialize(t *testing.T) {
|
||||
var actual Swagger
|
||||
err := json.Unmarshal([]byte(specJSON), &actual)
|
||||
if assert.NoError(t, err) {
|
||||
assert.EqualValues(t, actual, spec)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVendorExtensionStringSlice(t *testing.T) {
|
||||
var actual Swagger
|
||||
err := json.Unmarshal([]byte(specJSON), &actual)
|
||||
if assert.NoError(t, err) {
|
||||
schemes, ok := actual.Extensions.GetStringSlice("x-schemes")
|
||||
if assert.True(t, ok) {
|
||||
assert.EqualValues(t, []string{"unix", "amqp"}, schemes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptionalSwaggerProps_Serialize(t *testing.T) {
|
||||
minimalJsonSpec := []byte(`{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "0.0.0",
|
||||
"title": "Simple API"
|
||||
},
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`)
|
||||
|
||||
var minimalSpec Swagger
|
||||
err := json.Unmarshal(minimalJsonSpec, &minimalSpec)
|
||||
if assert.NoError(t, err) {
|
||||
bytes, err := json.Marshal(&minimalSpec)
|
||||
if assert.NoError(t, err) {
|
||||
var ms map[string]interface{}
|
||||
if err := json.Unmarshal(bytes, &ms); assert.NoError(t, err) {
|
||||
assert.NotContains(t, ms, "consumes")
|
||||
assert.NotContains(t, ms, "produces")
|
||||
assert.NotContains(t, ms, "schemes")
|
||||
assert.NotContains(t, ms, "host")
|
||||
assert.NotContains(t, ms, "basePath")
|
||||
assert.NotContains(t, ms, "definitions")
|
||||
assert.NotContains(t, ms, "parameters")
|
||||
assert.NotContains(t, ms, "responses")
|
||||
assert.NotContains(t, ms, "securityDefinitions")
|
||||
assert.NotContains(t, ms, "security")
|
||||
assert.NotContains(t, ms, "tags")
|
||||
assert.NotContains(t, ms, "externalDocs")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
vendor/github.com/go-openapi/spec/xml_object_test.go
generated
vendored
Normal file
65
vendor/github.com/go-openapi/spec/xml_object_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright 2015 go-swagger maintainers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestXmlObject_Serialize(t *testing.T) {
|
||||
obj1 := XMLObject{}
|
||||
actual, err := json.Marshal(obj1)
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, "{}", string(actual))
|
||||
}
|
||||
|
||||
obj2 := XMLObject{
|
||||
Name: "the name",
|
||||
Namespace: "the namespace",
|
||||
Prefix: "the prefix",
|
||||
Attribute: true,
|
||||
Wrapped: true,
|
||||
}
|
||||
|
||||
actual, err = json.Marshal(obj2)
|
||||
if assert.NoError(t, err) {
|
||||
var ad map[string]interface{}
|
||||
if assert.NoError(t, json.Unmarshal(actual, &ad)) {
|
||||
assert.Equal(t, obj2.Name, ad["name"])
|
||||
assert.Equal(t, obj2.Namespace, ad["namespace"])
|
||||
assert.Equal(t, obj2.Prefix, ad["prefix"])
|
||||
assert.True(t, ad["attribute"].(bool))
|
||||
assert.True(t, ad["wrapped"].(bool))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestXmlObject_Deserialize(t *testing.T) {
|
||||
expected := XMLObject{}
|
||||
actual := XMLObject{}
|
||||
if assert.NoError(t, json.Unmarshal([]byte("{}"), &actual)) {
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
completed := `{"name":"the name","namespace":"the namespace","prefix":"the prefix","attribute":true,"wrapped":true}`
|
||||
expected = XMLObject{"the name", "the namespace", "the prefix", true, true}
|
||||
actual = XMLObject{}
|
||||
if assert.NoError(t, json.Unmarshal([]byte(completed), &actual)) {
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue