Skip to content

Commit

Permalink
refactor parse to support map and multi slice
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Apr 3, 2024
1 parent 35fc1f3 commit 38d9630
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 335 deletions.
48 changes: 19 additions & 29 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,28 @@ import (

// Object represents the object entity from the swagger definition
type Object struct {
IsArray bool `json:"-"`
GoType reflect.Type `json:"-"`
Name string `json:"-"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
Format string `json:"format,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]Property `json:"properties,omitempty"`
GoType reflect.Type `json:"-"`
Name string `json:"-"`
Type string `json:"type"`
Description string `json:"description,omitempty"`
Format string `json:"format,omitempty"`
Required []string `json:"required,omitempty"`
Properties map[string]Property `json:"properties,omitempty"`
AdditionalProperties *Property `json:"additionalProperties,omitempty"`
Items *Property `json:"items,omitempty"`
}

// Property represents the property entity from the swagger definition
type Property struct {
GoType reflect.Type `json:"-"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Format string `json:"format,omitempty"`
Ref string `json:"$ref,omitempty"`
Example string `json:"example,omitempty"`
Items *Items `json:"items,omitempty"`
AddPropertie *AdditionalProperties `json:"additionalProperties,omitempty"`
}

type AdditionalProperties struct {
GoType reflect.Type `json:"-"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Format string `json:"format,omitempty"`
Ref string `json:"$ref,omitempty"`
Example string `json:"example,omitempty"`
Items *Items `json:"items,omitempty"`
GoType reflect.Type `json:"-"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Format string `json:"format,omitempty"`
Ref string `json:"$ref,omitempty"`
Example string `json:"example,omitempty"`
Items *Property `json:"items,omitempty"`
AdditionalProperties *Property `json:"additionalProperties,omitempty"`
}

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

func (a *API) addDefinition(e *Endpoint) {
if a.Definitions == nil {
a.Definitions = map[string]Object{}
a.Definitions = make(map[string]Object)
}

if e.Parameters != nil {
Expand Down
9 changes: 1 addition & 8 deletions endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,10 @@ import (
"github.com/zc2638/swag/types"
)

// Items represents items from the swagger doc
type Items struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Ref string `json:"$ref,omitempty"`
}

// Schema represents a schema from the swagger doc
type Schema struct {
Type string `json:"type,omitempty"`
Items *Items `json:"items,omitempty"`
Items *Property `json:"items,omitempty"`
Ref string `json:"$ref,omitempty"`
Prototype interface{} `json:"-"`
}
Expand Down
Loading

0 comments on commit 38d9630

Please sign in to comment.