Skip to content

Commit

Permalink
Fix typos in maximum/minimum attributes (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
parnic authored Aug 3, 2020
1 parent ec7a5ee commit e769bbe
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Besides that, `swag` also accepts aliases for some MIME Types as follows:
// @Param enumint query int false "int enums" Enums(1, 2, 3)
// @Param enumnumber query number false "int enums" Enums(1.1, 1.2, 1.3)
// @Param string query string false "string valid" minlength(5) maxlength(10)
// @Param int query int false "int valid" mininum(1) maxinum(10)
// @Param int query int false "int valid" minimum(1) maximum(10)
// @Param default query string false "string default" default(A)
// @Param collection query []string false "string collection" collectionFormat(multi)
```
Expand Down
2 changes: 1 addition & 1 deletion README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ Example [celler/controller](https://github.com/swaggo/swag/tree/master/example/c
// @Param enumint query int false "int enums" Enums(1, 2, 3)
// @Param enumnumber query number false "int enums" Enums(1.1, 1.2, 1.3)
// @Param string query string false "string valid" minlength(5) maxlength(10)
// @Param int query int false "int valid" mininum(1) maxinum(10)
// @Param int query int false "int valid" minimum(1) maximum(10)
// @Param default query string false "string default" default(A)
// @Param collection query []string false "string collection" collectionFormat(multi)
```
Expand Down
2 changes: 1 addition & 1 deletion example/celler/controller/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *Controller) SecuritiesExample(ctx *gin.Context) {
// @Param enumint query int false "int enums" Enums(1, 2, 3)
// @Param enumnumber query number false "int enums" Enums(1.1, 1.2, 1.3)
// @Param string query string false "string valid" minlength(5) maxlength(10)
// @Param int query int false "int valid" mininum(1) maxinum(10)
// @Param int query int false "int valid" minimum(1) maximum(10)
// @Param default query string false "string default" default(A)
// @Success 200 {string} string "answer"
// @Failure 400 {string} string "ok"
Expand Down
14 changes: 7 additions & 7 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
var regexAttributes = map[string]*regexp.Regexp{
// for Enums(A, B)
"enums": regexp.MustCompile(`(?i)\s+enums\(.*\)`),
// for Minimum(0)
"maxinum": regexp.MustCompile(`(?i)\s+maxinum\(.*\)`),
// for Maximum(0)
"mininum": regexp.MustCompile(`(?i)\s+mininum\(.*\)`),
// for Maximum(0)
// for maximum(0)
"maximum": regexp.MustCompile(`(?i)\s+maxinum|maximum\(.*\)`),
// for minimum(0)
"minimum": regexp.MustCompile(`(?i)\s+mininum|minimum\(.*\)`),
// for default(0)
"default": regexp.MustCompile(`(?i)\s+default\(.*\)`),
// for minlength(0)
"minlength": regexp.MustCompile(`(?i)\s+minlength\(.*\)`),
Expand All @@ -303,13 +303,13 @@ func (operation *Operation) parseAndExtractionParamAttribute(commentLine, object
if err != nil {
return err
}
case "maxinum":
case "maximum":
n, err := setNumberParam(attrKey, schemaType, attr, commentLine)
if err != nil {
return err
}
param.Maximum = &n
case "mininum":
case "minimum":
n, err := setNumberParam(attrKey, schemaType, attr, commentLine)
if err != nil {
return err
Expand Down
22 changes: 14 additions & 8 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,8 @@ func TestParseParamCommentByMinLength(t *testing.T) {
assert.Error(t, operation.ParseComment(comment, nil))
}

func TestParseParamCommentByMininum(t *testing.T) {
comment := `@Param some_id query int true "Some ID" Mininum(10)`
func TestParseParamCommentByMinimum(t *testing.T) {
comment := `@Param some_id query int true "Some ID" Minimum(10)`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)

Expand All @@ -1289,15 +1289,18 @@ func TestParseParamCommentByMininum(t *testing.T) {
}`
assert.Equal(t, expected, string(b))

comment = `@Param some_id query string true "Some ID" Mininum(10)`
comment = `@Param some_id query int true "Some ID" Mininum(10)`
assert.NoError(t, operation.ParseComment(comment, nil))

comment = `@Param some_id query string true "Some ID" Minimum(10)`
assert.Error(t, operation.ParseComment(comment, nil))

comment = `@Param some_id query integer true "Some ID" Mininum(Goopher)`
comment = `@Param some_id query integer true "Some ID" Minimum(Goopher)`
assert.Error(t, operation.ParseComment(comment, nil))
}

func TestParseParamCommentByMaxinum(t *testing.T) {
comment := `@Param some_id query int true "Some ID" Maxinum(10)`
func TestParseParamCommentByMaximum(t *testing.T) {
comment := `@Param some_id query int true "Some ID" Maximum(10)`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)

Expand All @@ -1317,10 +1320,13 @@ func TestParseParamCommentByMaxinum(t *testing.T) {
}`
assert.Equal(t, expected, string(b))

comment = `@Param some_id query string true "Some ID" Maxinum(10)`
comment = `@Param some_id query int true "Some ID" Maxinum(10)`
assert.NoError(t, operation.ParseComment(comment, nil))

comment = `@Param some_id query string true "Some ID" Maximum(10)`
assert.Error(t, operation.ParseComment(comment, nil))

comment = `@Param some_id query integer true "Some ID" Maxinum(Goopher)`
comment = `@Param some_id query integer true "Some ID" Maximum(Goopher)`
assert.Error(t, operation.ParseComment(comment, nil))

}
Expand Down
4 changes: 2 additions & 2 deletions testdata/simple/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func GetStringByInt(c *gin.Context) {
// @Produce json
// @Param some_id path string true "Some ID"
// @Param category query int true "Category" Enums(1, 2, 3)
// @Param offset query int true "Offset" Mininum(0) default(0)
// @Param limit query int true "Limit" Maxinum(50) default(10)
// @Param offset query int true "Offset" Minimum(0) default(0)
// @Param limit query int true "Limit" Maximum(50) default(10)
// @Param q query string true "q" Minlength(1) Maxlength(50) default("")
// @Success 200 {string} string "ok"
// @Failure 400 {object} web.APIError "We need ID!!"
Expand Down
4 changes: 2 additions & 2 deletions testdata/simple2/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func GetStringByInt(c *gin.Context) {
// @Produce json
// @Param some_id path string true "Some ID"
// @Param category query int true "Category" Enums(1, 2, 3)
// @Param offset query int true "Offset" Mininum(0) default(0)
// @Param limit query int true "Limit" Maxinum(50) default(10)
// @Param offset query int true "Offset" Minimum(0) default(0)
// @Param limit query int true "Limit" Maximum(50) default(10)
// @Param q query string true "q" Minlength(1) Maxlength(50) default("")
// @Success 200 {string} string "ok"
// @Failure 400 {object} web.APIError "We need ID!!"
Expand Down
4 changes: 2 additions & 2 deletions testdata/simple3/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func GetStringByInt(c *gin.Context) {
// @Produce json
// @Param some_id path string true "Some ID"
// @Param category query int true "Category" Enums(1, 2, 3)
// @Param offset query int true "Offset" Mininum(0) default(0)
// @Param limit query int true "Limit" Maxinum(50) default(10)
// @Param offset query int true "Offset" Minimum(0) default(0)
// @Param limit query int true "Limit" Maximum(50) default(10)
// @Param q query string true "q" Minlength(1) Maxlength(50) default("")
// @Success 200 {string} string "ok"
// @Failure 400 {object} web.APIError "We need ID!!"
Expand Down

0 comments on commit e769bbe

Please sign in to comment.