|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
"context"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
//"git.ikuban.com/server/swagger-api/protoc-gen-openapiv2/generator"
|
|
//"git.ikuban.com/server/swagger-api/protoc-gen-openapiv2/generator"
|
|
|
|
|
+ generatorJson "git.ikuban.com/server/gnostic/protoc-gen-jsonschema/generator"
|
|
|
"git.ikuban.com/server/gnostic/protoc-gen-openapi/generator"
|
|
"git.ikuban.com/server/gnostic/protoc-gen-openapi/generator"
|
|
|
"github.com/go-kratos/kratos/v2/api/metadata"
|
|
"github.com/go-kratos/kratos/v2/api/metadata"
|
|
|
"github.com/xmkuban/utils/utils"
|
|
"github.com/xmkuban/utils/utils"
|
|
@@ -15,14 +16,18 @@ import (
|
|
|
|
|
|
|
|
// Service is service
|
|
// Service is service
|
|
|
type Service struct {
|
|
type Service struct {
|
|
|
- ser *metadata.Server
|
|
|
|
|
- serviceInfoMap map[string]grpc.ServiceInfo
|
|
|
|
|
|
|
+ ser *metadata.Server
|
|
|
|
|
+ outType string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// New service
|
|
// New service
|
|
|
-func New(srv *grpc.Server) *Service {
|
|
|
|
|
|
|
+func New(srv *grpc.Server, outType string) *Service {
|
|
|
|
|
+ if outType == "" {
|
|
|
|
|
+ outType = "yaml"
|
|
|
|
|
+ }
|
|
|
return &Service{
|
|
return &Service{
|
|
|
- ser: metadata.NewServer(srv),
|
|
|
|
|
|
|
+ ser: metadata.NewServer(srv),
|
|
|
|
|
+ outType: outType,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -68,18 +73,31 @@ func (s *Service) GetServiceOpenAPI(ctx context.Context, in *metadata.GetService
|
|
|
return "", err
|
|
return "", err
|
|
|
}
|
|
}
|
|
|
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
|
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
|
|
- gen := generator.NewOpenAPIv3Generator(plugin, generator.Configuration{
|
|
|
|
|
- Version: utils.ToPointString("1.0"),
|
|
|
|
|
- Title: utils.ToPointString(""),
|
|
|
|
|
- Description: utils.ToPointString(""),
|
|
|
|
|
- Naming: utils.ToPointString("json"),
|
|
|
|
|
- FQSchemaNaming: utils.ToPointBool(true),
|
|
|
|
|
- EnumType: utils.ToPointString("integer"),
|
|
|
|
|
- CircularDepth: utils.ToPointInt(2),
|
|
|
|
|
- DefaultResponse: utils.ToPointBool(false),
|
|
|
|
|
- OutputMode: utils.ToPointString("merged"),
|
|
|
|
|
- }, plugin.Files)
|
|
|
|
|
- content, err := gen.RunV2()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var content []byte
|
|
|
|
|
+ if s.outType == "yaml" {
|
|
|
|
|
+ gen := generator.NewOpenAPIv3Generator(plugin, generator.Configuration{
|
|
|
|
|
+ Version: utils.ToPointString("1.0"),
|
|
|
|
|
+ Title: utils.ToPointString(""),
|
|
|
|
|
+ Description: utils.ToPointString(""),
|
|
|
|
|
+ Naming: utils.ToPointString("json"),
|
|
|
|
|
+ FQSchemaNaming: utils.ToPointBool(true),
|
|
|
|
|
+ EnumType: utils.ToPointString("integer"),
|
|
|
|
|
+ CircularDepth: utils.ToPointInt(2),
|
|
|
|
|
+ DefaultResponse: utils.ToPointBool(false),
|
|
|
|
|
+ OutputMode: utils.ToPointString("merged"),
|
|
|
|
|
+ }, plugin.Files)
|
|
|
|
|
+ content, err = gen.RunV2()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ gen := generatorJson.NewJSONSchemaGenerator(plugin, generatorJson.Configuration{
|
|
|
|
|
+ BaseURL: utils.ToPointString(""),
|
|
|
|
|
+ Version: utils.ToPointString("1.0"),
|
|
|
|
|
+ Naming: utils.ToPointString("json"),
|
|
|
|
|
+ EnumType: utils.ToPointString("integer"),
|
|
|
|
|
+ })
|
|
|
|
|
+ content, err = gen.RunV2()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return "", err
|
|
return "", err
|
|
|
}
|
|
}
|