trpc.group/trpc-go/trpc-cmdline@v1.0.9/util/apidocs/openapi/gen.go (about)

     1  // Tencent is pleased to support the open source community by making tRPC available.
     2  //
     3  // Copyright (C) 2023 THL A29 Limited, a Tencent company.
     4  // All rights reserved.
     5  //
     6  // If you have downloaded a copy of the tRPC source code from Tencent,
     7  // please note that tRPC source code is licensed under the  Apache 2.0 License,
     8  // A copy of the Apache 2.0 License is included in this file.
     9  
    10  // Package openapi provides the ability to manipulate OpenAPI documents.
    11  package openapi
    12  
    13  import (
    14  	"trpc.group/trpc-go/trpc-cmdline/descriptor"
    15  	"trpc.group/trpc-go/trpc-cmdline/params"
    16  	"trpc.group/trpc-go/trpc-cmdline/util/apidocs"
    17  )
    18  
    19  // GenOpenAPI provides external structure used to generate openapi json.
    20  func GenOpenAPI(fd *descriptor.FileDescriptor, option *params.Option) error {
    21  	// Assemble the entire JSON information.
    22  	openapi, err := apidocs.NewOpenAPIJSON(fd, option)
    23  	if err != nil {
    24  		return err
    25  	}
    26  
    27  	return apidocs.WriteJSON(option.OpenAPIOut, openapi)
    28  }