mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
goctl features of 1.8.4-alpha (#4849)
This commit is contained in:
32
tools/goctl/api/swagger/definition.go
Normal file
32
tools/goctl/api/swagger/definition.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/spec"
|
||||
apiSpec "github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
||||
)
|
||||
|
||||
func definitionsFromTypes(ctx Context, types []apiSpec.Type) spec.Definitions {
|
||||
if !ctx.UseDefinitions {
|
||||
return nil
|
||||
}
|
||||
definitions := make(spec.Definitions)
|
||||
for _, tp := range types {
|
||||
typeName := tp.Name()
|
||||
definitions[typeName] = schemaFromType(ctx, tp)
|
||||
}
|
||||
return definitions
|
||||
}
|
||||
|
||||
func schemaFromType(ctx Context, tp apiSpec.Type) spec.Schema {
|
||||
p, r := propertiesFromType(ctx, tp)
|
||||
props := spec.SchemaProps{
|
||||
Type: typeFromGoType(ctx, tp),
|
||||
Properties: p,
|
||||
AdditionalProperties: mapFromGoType(ctx, tp),
|
||||
Items: itemsFromGoType(ctx, tp),
|
||||
Required: r,
|
||||
}
|
||||
return spec.Schema{
|
||||
SchemaProps: props,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user