Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Oct 30, 2023
1 parent 2f5f7ec commit 0f67b3e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
45 changes: 45 additions & 0 deletions opendoc/aaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,48 @@ type License = openapi3.License
type Contact = openapi3.Contact
type Servers = openapi3.Servers
type Server = openapi3.Server

// NamedEnum returns the enumerated acceptable values with according string names.
type NamedEnum interface {
NamedEnum() ([]interface{}, []string)
}

// Enum returns the enumerated acceptable values.
type Enum interface {
Enum() []interface{}
}

// OneOfExposer exposes "oneOf" items as list of samples.
type OneOfExposer interface {
JSONSchemaOneOf() []interface{}
}

// AnyOfExposer exposes "anyOf" items as list of samples.
type AnyOfExposer interface {
JSONSchemaAnyOf() []interface{}
}

// AllOfExposer exposes "allOf" items as list of samples.
type AllOfExposer interface {
JSONSchemaAllOf() []interface{}
}

// NotExposer exposes "not" schema as a sample.
type NotExposer interface {
JSONSchemaNot() interface{}
}

// IfExposer exposes "if" schema as a sample.
type IfExposer interface {
JSONSchemaIf() interface{}
}

// ThenExposer exposes "then" schema as a sample.
type ThenExposer interface {
JSONSchemaThen() interface{}
}

// ElseExposer exposes "else" schema as a sample.
type ElseExposer interface {
JSONSchemaElse() interface{}
}
5 changes: 2 additions & 3 deletions opendoc/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ func (op *Operation) Openapi() *openapi3.PathItem {
item.Trace = operation
}

requestBody := genRequestBody(op.request, op.requestContentType...)
switch op.method {
case http.MethodPost, http.MethodPut, http.MethodPatch:
operation.RequestBody = requestBody
case http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete:
operation.RequestBody = genRequestBody(op.request, op.requestContentType...)
}

return item
Expand Down
5 changes: 5 additions & 0 deletions opendoc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type Service struct {
contentType []string
}

func (s *Service) SetName(name string) *Service {
s.name = name
return s
}

func (s *Service) AddContentType(contentType ...string) *Service {
s.contentType = append(s.contentType, contentType...)
return s
Expand Down
7 changes: 7 additions & 0 deletions opendoc/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ func (s *Swagger) ServiceOf(name string, cb func(srv *Service)) {
cb(srv)
}

func (s *Swagger) Service() *Service {
var srv = new(Service)
srv.prefix = s.rootPath
s.Routers = append(s.Routers, srv)
return srv
}

func (s *Swagger) buildSwagger() *openapi3.T {
if s.Config == nil {
s.Config = DefaultCfg()
Expand Down
15 changes: 15 additions & 0 deletions opendoc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ func genSchema(val interface{}) (ref string, schema *openapi3.Schema) {
return "", &openapi3.Schema{Type: openapi3.TypeString, Format: "uri"}
}

switch v := val.(type) {
case OneOfExposer:
var refs []*openapi3.SchemaRef
for _, s := range v.JSONSchemaOneOf() {
ref, schema := genSchema(s)
if ref != "" {
refs = append(refs, openapi3.NewSchemaRef(ref, nil))
} else {
refs = append(refs, &openapi3.SchemaRef{Value: schema})
}
}

return "", &openapi3.Schema{OneOf: refs}
}

switch model.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Uint, reflect.Uint8, reflect.Uint16:
schema = openapi3.NewIntegerSchema()
Expand Down

0 comments on commit 0f67b3e

Please sign in to comment.