gen

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package gen for generate OpenAPI specification from proto.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase[S ~string](s S) string

CamelCase was copied from https://github.com/golang/protobuf/blob/v1.5.2/protoc-gen-go/generator/generator.go#L2648 CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.

func Capitalize

func Capitalize(s string) string

Capitalize converts first character to upper.

If the string is invalid UTF-8 or empty, it is returned as is.

func LowerCamelCase

func LowerCamelCase[S ~string](s S) string

LowerCamelCase returns the lowerCamelCased name.

func Uncapitalize added in v0.2.0

func Uncapitalize(s string) string

Uncapitalize converts first character to lower.

If the string is invalid UTF-8 or empty, it is returned as is.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator instance.

func NewGenerator

func NewGenerator(files []*protogen.File, opts ...GeneratorOption) (*Generator, error)

NewGenerator returns new Generator instance.

func (*Generator) JSON

func (g *Generator) JSON() ([]byte, error)

JSON returns OpenAPI specification bytes.

func (*Generator) YAML

func (g *Generator) YAML() ([]byte, error)

YAML returns OpenAPI specification bytes.

type GeneratorOption

type GeneratorOption func(g *Generator)

GeneratorOption is option for Generator.

func WithIndent

func WithIndent(indent int) GeneratorOption

WithIndent sets indent.

func WithSpecInfoDescription

func WithSpecInfoDescription(description string) GeneratorOption

WithSpecInfoDescription sets description.

func WithSpecInfoTitle

func WithSpecInfoTitle(title string) GeneratorOption

WithSpecInfoTitle sets title.

func WithSpecInfoVersion

func WithSpecInfoVersion(version string) GeneratorOption

WithSpecInfoVersion sets version.

func WithSpecOpenAPI

func WithSpecOpenAPI(openapi string) GeneratorOption

WithSpecOpenAPI sets openapi.

type HTTPRule

type HTTPRule struct {
	Path         string
	Method       string
	Body         string
	ResponseBody string
	Additional   bool
}

HTTPRule is a parsed HTTP rule annotation.

type InvalidPathTemplateError

type InvalidPathTemplateError struct {
	// Msg is error message.
	Msg string
	// At is byte position.
	At int
}

InvalidPathTemplateError is a path template parsing error.

func (*InvalidPathTemplateError) Error

func (e *InvalidPathTemplateError) Error() string

Error implements error.

type PathSegment

type PathSegment struct {
	Raw   string
	Param string
}

PathSegment is a OpenAPI path segment.

func (PathSegment) IsParam

func (p PathSegment) IsParam() bool

IsParam whether is segment defines a path parameter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL