Skip to content

Commit 9b1f0c8

Browse files
authored
support map and multi slice (#43)
1 parent 35fc1f3 commit 9b1f0c8

13 files changed

+311
-428
lines changed

README.md

+1-24
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,7 @@ Golang 1.16+
2121
## Installation
2222

2323
```shell
24-
go get -u github.com/zc2638/[email protected]
25-
```
26-
27-
## Use note:
28-
The time.time type uses jsonTag to parse it into a string type
29-
```go
30-
type XXX struct{
31-
Now time.Time `json:",string"`
32-
}
33-
```
34-
35-
The compatibility is resolved as follows:
36-
```go
37-
type xxx struct {
38-
MapSlicePtr map[string][]*string
39-
MapSlice map[string][]string
40-
MapSliceStructPtr map[string][]*Person
41-
MapSliceStruct map[string][]Person
42-
SliceStructPtr *[]*Person
43-
SliceStruct *[]Person
44-
SliceStringPtr *[]*string
45-
SliceString *[]string
46-
}
47-
24+
go get -u github.com/zc2638/[email protected]
4825
```
4926

5027
**Tip:** As of `v1.2.0`, lower versions are no longer compatible. In order to be compatible with most web frameworks,

README_zh.md

+1-24
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,7 @@ Golang 1.16+
2121
## 安装
2222

2323
```shell
24-
go get -u github.com/zc2638/[email protected]
25-
```
26-
27-
## 使用注意:
28-
time.time类型使用jsonTag来将其解析为string类型
29-
```go
30-
type XXX struct{
31-
Now time.Time `json:",string"`
32-
}
33-
```
34-
35-
兼容的解析如下:
36-
```go
37-
type xxx struct {
38-
MapSlicePtr map[string][]*string
39-
MapSlice map[string][]string
40-
MapSliceStructPtr map[string][]*Person
41-
MapSliceStruct map[string][]Person
42-
SliceStructPtr *[]*Person
43-
SliceStruct *[]Person
44-
SliceStringPtr *[]*string
45-
SliceString *[]string
46-
}
47-
24+
go get -u github.com/zc2638/[email protected]
4825
```
4926

5027
**Tip:**`v1.2.0` 开始,低版本不再兼容。为了兼容大部分的web框架,整体架构做了很大的改动。

api.go

+18-29
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,27 @@ import (
2929

3030
// Object represents the object entity from the swagger definition
3131
type Object struct {
32-
IsArray bool `json:"-"`
33-
GoType reflect.Type `json:"-"`
34-
Name string `json:"-"`
35-
Type string `json:"type"`
36-
Description string `json:"description,omitempty"`
37-
Format string `json:"format,omitempty"`
38-
Required []string `json:"required,omitempty"`
39-
Properties map[string]Property `json:"properties,omitempty"`
32+
Name string `json:"-"`
33+
Type string `json:"type"`
34+
Description string `json:"description,omitempty"`
35+
Format string `json:"format,omitempty"`
36+
Required []string `json:"required,omitempty"`
37+
Properties map[string]Property `json:"properties,omitempty"`
38+
AdditionalProperties *Property `json:"additionalProperties,omitempty"`
39+
Items *Property `json:"items,omitempty"`
4040
}
4141

4242
// Property represents the property entity from the swagger definition
4343
type Property struct {
44-
GoType reflect.Type `json:"-"`
45-
Type string `json:"type,omitempty"`
46-
Description string `json:"description,omitempty"`
47-
Enum []string `json:"enum,omitempty"`
48-
Format string `json:"format,omitempty"`
49-
Ref string `json:"$ref,omitempty"`
50-
Example string `json:"example,omitempty"`
51-
Items *Items `json:"items,omitempty"`
52-
AddPropertie *AdditionalProperties `json:"additionalProperties,omitempty"`
53-
}
54-
55-
type AdditionalProperties struct {
56-
GoType reflect.Type `json:"-"`
57-
Type string `json:"type,omitempty"`
58-
Description string `json:"description,omitempty"`
59-
Enum []string `json:"enum,omitempty"`
60-
Format string `json:"format,omitempty"`
61-
Ref string `json:"$ref,omitempty"`
62-
Example string `json:"example,omitempty"`
63-
Items *Items `json:"items,omitempty"`
44+
GoType reflect.Type `json:"-"`
45+
Type string `json:"type,omitempty"`
46+
Description string `json:"description,omitempty"`
47+
Enum []string `json:"enum,omitempty"`
48+
Format string `json:"format,omitempty"`
49+
Ref string `json:"$ref,omitempty"`
50+
Example string `json:"example,omitempty"`
51+
Items *Property `json:"items,omitempty"`
52+
AdditionalProperties *Property `json:"additionalProperties,omitempty"`
6453
}
6554

6655
// Contact represents the contact entity from the swagger definition; used by Info
@@ -252,7 +241,7 @@ func (a *API) addPath(e *Endpoint) {
252241

253242
func (a *API) addDefinition(e *Endpoint) {
254243
if a.Definitions == nil {
255-
a.Definitions = map[string]Object{}
244+
a.Definitions = make(map[string]Object)
256245
}
257246

258247
if e.Parameters != nil {

endpoint.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ import (
2121
"github.com/zc2638/swag/types"
2222
)
2323

24-
// Items represents items from the swagger doc
25-
type Items struct {
26-
Type string `json:"type,omitempty"`
27-
Format string `json:"format,omitempty"`
28-
Ref string `json:"$ref,omitempty"`
29-
}
30-
3124
// Schema represents a schema from the swagger doc
3225
type Schema struct {
33-
Type string `json:"type,omitempty"`
34-
Items *Items `json:"items,omitempty"`
26+
Items *Property `json:"items,omitempty"`
3527
Ref string `json:"$ref,omitempty"`
3628
Prototype interface{} `json:"-"`
3729
}

0 commit comments

Comments
 (0)