|
@@ -3,12 +3,10 @@ package swagger_api
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- //"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"
|
|
|
- "google.golang.org/grpc"
|
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
|
"google.golang.org/protobuf/types/descriptorpb"
|
|
"google.golang.org/protobuf/types/descriptorpb"
|
|
|
"google.golang.org/protobuf/types/pluginpb"
|
|
"google.golang.org/protobuf/types/pluginpb"
|
|
@@ -16,18 +14,14 @@ import (
|
|
|
|
|
|
|
|
// Service is service
|
|
// Service is service
|
|
|
type Service struct {
|
|
type Service struct {
|
|
|
- ser *metadata.Server
|
|
|
|
|
- outType string
|
|
|
|
|
|
|
+ ser *metadata.Server
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// New service
|
|
// New service
|
|
|
-func New(srv *grpc.Server, outType string) *Service {
|
|
|
|
|
- if outType == "" {
|
|
|
|
|
- outType = "yaml"
|
|
|
|
|
- }
|
|
|
|
|
|
|
+func New() *Service {
|
|
|
|
|
+
|
|
|
return &Service{
|
|
return &Service{
|
|
|
- ser: metadata.NewServer(srv),
|
|
|
|
|
- outType: outType,
|
|
|
|
|
|
|
+ ser: metadata.NewServer(nil),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -75,28 +69,18 @@ func (s *Service) GetServiceOpenAPI(ctx context.Context, in *metadata.GetService
|
|
|
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
|
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
|
|
|
|
|
|
|
|
var content []byte
|
|
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()
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 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()
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return "", err
|
|
return "", err
|