Skip to content

Commit

Permalink
support boolean false value in extension (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
HurSungYun committed Aug 17, 2021
1 parent fd74bcf commit 485f917
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -686,7 +686,7 @@ type Account struct {

```go
type Account struct {
ID string `json:"id" extensions:"x-nullable,x-abc=def"` // extensions fields must start with "x-"
ID string `json:"id" extensions:"x-nullable,x-abc=def,!x-omitempty"` // extensions fields must start with "x-"
}
```

Expand All @@ -699,7 +699,8 @@ generate swagger doc as follows:
"id": {
"type": "string",
"x-nullable": true,
"x-abc": "def"
"x-abc": "def",
"x-omitempty": false
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions README_zh-CN.md
Expand Up @@ -656,7 +656,7 @@ type Account struct {

```go
type Account struct {
ID string `json:"id" extensions:"x-nullable,x-abc=def"` // 扩展字段必须以"x-"开头
ID string `json:"id" extensions:"x-nullable,x-abc=def,!x-omitempty"` // 扩展字段必须以"x-"开头
}
```

Expand All @@ -669,7 +669,8 @@ type Account struct {
"id": {
"type": "string",
"x-nullable": true,
"x-abc": "def"
"x-abc": "def",
"x-omitempty": false
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion parser.go
Expand Up @@ -1190,7 +1190,11 @@ func (parser *Parser) parseFieldTag(field *ast.Field, types []string) (*structFi
if len(parts) == 2 {
structField.extensions[parts[0]] = parts[1]
} else {
structField.extensions[parts[0]] = true
if len(parts[0]) > 0 && string(parts[0][0]) == "!" {
structField.extensions[string(parts[0][1:])] = false
} else {
structField.extensions[parts[0]] = true
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion testdata/simple/expected.json
Expand Up @@ -600,7 +600,8 @@
"middlename": {
"type": "string",
"x-abc": "def",
"x-nullable": true
"x-nullable": true,
"x-omitempty": false
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion testdata/simple/web/handler.go
Expand Up @@ -53,7 +53,7 @@ type CrossAlias cross.Cross

type Pet2 struct {
ID int `json:"id"`
MiddleName *string `json:"middlename" extensions:"x-nullable,x-abc=def"`
MiddleName *string `json:"middlename" extensions:"x-nullable,x-abc=def,!x-omitempty"`
DeletedAt *time.Time `json:"deleted_at"`
}

Expand Down

0 comments on commit 485f917

Please sign in to comment.