vendor: remove dep and use vndr

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-06-06 09:19:04 +02:00
parent 16f44674a4
commit 148e72d81e
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
16131 changed files with 73815 additions and 4235138 deletions

View file

@ -1,26 +0,0 @@
# 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

View file

@ -1,117 +0,0 @@
## 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`.

View file

@ -1 +0,0 @@
secrets.yml

View file

@ -1,13 +0,0 @@
language: go
go:
- 1.7
install:
- go get -u github.com/stretchr/testify/assert
- go get -u github.com/go-openapi/swag
script:
- go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
slack:
secure: a5VgoiwB1G/AZqzmephPZIhEB9avMlsWSlVnM1dSAtYAwdrQHGTQxAmpOxYIoSPDhWNN5bfZmjd29++UlTwLcHSR+e0kJhH6IfDlsHj/HplNCJ9tyI0zYc7XchtdKgeMxMzBKCzgwFXGSbQGydXTliDNBo0HOzmY3cou/daMFTP60K+offcjS+3LRAYb1EroSRXZqrk1nuF/xDL3792DZUdPMiFR/L/Df6y74D6/QP4sTkTDFQitz4Wy/7jbsfj8dG6qK2zivgV6/l+w4OVjFkxVpPXogDWY10vVXNVynqxfJ7to2d1I9lNCHE2ilBCkWMIPdyJF7hjF8pKW+82yP4EzRh0vu8Xn0HT5MZpQxdRY/YMxNrWaG7SxsoEaO4q5uhgdzAqLYY3TRa7MjIK+7Ur+aqOeTXn6OKwVi0CjvZ6mIU3WUKSwiwkFZMbjRAkSb5CYwMEfGFO/z964xz83qGt6WAtBXNotqCQpTIiKtDHQeLOMfksHImCg6JLhQcWBVxamVgu0G3Pdh8Y6DyPnxraXY95+QDavbjqv7TeYT9T/FNnrkXaTTK0s4iWE5H4ACU0Qvz0wUYgfQrZv0/Hp7V17+rabUwnzYySHCy9SWX/7OV9Cfh31iMp9ZIffr76xmmThtOEqs8TrTtU6BWI3rWwvA9cXQipZTVtL0oswrGw=

View file

@ -1,74 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View file

@ -1,573 +0,0 @@
// Copyright 2013 sigu-399 ( https://github.com/sigu-399 )
//
// 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.
// author sigu-399
// author-github https://github.com/sigu-399
// author-mail sigu.399@gmail.com
//
// repository-name jsonpointer
// repository-desc An implementation of JSON Pointer - Go language
//
// description Automated tests on package.
//
// created 03-03-2013
package jsonpointer
import (
"encoding/json"
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
const (
TestDocumentNBItems = 11
TestNodeObjNBItems = 4
TestDocumentString = `{
"foo": ["bar", "baz"],
"obj": { "a":1, "b":2, "c":[3,4], "d":[ {"e":9}, {"f":[50,51]} ] },
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
}`
)
var testDocumentJSON interface{}
type testStructJSON struct {
Foo []string `json:"foo"`
Obj struct {
A int `json:"a"`
B int `json:"b"`
C []int `json:"c"`
D []struct {
E int `json:"e"`
F []int `json:"f"`
} `json:"d"`
} `json:"obj"`
}
type aliasedMap map[string]interface{}
var testStructJSONDoc testStructJSON
var testStructJSONPtr *testStructJSON
func init() {
json.Unmarshal([]byte(TestDocumentString), &testDocumentJSON)
json.Unmarshal([]byte(TestDocumentString), &testStructJSONDoc)
testStructJSONPtr = &testStructJSONDoc
}
func TestEscaping(t *testing.T) {
ins := []string{`/`, `/`, `/a~1b`, `/a~1b`, `/c%d`, `/e^f`, `/g|h`, `/i\j`, `/k"l`, `/ `, `/m~0n`}
outs := []float64{0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 8}
for i := range ins {
p, err := New(ins[i])
if assert.NoError(t, err, "input: %v", ins[i]) {
result, _, err := p.Get(testDocumentJSON)
if assert.NoError(t, err, "input: %v", ins[i]) {
assert.Equal(t, outs[i], result, "input: %v", ins[i])
}
}
}
}
func TestFullDocument(t *testing.T) {
in := ``
p, err := New(in)
if err != nil {
t.Errorf("New(%v) error %v", in, err.Error())
}
result, _, err := p.Get(testDocumentJSON)
if err != nil {
t.Errorf("Get(%v) error %v", in, err.Error())
}
if len(result.(map[string]interface{})) != TestDocumentNBItems {
t.Errorf("Get(%v) = %v, expect full document", in, result)
}
result, _, err = p.get(testDocumentJSON, nil)
if err != nil {
t.Errorf("Get(%v) error %v", in, err.Error())
}
if len(result.(map[string]interface{})) != TestDocumentNBItems {
t.Errorf("Get(%v) = %v, expect full document", in, result)
}
}
func TestDecodedTokens(t *testing.T) {
p, err := New("/obj/a~1b")
assert.NoError(t, err)
assert.Equal(t, []string{"obj", "a/b"}, p.DecodedTokens())
}
func TestIsEmpty(t *testing.T) {
p, err := New("")
assert.NoError(t, err)
assert.True(t, p.IsEmpty())
p, err = New("/obj")
assert.NoError(t, err)
assert.False(t, p.IsEmpty())
}
func TestGetSingle(t *testing.T) {
in := `/obj`
_, err := New(in)
assert.NoError(t, err)
result, _, err := GetForToken(testDocumentJSON, "obj")
assert.NoError(t, err)
assert.Len(t, result, TestNodeObjNBItems)
result, _, err = GetForToken(testStructJSONDoc, "Obj")
assert.Error(t, err)
assert.Nil(t, result)
result, _, err = GetForToken(testStructJSONDoc, "Obj2")
assert.Error(t, err)
assert.Nil(t, result)
}
type pointableImpl struct {
a string
}
func (p pointableImpl) JSONLookup(token string) (interface{}, error) {
if token == "some" {
return p.a, nil
}
return nil, fmt.Errorf("object has no field %q", token)
}
func TestPointableInterface(t *testing.T) {
p := &pointableImpl{"hello"}
result, _, err := GetForToken(p, "some")
assert.NoError(t, err)
assert.Equal(t, p.a, result)
result, _, err = GetForToken(p, "something")
assert.Error(t, err)
assert.Nil(t, result)
}
func TestGetNode(t *testing.T) {
in := `/obj`
p, err := New(in)
assert.NoError(t, err)
result, _, err := p.Get(testDocumentJSON)
assert.NoError(t, err)
assert.Len(t, result, TestNodeObjNBItems)
result, _, err = p.Get(aliasedMap(testDocumentJSON.(map[string]interface{})))
assert.NoError(t, err)
assert.Len(t, result, TestNodeObjNBItems)
result, _, err = p.Get(testStructJSONDoc)
assert.NoError(t, err)
assert.Equal(t, testStructJSONDoc.Obj, result)
result, _, err = p.Get(testStructJSONPtr)
assert.NoError(t, err)
assert.Equal(t, testStructJSONDoc.Obj, result)
}
func TestArray(t *testing.T) {
ins := []string{`/foo/0`, `/foo/0`, `/foo/1`}
outs := []string{"bar", "bar", "baz"}
for i := range ins {
p, err := New(ins[i])
assert.NoError(t, err)
result, _, err := p.Get(testStructJSONDoc)
assert.NoError(t, err)
assert.Equal(t, outs[i], result)
result, _, err = p.Get(testStructJSONPtr)
assert.NoError(t, err)
assert.Equal(t, outs[i], result)
result, _, err = p.Get(testDocumentJSON)
assert.NoError(t, err)
assert.Equal(t, outs[i], result)
}
}
func TestOtherThings(t *testing.T) {
_, err := New("abc")
assert.Error(t, err)
p, err := New("")
assert.NoError(t, err)
assert.Equal(t, "", p.String())
p, err = New("/obj/a")
assert.Equal(t, "/obj/a", p.String())
s := Escape("m~n")
assert.Equal(t, "m~0n", s)
s = Escape("m/n")
assert.Equal(t, "m~1n", s)
p, err = New("/foo/3")
assert.NoError(t, err)
_, _, err = p.Get(testDocumentJSON)
assert.Error(t, err)
p, err = New("/foo/a")
assert.NoError(t, err)
_, _, err = p.Get(testDocumentJSON)
assert.Error(t, err)
p, err = New("/notthere")
assert.NoError(t, err)
_, _, err = p.Get(testDocumentJSON)
assert.Error(t, err)
p, err = New("/invalid")
assert.NoError(t, err)
_, _, err = p.Get(1234)
assert.Error(t, err)
p, err = New("/foo/1")
assert.NoError(t, err)
expected := "hello"
bbb := testDocumentJSON.(map[string]interface{})["foo"]
bbb.([]interface{})[1] = "hello"
v, _, err := p.Get(testDocumentJSON)
assert.NoError(t, err)
assert.Equal(t, expected, v)
esc := Escape("a/")
assert.Equal(t, "a~1", esc)
unesc := Unescape(esc)
assert.Equal(t, "a/", unesc)
unesc = Unescape("~01")
assert.Equal(t, "~1", unesc)
assert.Equal(t, "~0~1", Escape("~/"))
assert.Equal(t, "~/", Unescape("~0~1"))
}
func TestObject(t *testing.T) {
ins := []string{`/obj/a`, `/obj/b`, `/obj/c/0`, `/obj/c/1`, `/obj/c/1`, `/obj/d/1/f/0`}
outs := []float64{1, 2, 3, 4, 4, 50}
for i := range ins {
p, err := New(ins[i])
assert.NoError(t, err)
result, _, err := p.Get(testDocumentJSON)
assert.NoError(t, err)
assert.Equal(t, outs[i], result)
result, _, err = p.Get(testStructJSONDoc)
assert.NoError(t, err)
assert.EqualValues(t, outs[i], result)
result, _, err = p.Get(testStructJSONPtr)
assert.NoError(t, err)
assert.EqualValues(t, outs[i], result)
}
}
type setJsonDocEle struct {
B int `json:"b"`
C int `json:"c"`
}
type setJsonDoc struct {
A []struct {
B int `json:"b"`
C int `json:"c"`
} `json:"a"`
D int `json:"d"`
}
type settableDoc struct {
Coll settableColl
Int settableInt
}
func (s settableDoc) MarshalJSON() ([]byte, error) {
var res struct {
A settableColl `json:"a"`
D settableInt `json:"d"`
}
res.A = s.Coll
res.D = s.Int
return json.Marshal(res)
}
func (s *settableDoc) UnmarshalJSON(data []byte) error {
var res struct {
A settableColl `json:"a"`
D settableInt `json:"d"`
}
if err := json.Unmarshal(data, &res); err != nil {
return err
}
s.Coll = res.A
s.Int = res.D
return nil
}
// JSONLookup implements an interface to customize json pointer lookup
func (s settableDoc) JSONLookup(token string) (interface{}, error) {
switch token {
case "a":
return &s.Coll, nil
case "d":
return &s.Int, nil
default:
return nil, fmt.Errorf("%s is not a known field", token)
}
}
// JSONLookup implements an interface to customize json pointer lookup
func (s *settableDoc) JSONSet(token string, data interface{}) error {
switch token {
case "a":
switch dt := data.(type) {
case settableColl:
s.Coll = dt
return nil
case *settableColl:
if dt != nil {
s.Coll = *dt
} else {
s.Coll = settableColl{}
}
return nil
case []settableCollItem:
s.Coll.Items = dt
return nil
}
case "d":
switch dt := data.(type) {
case settableInt:
s.Int = dt
return nil
case int:
s.Int.Value = dt
return nil
case int8:
s.Int.Value = int(dt)
return nil
case int16:
s.Int.Value = int(dt)
return nil
case int32:
s.Int.Value = int(dt)
return nil
case int64:
s.Int.Value = int(dt)
return nil
default:
return fmt.Errorf("invalid type %T for %s", data, token)
}
}
return fmt.Errorf("%s is not a known field", token)
}
type settableColl struct {
Items []settableCollItem
}
func (s settableColl) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Items)
}
func (s *settableColl) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &s.Items)
}
// JSONLookup implements an interface to customize json pointer lookup
func (s settableColl) JSONLookup(token string) (interface{}, error) {
if tok, err := strconv.Atoi(token); err == nil {
return &s.Items[tok], nil
}
return nil, fmt.Errorf("%s is not a valid index", token)
}
// JSONLookup implements an interface to customize json pointer lookup
func (s *settableColl) JSONSet(token string, data interface{}) error {
if _, err := strconv.Atoi(token); err == nil {
_, err := SetForToken(s.Items, token, data)
return err
}
return fmt.Errorf("%s is not a valid index", token)
}
type settableCollItem struct {
B int `json:"b"`
C int `json:"c"`
}
type settableInt struct {
Value int
}
func (s settableInt) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Value)
}
func (s *settableInt) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &s.Value)
}
func TestSetNode(t *testing.T) {
jsonText := `{"a":[{"b": 1, "c": 2}], "d": 3}`
var jsonDocument interface{}
if assert.NoError(t, json.Unmarshal([]byte(jsonText), &jsonDocument)) {
in := "/a/0/c"
p, err := New(in)
if assert.NoError(t, err) {
_, err = p.Set(jsonDocument, 999)
assert.NoError(t, err)
firstNode := jsonDocument.(map[string]interface{})
assert.Len(t, firstNode, 2)
sliceNode := firstNode["a"].([]interface{})
assert.Len(t, sliceNode, 1)
changedNode := sliceNode[0].(map[string]interface{})
chNodeVI := changedNode["c"]
if assert.IsType(t, 0, chNodeVI) {
changedNodeValue := chNodeVI.(int)
if assert.Equal(t, 999, changedNodeValue) {
assert.Len(t, sliceNode, 1)
}
}
}
v, err := New("/a/0")
if assert.NoError(t, err) {
_, err = v.Set(jsonDocument, map[string]interface{}{"b": 3, "c": 8})
if assert.NoError(t, err) {
firstNode := jsonDocument.(map[string]interface{})
assert.Len(t, firstNode, 2)
sliceNode := firstNode["a"].([]interface{})
assert.Len(t, sliceNode, 1)
changedNode := sliceNode[0].(map[string]interface{})
assert.Equal(t, 3, changedNode["b"])
assert.Equal(t, 8, changedNode["c"])
}
}
}
var structDoc setJsonDoc
if assert.NoError(t, json.Unmarshal([]byte(jsonText), &structDoc)) {
g, err := New("/a")
if assert.NoError(t, err) {
_, err = g.Set(&structDoc, []struct {
B int `json:"b"`
C int `json:"c"`
}{{B: 4, C: 7}})
if assert.NoError(t, err) {
assert.Len(t, structDoc.A, 1)
changedNode := structDoc.A[0]
assert.Equal(t, 4, changedNode.B)
assert.Equal(t, 7, changedNode.C)
}
}
v, err := New("/a/0")
if assert.NoError(t, err) {
_, err = v.Set(structDoc, struct {
B int `json:"b"`
C int `json:"c"`
}{B: 3, C: 8})
if assert.NoError(t, err) {
assert.Len(t, structDoc.A, 1)
changedNode := structDoc.A[0]
assert.Equal(t, 3, changedNode.B)
assert.Equal(t, 8, changedNode.C)
}
}
p, err := New("/a/0/c")
if assert.NoError(t, err) {
_, err = p.Set(&structDoc, 999)
assert.NoError(t, err)
if assert.Len(t, structDoc.A, 1) {
assert.Equal(t, 999, structDoc.A[0].C)
}
}
}
var setDoc settableDoc
if assert.NoError(t, json.Unmarshal([]byte(jsonText), &setDoc)) {
g, err := New("/a")
if assert.NoError(t, err) {
_, err = g.Set(&setDoc, []settableCollItem{{B: 4, C: 7}})
if assert.NoError(t, err) {
assert.Len(t, setDoc.Coll.Items, 1)
changedNode := setDoc.Coll.Items[0]
assert.Equal(t, 4, changedNode.B)
assert.Equal(t, 7, changedNode.C)
}
}
v, err := New("/a/0")
if assert.NoError(t, err) {
_, err = v.Set(setDoc, settableCollItem{B: 3, C: 8})
if assert.NoError(t, err) {
assert.Len(t, setDoc.Coll.Items, 1)
changedNode := setDoc.Coll.Items[0]
assert.Equal(t, 3, changedNode.B)
assert.Equal(t, 8, changedNode.C)
}
}
p, err := New("/a/0/c")
if assert.NoError(t, err) {
_, err = p.Set(setDoc, 999)
assert.NoError(t, err)
if assert.Len(t, setDoc.Coll.Items, 1) {
assert.Equal(t, 999, setDoc.Coll.Items[0].C)
}
}
}
}

View file

@ -1,117 +0,0 @@
## 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`.

View file

@ -1 +0,0 @@
secrets.yml

View file

@ -1,14 +0,0 @@
language: go
go:
- 1.7
install:
- go get -u github.com/stretchr/testify/assert
- go get -u github.com/PuerkitoBio/purell
- go get -u github.com/go-openapi/jsonpointer
script:
- go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic ./...
after_success:
- bash <(curl -s https://codecov.io/bash)
notifications:
slack:
secure: OpQG/36F7DSF00HLm9WZMhyqFCYYyYTsVDObW226cWiR8PWYiNfLZiSEvIzT1Gx4dDjhigKTIqcLhG34CkL5iNXDjm9Yyo2RYhQPlK8NErNqUEXuBqn4RqYHW48VGhEhOyDd4Ei0E2FN5ZbgpvHgtpkdZ6XDi64r3Ac89isP9aPHXQTuv2Jog6b4/OKKiUTftLcTIst0p4Cp3gqOJWf1wnoj+IadWiECNVQT6zb47IYjtyw6+uV8iUjTzdKcRB6Zc6b4Dq7JAg1Zd7Jfxkql3hlKp4PNlRf9Cy7y5iA3G7MLyg3FcPX5z2kmcyPt2jOTRMBWUJ5zIQpOxizAcN8WsT3WWBL5KbuYK6k0PzujrIDLqdxGpNmjkkMfDBT9cKmZpm2FdW+oZgPFJP+oKmAo4u4KJz/vjiPTXgQlN5bmrLuRMCp+AwC5wkIohTqWZVPE2TK6ZSnMYcg/W39s+RP/9mJoyryAvPSpBOLTI+biCgaUCTOAZxNTWpMFc3tPYntc41WWkdKcooZ9JA5DwfcaVFyTGQ3YXz+HvX6G1z/gW0Q/A4dBi9mj2iE1xm7tRTT+4VQ2AXFvSEI1HJpfPgYnwAtwOD1v3Qm2EUHk9sCdtEDR4wVGEPIVn44GnwFMnGKx9JWppMPYwFu3SVDdHt+E+LOlhZUply11Aa+IVrT2KUQ=

View file

@ -1,74 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View file

@ -1,420 +0,0 @@
// Copyright 2013 sigu-399 ( https://github.com/sigu-399 )
//
// 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.
// author sigu-399
// author-github https://github.com/sigu-399
// author-mail sigu.399@gmail.com
//
// repository-name jsonreference
// repository-desc An implementation of JSON Reference - Go language
//
// description Automated tests on package.
//
// created 03-03-2013
package jsonreference
import (
"testing"
"github.com/go-openapi/jsonpointer"
"github.com/stretchr/testify/assert"
)
func TestIsRoot(t *testing.T) {
in := "#"
r1, err := New(in)
assert.NoError(t, err)
assert.True(t, r1.IsRoot())
in = "#/ok"
r1 = MustCreateRef(in)
assert.False(t, r1.IsRoot())
assert.Panics(t, assert.PanicTestFunc(func() {
MustCreateRef("%2")
}))
}
func TestFull(t *testing.T) {
in := "http://host/path/a/b/c#/f/a/b"
r1, err := New(in)
if err != nil {
t.Errorf("New(%v) error %s", in, err.Error())
}
if in != r1.String() {
t.Errorf("New(%v) = %v, expect %v", in, r1.String(), in)
}
if r1.HasFragmentOnly != false {
t.Errorf("New(%v)::HasFragmentOnly %v expect %v", in, r1.HasFragmentOnly, false)
}
if r1.HasFullURL != true {
t.Errorf("New(%v)::HasFullURL %v expect %v", in, r1.HasFullURL, true)
}
if r1.HasURLPathOnly != false {
t.Errorf("New(%v)::HasURLPathOnly %v expect %v", in, r1.HasURLPathOnly, false)
}
if r1.HasFileScheme != false {
t.Errorf("New(%v)::HasFileScheme %v expect %v", in, r1.HasFileScheme, false)
}
if r1.GetPointer().String() != "/f/a/b" {
t.Errorf("New(%v)::GetPointer() %v expect %v", in, r1.GetPointer().String(), "/f/a/b")
}
}
func TestFullURL(t *testing.T) {
in := "http://host/path/a/b/c"
r1, err := New(in)
if err != nil {
t.Errorf("New(%v) error %s", in, err.Error())
}
if in != r1.String() {
t.Errorf("New(%v) = %v, expect %v", in, r1.String(), in)
}
if r1.HasFragmentOnly != false {
t.Errorf("New(%v)::HasFragmentOnly %v expect %v", in, r1.HasFragmentOnly, false)
}
if r1.HasFullURL != true {
t.Errorf("New(%v)::HasFullURL %v expect %v", in, r1.HasFullURL, true)
}
if r1.HasURLPathOnly != false {
t.Errorf("New(%v)::HasURLPathOnly %v expect %v", in, r1.HasURLPathOnly, false)
}
if r1.HasFileScheme != false {
t.Errorf("New(%v)::HasFileScheme %v expect %v", in, r1.HasFileScheme, false)
}
if r1.GetPointer().String() != "" {
t.Errorf("New(%v)::GetPointer() %v expect %v", in, r1.GetPointer().String(), "")
}
}
func TestFragmentOnly(t *testing.T) {
in := "#/fragment/only"
r1, err := New(in)
if err != nil {
t.Errorf("New(%v) error %s", in, err.Error())
}
if in != r1.String() {
t.Errorf("New(%v) = %v, expect %v", in, r1.String(), in)
}
if r1.HasFragmentOnly != true {
t.Errorf("New(%v)::HasFragmentOnly %v expect %v", in, r1.HasFragmentOnly, true)
}
if r1.HasFullURL != false {
t.Errorf("New(%v)::HasFullURL %v expect %v", in, r1.HasFullURL, false)
}
if r1.HasURLPathOnly != false {
t.Errorf("New(%v)::HasURLPathOnly %v expect %v", in, r1.HasURLPathOnly, false)
}
if r1.HasFileScheme != false {
t.Errorf("New(%v)::HasFileScheme %v expect %v", in, r1.HasFileScheme, false)
}
if r1.GetPointer().String() != "/fragment/only" {
t.Errorf("New(%v)::GetPointer() %v expect %v", in, r1.GetPointer().String(), "/fragment/only")
}
p, _ := jsonpointer.New(r1.referenceURL.Fragment)
r2 := Ref{referencePointer: p, HasFragmentOnly: true}
assert.Equal(t, r2.String(), in)
r3 := Ref{referencePointer: p, HasFragmentOnly: false}
assert.Equal(t, r3.String(), in[1:])
}
func TestURLPathOnly(t *testing.T) {
in := "/documents/document.json"
r1, err := New(in)
if err != nil {
t.Errorf("New(%v) error %s", in, err.Error())
}
if in != r1.String() {
t.Errorf("New(%v) = %v, expect %v", in, r1.String(), in)
}
if r1.HasFragmentOnly != false {
t.Errorf("New(%v)::HasFragmentOnly %v expect %v", in, r1.HasFragmentOnly, false)
}
if r1.HasFullURL != false {
t.Errorf("New(%v)::HasFullURL %v expect %v", in, r1.HasFullURL, false)
}
if r1.HasURLPathOnly != true {
t.Errorf("New(%v)::HasURLPathOnly %v expect %v", in, r1.HasURLPathOnly, true)
}
if r1.HasFileScheme != false {
t.Errorf("New(%v)::HasFileScheme %v expect %v", in, r1.HasFileScheme, false)
}
if r1.GetPointer().String() != "" {
t.Errorf("New(%v)::GetPointer() %v expect %v", in, r1.GetPointer().String(), "")
}
}
func TestURLRelativePathOnly(t *testing.T) {
in := "document.json"
r1, err := New(in)
if err != nil {
t.Errorf("New(%v) error %s", in, err.Error())
}
if in != r1.String() {
t.Errorf("New(%v) = %v, expect %v", in, r1.String(), in)
}
if r1.HasFragmentOnly != false {
t.Errorf("New(%v)::HasFragmentOnly %v expect %v", in, r1.HasFragmentOnly, false)
}
if r1.HasFullURL != false {
t.Errorf("New(%v)::HasFullURL %v expect %v", in, r1.HasFullURL, false)
}
if r1.HasURLPathOnly != true {
t.Errorf("New(%v)::HasURLPathOnly %v expect %v", in, r1.HasURLPathOnly, true)
}
if r1.HasFileScheme != false {
t.Errorf("New(%v)::HasFileScheme %v expect %v", in, r1.HasFileScheme, false)
}
if r1.GetPointer().String() != "" {
t.Errorf("New(%v)::GetPointer() %v expect %v", in, r1.GetPointer().String(), "")
}
}
func TestInheritsInValid(t *testing.T) {
in1 := "http://www.test.com/doc.json"
in2 := "#/a/b"
r1, _ := New(in1)
r2 := Ref{}
result, err := r1.Inherits(r2)
assert.Error(t, err)
assert.Nil(t, result)
r1 = Ref{}
r2, _ = New(in2)
result, err = r1.Inherits(r2)
assert.NoError(t, err)
assert.Equal(t, r2, *result)
}
func TestInheritsValid(t *testing.T) {
in1 := "http://www.test.com/doc.json"
in2 := "#/a/b"
out := in1 + in2
r1, _ := New(in1)
r2, _ := New(in2)
result, err := r1.Inherits(r2)
if err != nil {
t.Errorf("Inherits(%s,%s) error %s", r1.String(), r2.String(), err.Error())
}
if result.String() != out {
t.Errorf("Inherits(%s,%s) = %s, expect %s", r1.String(), r2.String(), result.String(), out)
}
if result.GetPointer().String() != "/a/b" {
t.Errorf("result(%v)::GetPointer() %v expect %v", result.String(), result.GetPointer().String(), "/a/b")
}
}
func TestInheritsDifferentHost(t *testing.T) {
in1 := "http://www.test.com/doc.json"
in2 := "http://www.test2.com/doc.json#bla"
r1, _ := New(in1)
r2, _ := New(in2)
result, err := r1.Inherits(r2)
if err != nil {
t.Errorf("Inherits(%s,%s) should not fail. Error: %s", r1.String(), r2.String(), err.Error())
}
if result.String() != in2 {
t.Errorf("Inherits(%s,%s) should be %s but is %s", in1, in2, in2, result)
}
if result.GetPointer().String() != "" {
t.Errorf("result(%v)::GetPointer() %v expect %v", result.String(), result.GetPointer().String(), "")
}
}
func TestFileScheme(t *testing.T) {
in1 := "file:///Users/mac/1.json#a"
in2 := "file:///Users/mac/2.json#b"
r1, _ := New(in1)
r2, _ := New(in2)
if r1.HasFragmentOnly != false {
t.Errorf("New(%v)::HasFragmentOnly %v expect %v", in1, r1.HasFragmentOnly, false)
}
if r1.HasFileScheme != true {
t.Errorf("New(%v)::HasFileScheme %v expect %v", in1, r1.HasFileScheme, true)
}
if r1.HasFullFilePath != true {
t.Errorf("New(%v)::HasFullFilePath %v expect %v", in1, r1.HasFullFilePath, true)
}
if r1.IsCanonical() != true {
t.Errorf("New(%v)::IsCanonical %v expect %v", in1, r1.IsCanonical, true)
}
result, err := r1.Inherits(r2)
if err != nil {
t.Errorf("Inherits(%s,%s) should not fail. Error: %s", r1.String(), r2.String(), err.Error())
}
if result.String() != in2 {
t.Errorf("Inherits(%s,%s) should be %s but is %s", in1, in2, in2, result)
}
if result.GetPointer().String() != "" {
t.Errorf("result(%v)::GetPointer() %v expect %v", result.String(), result.GetPointer().String(), "")
}
}
func TestReferenceResolution(t *testing.T) {
// 5.4. Reference Resolution Examples
// http://tools.ietf.org/html/rfc3986#section-5.4
base := "http://a/b/c/d;p?q"
baseRef, err := New(base)
if err != nil {
t.Errorf("New(%s) failed error: %s", base, err.Error())
}
if baseRef.String() != base {
t.Errorf("New(%s) %s expected %s", base, baseRef.String(), base)
}
checks := []string{
// 5.4.1. Normal Examples
// http://tools.ietf.org/html/rfc3986#section-5.4.1
"g:h", "g:h",
"g", "http://a/b/c/g",
"./g", "http://a/b/c/g",
"g/", "http://a/b/c/g/",
"/g", "http://a/g",
"//g", "http://g",
"?y", "http://a/b/c/d;p?y",
"g?y", "http://a/b/c/g?y",
"#s", "http://a/b/c/d;p?q#s",
"g#s", "http://a/b/c/g#s",
"g?y#s", "http://a/b/c/g?y#s",
";x", "http://a/b/c/;x",
"g;x", "http://a/b/c/g;x",
"g;x?y#s", "http://a/b/c/g;x?y#s",
"", "http://a/b/c/d;p?q",
".", "http://a/b/c/",
"./", "http://a/b/c/",
"..", "http://a/b/",
"../", "http://a/b/",
"../g", "http://a/b/g",
"../..", "http://a/",
"../../", "http://a/",
"../../g", "http://a/g",
// 5.4.2. Abnormal Examples
// http://tools.ietf.org/html/rfc3986#section-5.4.2
"../../../g", "http://a/g",
"../../../../g", "http://a/g",
"/./g", "http://a/g",
"/../g", "http://a/g",
"g.", "http://a/b/c/g.",
".g", "http://a/b/c/.g",
"g..", "http://a/b/c/g..",
"..g", "http://a/b/c/..g",
"./../g", "http://a/b/g",
"./g/.", "http://a/b/c/g/",
"g/./h", "http://a/b/c/g/h",
"g/../h", "http://a/b/c/h",
"g;x=1/./y", "http://a/b/c/g;x=1/y",
"g;x=1/../y", "http://a/b/c/y",
"g?y/./x", "http://a/b/c/g?y/./x",
"g?y/../x", "http://a/b/c/g?y/../x",
"g#s/./x", "http://a/b/c/g#s/./x",
"g#s/../x", "http://a/b/c/g#s/../x",
"http:g", "http:g", // for strict parsers
//"http:g", "http://a/b/c/g", // for backward compatibility
}
for i := 0; i < len(checks); i += 2 {
child := checks[i]
expected := checks[i+1]
// fmt.Printf("%d: %v -> %v\n", i/2, child, expected)
childRef, e := New(child)
if e != nil {
t.Errorf("%d: New(%s) failed error: %s", i/2, child, e.Error())
}
res, e := baseRef.Inherits(childRef)
if res == nil {
t.Errorf("%d: Inherits(%s, %s) nil not expected", i/2, base, child)
}
if e != nil {
t.Errorf("%d: Inherits(%s) failed error: %s", i/2, child, e.Error())
}
if res.String() != expected {
t.Errorf("%d: Inherits(%s, %s) %s expected %s", i/2, base, child, res.String(), expected)
}
}
}

View file

@ -1,26 +0,0 @@
# 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

View file

@ -1,117 +0,0 @@
## 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`.

View file

@ -1,2 +0,0 @@
secrets.yml
coverage.out

View file

@ -1,16 +0,0 @@
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=

View file

@ -1,74 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View file

@ -1,128 +0,0 @@
// 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)
}

View file

@ -1,37 +0,0 @@
// 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)
}

File diff suppressed because it is too large Load diff

View file

@ -1,29 +0,0 @@
// 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)
}

View file

@ -1,254 +0,0 @@
{
"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"
}
}
}
}
}

View file

@ -1,54 +0,0 @@
{
"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"
}
}
}
}
}

View file

@ -1 +0,0 @@
{"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"]}}}

View file

@ -1,67 +0,0 @@
---
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

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -1,85 +0,0 @@
{
"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"
}
}
}
}
}

View file

@ -1,124 +0,0 @@
{
"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"
]
}
}
}

View file

@ -1,25 +0,0 @@
{
"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"}
]
}
}
}

View file

@ -1,127 +0,0 @@
{
"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"
}
}
}
}
}

View file

@ -1,161 +0,0 @@
{
"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"
}
}
}
}
}
}

View file

@ -1,18 +0,0 @@
{
"properties": {
"id": {
"format": "int64",
"readOnly": true,
"type": "integer"
},
"title": {
"maxLength": 80,
"minLength": 2,
"type": "string"
}
},
"required": [
"title"
],
"type": "object"
}

View file

@ -1,46 +0,0 @@
{
"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"
}

View file

@ -1,6 +0,0 @@
{
"type":"array",
"items": {
"type": "string"
}
}

View file

@ -1,3 +0,0 @@
{
"type": "string"
}

View file

@ -1,224 +0,0 @@
{
"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"
}
}
}
}
}

View file

@ -1,14 +0,0 @@
{
"id": "http://localhost:1234",
"items": {
"id": "deeper/",
"items": {
"$ref": "stringProp.json"
}
},
"definitions": {
"bool": {
"$ref": "boolProp.json"
}
}
}

View file

@ -1,9 +0,0 @@
{
"id": "http://localhost:1234",
"items": {
"id": "deeper/",
"items": {
"$ref": "arrayProp.json#/items"
}
}
}

View file

@ -1,90 +0,0 @@
// 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)
}

View file

@ -1,65 +0,0 @@
// 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)
}
}

View file

@ -1,81 +0,0 @@
// 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)
}

View file

@ -1,28 +0,0 @@
// 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)
}

View file

@ -1,85 +0,0 @@
// 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)
}

View file

@ -1,156 +0,0 @@
// 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"}}}`)
}

View file

@ -1,81 +0,0 @@
// 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)
}

View file

@ -1,43 +0,0 @@
// 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)
}

View file

@ -1,58 +0,0 @@
// 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)
}
}

View file

@ -1,53 +0,0 @@
// 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)
}

View file

@ -1,205 +0,0 @@
// 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"])
}
}

View file

@ -1,150 +0,0 @@
{
"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": {}
}

View file

@ -1,5 +0,0 @@
# 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

File diff suppressed because it is too large Load diff

View file

@ -1,110 +0,0 @@
// 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{})
}

View file

@ -1,365 +0,0 @@
// 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")
}
}
}
}

View file

@ -1,65 +0,0 @@
// 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)
}
}

View file

@ -1,26 +0,0 @@
# 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

View file

@ -1,117 +0,0 @@
## 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`.

View file

@ -1 +0,0 @@
secrets.yml

View file

@ -1,13 +0,0 @@
language: go
go:
- 1.7
install:
- go get -u github.com/stretchr/testify
- go get -u github.com/mailru/easyjson
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=

View file

@ -1,74 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at ivan+abuse@flanders.co.nz. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View file

@ -1,215 +0,0 @@
// 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 swag
import (
"math"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
// These are really dumb tests
func TestConvertBool(t *testing.T) {
for k := range evaluatesAsTrue {
r, err := ConvertBool(k)
if assert.NoError(t, err) {
assert.True(t, r)
}
}
for _, k := range []string{"a", "", "0", "false", "unchecked"} {
r, err := ConvertBool(k)
if assert.NoError(t, err) {
assert.False(t, r)
}
}
}
func TestConvertFloat32(t *testing.T) {
validFloats := []float32{1.0, -1, math.MaxFloat32, math.SmallestNonzeroFloat32, 0, 5.494430303}
invalidFloats := []string{"a", strconv.FormatFloat(math.MaxFloat64, 'f', -1, 64), "true"}
for _, f := range validFloats {
c, err := ConvertFloat32(FormatFloat32(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidFloats {
_, err := ConvertFloat32(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertFloat64(t *testing.T) {
validFloats := []float64{1.0, -1, float64(math.MaxFloat32), float64(math.SmallestNonzeroFloat32), math.MaxFloat64, math.SmallestNonzeroFloat64, 0, 5.494430303}
invalidFloats := []string{"a", "true"}
for _, f := range validFloats {
c, err := ConvertFloat64(FormatFloat64(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidFloats {
_, err := ConvertFloat64(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertInt8(t *testing.T) {
validInts := []int8{0, 1, -1, math.MaxInt8, math.MinInt8}
invalidInts := []string{"1.233", "a", "false", strconv.Itoa(int(math.MaxInt64))}
for _, f := range validInts {
c, err := ConvertInt8(FormatInt8(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidInts {
_, err := ConvertInt8(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertInt16(t *testing.T) {
validInts := []int16{0, 1, -1, math.MaxInt8, math.MinInt8, math.MaxInt16, math.MinInt16}
invalidInts := []string{"1.233", "a", "false", strconv.Itoa(int(math.MaxInt64))}
for _, f := range validInts {
c, err := ConvertInt16(FormatInt16(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidInts {
_, err := ConvertInt16(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertInt32(t *testing.T) {
validInts := []int32{0, 1, -1, math.MaxInt8, math.MinInt8, math.MaxInt16, math.MinInt16, math.MinInt32, math.MaxInt32}
invalidInts := []string{"1.233", "a", "false", strconv.Itoa(int(math.MaxInt64))}
for _, f := range validInts {
c, err := ConvertInt32(FormatInt32(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidInts {
_, err := ConvertInt32(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertInt64(t *testing.T) {
validInts := []int64{0, 1, -1, math.MaxInt8, math.MinInt8, math.MaxInt16, math.MinInt16, math.MinInt32, math.MaxInt32, math.MaxInt64, math.MinInt64}
invalidInts := []string{"1.233", "a", "false"}
for _, f := range validInts {
c, err := ConvertInt64(FormatInt64(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidInts {
_, err := ConvertInt64(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertUint8(t *testing.T) {
validInts := []uint8{0, 1, math.MaxUint8}
invalidInts := []string{"1.233", "a", "false", strconv.FormatUint(math.MaxUint64, 10)}
for _, f := range validInts {
c, err := ConvertUint8(FormatUint8(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidInts {
_, err := ConvertUint8(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertUint16(t *testing.T) {
validUints := []uint16{0, 1, math.MaxUint8, math.MaxUint16}
invalidUints := []string{"1.233", "a", "false", strconv.FormatUint(math.MaxUint64, 10)}
for _, f := range validUints {
c, err := ConvertUint16(FormatUint16(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidUints {
_, err := ConvertUint16(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertUint32(t *testing.T) {
validUints := []uint32{0, 1, math.MaxUint8, math.MaxUint16, math.MaxUint32}
invalidUints := []string{"1.233", "a", "false", strconv.FormatUint(math.MaxUint64, 10)}
for _, f := range validUints {
c, err := ConvertUint32(FormatUint32(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidUints {
_, err := ConvertUint32(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestConvertUint64(t *testing.T) {
validUints := []uint64{0, 1, math.MaxUint8, math.MaxUint16, math.MaxUint32, math.MaxUint64}
invalidUints := []string{"1.233", "a", "false"}
for _, f := range validUints {
c, err := ConvertUint64(FormatUint64(f))
if assert.NoError(t, err) {
assert.EqualValues(t, f, c)
}
}
for _, f := range invalidUints {
_, err := ConvertUint64(f)
assert.Error(t, err, "expected '"+f+"' to generate an error")
}
}
func TestIsFloat64AJSONInteger(t *testing.T) {
assert.False(t, IsFloat64AJSONInteger(math.Inf(1)))
assert.False(t, IsFloat64AJSONInteger(maxJSONFloat+1))
assert.False(t, IsFloat64AJSONInteger(minJSONFloat-1))
assert.True(t, IsFloat64AJSONInteger(1.0))
assert.True(t, IsFloat64AJSONInteger(maxJSONFloat))
assert.True(t, IsFloat64AJSONInteger(minJSONFloat))
}
func TestFormatBool(t *testing.T) {
assert.Equal(t, "true", FormatBool(true))
assert.Equal(t, "false", FormatBool(false))
}

View file

@ -1,579 +0,0 @@
package swag
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var testCasesStringSlice = [][]string{
{"a", "b", "c", "d", "e"},
{"a", "b", "", "", "e"},
}
func TestStringSlice(t *testing.T) {
for idx, in := range testCasesStringSlice {
if in == nil {
continue
}
out := StringSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := StringValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesStringValueSlice = [][]*string{
{String("a"), String("b"), nil, String("c")},
}
func TestStringValueSlice(t *testing.T) {
for idx, in := range testCasesStringValueSlice {
if in == nil {
continue
}
out := StringValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := StringSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesStringMap = []map[string]string{
{"a": "1", "b": "2", "c": "3"},
}
func TestStringMap(t *testing.T) {
for idx, in := range testCasesStringMap {
if in == nil {
continue
}
out := StringMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := StringValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesBoolSlice = [][]bool{
{true, true, false, false},
}
func TestBoolSlice(t *testing.T) {
for idx, in := range testCasesBoolSlice {
if in == nil {
continue
}
out := BoolSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := BoolValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesBoolValueSlice = [][]*bool{}
func TestBoolValueSlice(t *testing.T) {
for idx, in := range testCasesBoolValueSlice {
if in == nil {
continue
}
out := BoolValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := BoolSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesBoolMap = []map[string]bool{
{"a": true, "b": false, "c": true},
}
func TestBoolMap(t *testing.T) {
for idx, in := range testCasesBoolMap {
if in == nil {
continue
}
out := BoolMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := BoolValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesIntSlice = [][]int{
{1, 2, 3, 4},
}
func TestIntSlice(t *testing.T) {
for idx, in := range testCasesIntSlice {
if in == nil {
continue
}
out := IntSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := IntValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesIntValueSlice = [][]*int{}
func TestIntValueSlice(t *testing.T) {
for idx, in := range testCasesIntValueSlice {
if in == nil {
continue
}
out := IntValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := IntSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesIntMap = []map[string]int{
{"a": 3, "b": 2, "c": 1},
}
func TestIntMap(t *testing.T) {
for idx, in := range testCasesIntMap {
if in == nil {
continue
}
out := IntMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := IntValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesInt64Slice = [][]int64{
{1, 2, 3, 4},
}
func TestInt64Slice(t *testing.T) {
for idx, in := range testCasesInt64Slice {
if in == nil {
continue
}
out := Int64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Int64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesInt64ValueSlice = [][]*int64{}
func TestInt64ValueSlice(t *testing.T) {
for idx, in := range testCasesInt64ValueSlice {
if in == nil {
continue
}
out := Int64ValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := Int64Slice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesInt64Map = []map[string]int64{
{"a": 3, "b": 2, "c": 1},
}
func TestInt64Map(t *testing.T) {
for idx, in := range testCasesInt64Map {
if in == nil {
continue
}
out := Int64Map(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Int64ValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesFloat64Slice = [][]float64{
{1, 2, 3, 4},
}
func TestFloat64Slice(t *testing.T) {
for idx, in := range testCasesFloat64Slice {
if in == nil {
continue
}
out := Float64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Float64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesUintSlice = [][]uint{
{1, 2, 3, 4},
}
func TestUintSlice(t *testing.T) {
for idx, in := range testCasesUintSlice {
if in == nil {
continue
}
out := UintSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := UintValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesUintValueSlice = [][]*uint{}
func TestUintValueSlice(t *testing.T) {
for idx, in := range testCasesUintValueSlice {
if in == nil {
continue
}
out := UintValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := UintSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesUintMap = []map[string]uint{
{"a": 3, "b": 2, "c": 1},
}
func TestUintMap(t *testing.T) {
for idx, in := range testCasesUintMap {
if in == nil {
continue
}
out := UintMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := UintValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesUint64Slice = [][]uint64{
{1, 2, 3, 4},
}
func TestUint64Slice(t *testing.T) {
for idx, in := range testCasesUint64Slice {
if in == nil {
continue
}
out := Uint64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Uint64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesUint64ValueSlice = [][]*uint64{}
func TestUint64ValueSlice(t *testing.T) {
for idx, in := range testCasesUint64ValueSlice {
if in == nil {
continue
}
out := Uint64ValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := Uint64Slice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesUint64Map = []map[string]uint64{
{"a": 3, "b": 2, "c": 1},
}
func TestUint64Map(t *testing.T) {
for idx, in := range testCasesUint64Map {
if in == nil {
continue
}
out := Uint64Map(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Uint64ValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesFloat64ValueSlice = [][]*float64{}
func TestFloat64ValueSlice(t *testing.T) {
for idx, in := range testCasesFloat64ValueSlice {
if in == nil {
continue
}
out := Float64ValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := Float64Slice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesFloat64Map = []map[string]float64{
{"a": 3, "b": 2, "c": 1},
}
func TestFloat64Map(t *testing.T) {
for idx, in := range testCasesFloat64Map {
if in == nil {
continue
}
out := Float64Map(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Float64ValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesTimeSlice = [][]time.Time{
{time.Now(), time.Now().AddDate(100, 0, 0)},
}
func TestTimeSlice(t *testing.T) {
for idx, in := range testCasesTimeSlice {
if in == nil {
continue
}
out := TimeSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := TimeValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesTimeValueSlice = [][]*time.Time{}
func TestTimeValueSlice(t *testing.T) {
for idx, in := range testCasesTimeValueSlice {
if in == nil {
continue
}
out := TimeValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := TimeSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesTimeMap = []map[string]time.Time{
{"a": time.Now().AddDate(-100, 0, 0), "b": time.Now()},
}
func TestTimeMap(t *testing.T) {
for idx, in := range testCasesTimeMap {
if in == nil {
continue
}
out := TimeMap(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := TimeValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}

View file

@ -1,163 +0,0 @@
// 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 swag
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
type testNameStruct struct {
Name string `json:"name"`
NotTheSame int64 `json:"plain"`
Ignored string `json:"-"`
}
func TestNameProvider(t *testing.T) {
provider := NewNameProvider()
var obj = testNameStruct{}
nm, ok := provider.GetGoName(obj, "name")
assert.True(t, ok)
assert.Equal(t, "Name", nm)
nm, ok = provider.GetGoName(obj, "plain")
assert.True(t, ok)
assert.Equal(t, "NotTheSame", nm)
nm, ok = provider.GetGoName(obj, "doesNotExist")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetGoName(obj, "ignored")
assert.False(t, ok)
assert.Empty(t, nm)
tpe := reflect.TypeOf(obj)
nm, ok = provider.GetGoNameForType(tpe, "name")
assert.True(t, ok)
assert.Equal(t, "Name", nm)
nm, ok = provider.GetGoNameForType(tpe, "plain")
assert.True(t, ok)
assert.Equal(t, "NotTheSame", nm)
nm, ok = provider.GetGoNameForType(tpe, "doesNotExist")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetGoNameForType(tpe, "ignored")
assert.False(t, ok)
assert.Empty(t, nm)
ptr := &obj
nm, ok = provider.GetGoName(ptr, "name")
assert.True(t, ok)
assert.Equal(t, "Name", nm)
nm, ok = provider.GetGoName(ptr, "plain")
assert.True(t, ok)
assert.Equal(t, "NotTheSame", nm)
nm, ok = provider.GetGoName(ptr, "doesNotExist")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetGoName(ptr, "ignored")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetJSONName(obj, "Name")
assert.True(t, ok)
assert.Equal(t, "name", nm)
nm, ok = provider.GetJSONName(obj, "NotTheSame")
assert.True(t, ok)
assert.Equal(t, "plain", nm)
nm, ok = provider.GetJSONName(obj, "DoesNotExist")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetJSONName(obj, "Ignored")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetJSONNameForType(tpe, "Name")
assert.True(t, ok)
assert.Equal(t, "name", nm)
nm, ok = provider.GetJSONNameForType(tpe, "NotTheSame")
assert.True(t, ok)
assert.Equal(t, "plain", nm)
nm, ok = provider.GetJSONNameForType(tpe, "doesNotExist")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetJSONNameForType(tpe, "Ignored")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetJSONName(ptr, "Name")
assert.True(t, ok)
assert.Equal(t, "name", nm)
nm, ok = provider.GetJSONName(ptr, "NotTheSame")
assert.True(t, ok)
assert.Equal(t, "plain", nm)
nm, ok = provider.GetJSONName(ptr, "doesNotExist")
assert.False(t, ok)
assert.Empty(t, nm)
nm, ok = provider.GetJSONName(ptr, "Ignored")
assert.False(t, ok)
assert.Empty(t, nm)
nms := provider.GetJSONNames(ptr)
assert.Len(t, nms, 2)
assert.Len(t, provider.index, 1)
}
func TestJSONConcatenation(t *testing.T) {
assert.Nil(t, ConcatJSON())
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`)), []byte(`{"id":1}`))
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{}`)), []byte(`{}`))
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[]`)), []byte(`[]`))
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{"name":"Rachel"}`)), []byte(`{"id":1,"name":"Rachel"}`))
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[{"name":"Rachel"}]`)), []byte(`[{"id":1},{"name":"Rachel"}]`))
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{"name":"Rachel"}`)), []byte(`{"name":"Rachel"}`))
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[{"name":"Rachel"}]`)), []byte(`[{"name":"Rachel"}]`))
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{}`)), []byte(`{"id":1}`))
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[]`)), []byte(`[{"id":1}]`))
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{}`), []byte(`{}`)), []byte(`{}`))
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[]`), []byte(`[]`)), []byte(`[]`))
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{"name":"Rachel"}`), []byte(`{"age":32}`)), []byte(`{"id":1,"name":"Rachel","age":32}`))
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[{"name":"Rachel"}]`), []byte(`[{"age":32}]`)), []byte(`[{"id":1},{"name":"Rachel"},{"age":32}]`))
assert.Equal(t, ConcatJSON([]byte(`{}`), []byte(`{"name":"Rachel"}`), []byte(`{"age":32}`)), []byte(`{"name":"Rachel","age":32}`))
assert.Equal(t, ConcatJSON([]byte(`[]`), []byte(`[{"name":"Rachel"}]`), []byte(`[{"age":32}]`)), []byte(`[{"name":"Rachel"},{"age":32}]`))
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{}`), []byte(`{"age":32}`)), []byte(`{"id":1,"age":32}`))
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[]`), []byte(`[{"age":32}]`)), []byte(`[{"id":1},{"age":32}]`))
assert.Equal(t, ConcatJSON([]byte(`{"id":1}`), []byte(`{"name":"Rachel"}`), []byte(`{}`)), []byte(`{"id":1,"name":"Rachel"}`))
assert.Equal(t, ConcatJSON([]byte(`[{"id":1}]`), []byte(`[{"name":"Rachel"}]`), []byte(`[]`)), []byte(`[{"id":1},{"name":"Rachel"}]`))
}

View file

@ -1,47 +0,0 @@
// 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 swag
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadFromHTTP(t *testing.T) {
_, err := LoadFromFileOrHTTP("httx://12394:abd")
assert.Error(t, err)
serv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusNotFound)
}))
defer serv.Close()
_, err = LoadFromFileOrHTTP(serv.URL)
assert.Error(t, err)
ts2 := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusOK)
rw.Write([]byte("the content"))
}))
defer ts2.Close()
d, err := LoadFromFileOrHTTP(ts2.URL)
assert.NoError(t, err)
assert.Equal(t, []byte("the content"), d)
}

View file

@ -1,30 +0,0 @@
package swag
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSplitHostPort(t *testing.T) {
data := []struct {
Input string
Host string
Port int
Err bool
}{
{"localhost:3933", "localhost", 3933, false},
{"localhost:yellow", "", -1, true},
{"localhost", "", -1, true},
{"localhost:", "", -1, true},
{"localhost:3933", "localhost", 3933, false},
}
for _, e := range data {
h, p, err := SplitHostPort(e.Input)
if (!e.Err && assert.NoError(t, err)) || (e.Err && assert.Error(t, err)) {
assert.Equal(t, e.Host, h)
assert.Equal(t, e.Port, p)
}
}
}

View file

@ -1,118 +0,0 @@
// 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 swag
import (
"io/ioutil"
"os"
"path/filepath"
"path"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func makeDirStructure(t *testing.T, tgt string) (string, string, error) {
if tgt == "" {
tgt = "pkgpaths"
}
td, err := ioutil.TempDir("", tgt)
if err != nil {
return "", "", err
}
td2, err := ioutil.TempDir("", tgt+"-2")
if err != nil {
return "", "", err
}
realPath := filepath.Join(td, "src", "foo", "bar")
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
return "", "", err
}
linkPathBase := filepath.Join(td, "src", "baz")
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
return "", "", err
}
linkPath := filepath.Join(linkPathBase, "das")
if err := os.Symlink(realPath, linkPath); err != nil {
return "", "", err
}
realPath = filepath.Join(td2, "src", "fuu", "bir")
if err := os.MkdirAll(realPath, os.ModePerm); err != nil {
return "", "", err
}
linkPathBase = filepath.Join(td2, "src", "biz")
if err := os.MkdirAll(linkPathBase, os.ModePerm); err != nil {
return "", "", err
}
linkPath = filepath.Join(linkPathBase, "dis")
if err := os.Symlink(realPath, linkPath); err != nil {
return "", "", err
}
return td, td2, nil
}
func TestFindPackage(t *testing.T) {
pth, pth2, err := makeDirStructure(t, "")
if err != nil {
t.Fatal(err)
}
defer func() {
os.RemoveAll(pth)
os.RemoveAll(pth2)
}()
searchPath := pth + string(filepath.ListSeparator) + pth2
// finds package when real name mentioned
pkg := FindInSearchPath(searchPath, "foo/bar")
assert.NotEmpty(t, pkg)
assertPath(t, path.Join(pth, "src", "foo", "bar"), pkg)
// finds package when real name is mentioned in secondary
pkg = FindInSearchPath(searchPath, "fuu/bir")
assert.NotEmpty(t, pkg)
assertPath(t, path.Join(pth2, "src", "fuu", "bir"), pkg)
// finds package when symlinked
pkg = FindInSearchPath(searchPath, "baz/das")
assert.NotEmpty(t, pkg)
assertPath(t, path.Join(pth, "src", "foo", "bar"), pkg)
// finds package when symlinked in secondary
pkg = FindInSearchPath(searchPath, "biz/dis")
assert.NotEmpty(t, pkg)
assertPath(t, path.Join(pth2, "src", "fuu", "bir"), pkg)
// return empty string when nothing is found
pkg = FindInSearchPath(searchPath, "not/there")
assert.Empty(t, pkg)
}
func assertPath(t testing.TB, expected, actual string) bool {
fp, err := filepath.EvalSymlinks(expected)
if assert.NoError(t, err) {
return assert.Equal(t, fp, actual)
}
return true
}
func TestFullGOPATH(t *testing.T) {
os.Unsetenv(GOPATHKey)
ngp := "/some/where:/other/place"
os.Setenv(GOPATHKey, ngp)
ogp := os.Getenv(GOPATHKey)
defer os.Setenv(GOPATHKey, ogp)
expected := ngp + ":" + runtime.GOROOT()
assert.Equal(t, expected, FullGoSearchPath())
}

View file

@ -1,277 +0,0 @@
// 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 swag
import (
"fmt"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type translationSample struct {
str, out string
}
func titleize(s string) string { return strings.ToTitle(s[:1]) + lower(s[1:]) }
func TestToGoName(t *testing.T) {
samples := []translationSample{
{"sample text", "SampleText"},
{"sample-text", "SampleText"},
{"sample_text", "SampleText"},
{"sampleText", "SampleText"},
{"sample 2 Text", "Sample2Text"},
{"findThingById", "FindThingByID"},
{"日本語sample 2 Text", "X日本語sample2Text"},
{"日本語findThingById", "X日本語findThingByID"},
}
for k := range commonInitialisms {
samples = append(samples,
translationSample{"sample " + lower(k) + " text", "Sample" + k + "Text"},
translationSample{"sample-" + lower(k) + "-text", "Sample" + k + "Text"},
translationSample{"sample_" + lower(k) + "_text", "Sample" + k + "Text"},
translationSample{"sample" + titleize(k) + "Text", "Sample" + k + "Text"},
translationSample{"sample " + lower(k), "Sample" + k},
translationSample{"sample-" + lower(k), "Sample" + k},
translationSample{"sample_" + lower(k), "Sample" + k},
translationSample{"sample" + titleize(k), "Sample" + k},
translationSample{"sample " + titleize(k) + " text", "Sample" + k + "Text"},
translationSample{"sample-" + titleize(k) + "-text", "Sample" + k + "Text"},
translationSample{"sample_" + titleize(k) + "_text", "Sample" + k + "Text"},
)
}
for _, sample := range samples {
assert.Equal(t, sample.out, ToGoName(sample.str))
}
}
func TestContainsStringsCI(t *testing.T) {
list := []string{"hello", "world", "and", "such"}
assert.True(t, ContainsStringsCI(list, "hELLo"))
assert.True(t, ContainsStringsCI(list, "world"))
assert.True(t, ContainsStringsCI(list, "AND"))
assert.False(t, ContainsStringsCI(list, "nuts"))
}
func TestSplitByFormat(t *testing.T) {
expected := []string{"one", "two", "three"}
for _, fmt := range []string{"csv", "pipes", "tsv", "ssv", "multi"} {
var actual []string
switch fmt {
case "multi":
assert.Nil(t, SplitByFormat("", fmt))
assert.Nil(t, SplitByFormat("blah", fmt))
case "ssv":
actual = SplitByFormat(strings.Join(expected, " "), fmt)
assert.EqualValues(t, expected, actual)
case "pipes":
actual = SplitByFormat(strings.Join(expected, "|"), fmt)
assert.EqualValues(t, expected, actual)
case "tsv":
actual = SplitByFormat(strings.Join(expected, "\t"), fmt)
assert.EqualValues(t, expected, actual)
default:
actual = SplitByFormat(strings.Join(expected, ","), fmt)
assert.EqualValues(t, expected, actual)
}
}
}
func TestJoinByFormat(t *testing.T) {
for _, fmt := range []string{"csv", "pipes", "tsv", "ssv", "multi"} {
lval := []string{"one", "two", "three"}
var expected []string
switch fmt {
case "multi":
expected = lval
case "ssv":
expected = []string{strings.Join(lval, " ")}
case "pipes":
expected = []string{strings.Join(lval, "|")}
case "tsv":
expected = []string{strings.Join(lval, "\t")}
default:
expected = []string{strings.Join(lval, ",")}
}
assert.Nil(t, JoinByFormat(nil, fmt))
assert.EqualValues(t, expected, JoinByFormat(lval, fmt))
}
}
func TestToFileName(t *testing.T) {
samples := []translationSample{
{"SampleText", "sample_text"},
{"FindThingByID", "find_thing_by_id"},
}
for k := range commonInitialisms {
samples = append(samples,
translationSample{"Sample" + k + "Text", "sample_" + lower(k) + "_text"},
)
}
for _, sample := range samples {
assert.Equal(t, sample.out, ToFileName(sample.str))
}
}
func TestToCommandName(t *testing.T) {
samples := []translationSample{
{"SampleText", "sample-text"},
{"FindThingByID", "find-thing-by-id"},
}
for k := range commonInitialisms {
samples = append(samples,
translationSample{"Sample" + k + "Text", "sample-" + lower(k) + "-text"},
)
}
for _, sample := range samples {
assert.Equal(t, sample.out, ToCommandName(sample.str))
}
}
func TestToHumanName(t *testing.T) {
samples := []translationSample{
{"SampleText", "sample text"},
{"FindThingByID", "find thing by ID"},
}
for k := range commonInitialisms {
samples = append(samples,
translationSample{"Sample" + k + "Text", "sample " + k + " text"},
)
}
for _, sample := range samples {
assert.Equal(t, sample.out, ToHumanNameLower(sample.str))
}
}
func TestToJSONName(t *testing.T) {
samples := []translationSample{
{"SampleText", "sampleText"},
{"FindThingByID", "findThingById"},
}
for k := range commonInitialisms {
samples = append(samples,
translationSample{"Sample" + k + "Text", "sample" + titleize(k) + "Text"},
)
}
for _, sample := range samples {
assert.Equal(t, sample.out, ToJSONName(sample.str))
}
}
type SimpleZeroes struct {
ID string
Name string
}
type ZeroesWithTime struct {
Time time.Time
}
func TestIsZero(t *testing.T) {
var strs [5]string
var strss []string
var a int
var b int8
var c int16
var d int32
var e int64
var f uint
var g uint8
var h uint16
var i uint32
var j uint64
var k map[string]string
var l interface{}
var m *SimpleZeroes
var n string
var o SimpleZeroes
var p ZeroesWithTime
var q time.Time
data := []struct {
Data interface{}
Expected bool
}{
{a, true},
{b, true},
{c, true},
{d, true},
{e, true},
{f, true},
{g, true},
{h, true},
{i, true},
{j, true},
{k, true},
{l, true},
{m, true},
{n, true},
{o, true},
{p, true},
{q, true},
{strss, true},
{strs, true},
{"", true},
{nil, true},
{1, false},
{0, true},
{int8(1), false},
{int8(0), true},
{int16(1), false},
{int16(0), true},
{int32(1), false},
{int32(0), true},
{int64(1), false},
{int64(0), true},
{uint(1), false},
{uint(0), true},
{uint8(1), false},
{uint8(0), true},
{uint16(1), false},
{uint16(0), true},
{uint32(1), false},
{uint32(0), true},
{uint64(1), false},
{uint64(0), true},
{0.0, true},
{0.1, false},
{float32(0.0), true},
{float32(0.1), false},
{float64(0.0), true},
{float64(0.1), false},
{[...]string{}, true},
{[...]string{"hello"}, false},
{[]string(nil), true},
{[]string{"a"}, false},
}
for _, it := range data {
assert.Equal(t, it.Expected, IsZero(it.Data), fmt.Sprintf("%#v", it.Data))
}
}