Skip to content

Commit

Permalink
remove gopkg (#25)
Browse files Browse the repository at this point in the history
remove gopkg
  • Loading branch information
zc2638 authored Feb 8, 2023
1 parent 9e291c0 commit d216a5e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 839 deletions.
8 changes: 5 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ package swag

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"path"
"reflect"
"strings"

"github.com/99nil/gopkg/ctr"

"github.com/zc2638/swag/asserts"
)

Expand Down Expand Up @@ -365,7 +364,10 @@ func (a *API) Handler() http.HandlerFunc {
doc := a.Clone()
doc.Host = req.Host
doc.Schemes = []string{scheme}
ctr.OK(w, doc)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(doc)
}
}

Expand Down
17 changes: 10 additions & 7 deletions endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ import (
"strconv"
"strings"

"github.com/99nil/gopkg/sets"

"github.com/zc2638/swag/types"

"github.com/zc2638/swag"
"github.com/zc2638/swag/types"
)

// New constructs a new swagger endpoint using the fields and functional options provided
Expand Down Expand Up @@ -183,9 +180,15 @@ func FormData(name string, typ types.ParameterType, description string, required
return func(e *swag.Endpoint) {
parameter(p)(e)

s := sets.NewString(e.Consumes...)
s.Add("multipart/form-data")
e.Consumes = s.List()
list := make([]string, 0, len(e.Consumes)+1)
for _, v := range e.Consumes {
if v == "multipart/form-data" {
continue
}
list = append(list, v)
}
list = append(list, "multipart/form-data")
e.Consumes = list
}
}

Expand Down
11 changes: 10 additions & 1 deletion endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,23 @@ func TestFormData(t *testing.T) {
Required: true,
Type: types.File,
}
expected2 := swag.Parameter{
In: "formData",
Name: "file2",
Description: "the description2",
Required: true,
Type: types.File,
}

e := New("post", "/",
Summary("upload file"),
FormData(expected.Name, types.File, expected.Description, expected.Required),
FormData(expected2.Name, types.File, expected2.Description, expected2.Required),
)

assert.Equal(t, 1, len(e.Parameters))
assert.Equal(t, 2, len(e.Parameters))
assert.Equal(t, expected, e.Parameters[0])
assert.Equal(t, expected2, e.Parameters[1])
}

type Model struct {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module github.com/zc2638/swag
go 1.16

require (
github.com/99nil/gopkg v0.0.0-20220607055250-e19b23d7661a
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/modern-go/reflect2 v1.0.2
github.com/stretchr/testify v1.7.1
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

retract v0.1.0
Expand Down
Loading

0 comments on commit d216a5e

Please sign in to comment.