Documentation
¶
Index ¶
- Constants
- func BuildOneofFieldSet(discriminatedOneofs []*annotations.OneofDiscriminatorInfo) map[*protogen.Field]bool
- func GenerateEnumType(p Printer, enum *protogen.Enum)
- func GenerateFieldDeclaration(p Printer, field *protogen.Field)
- func GenerateFlattenedFields(p Printer, childMsg *protogen.Message, prefix string)
- func GenerateFlattenedOneofInterface(p Printer, msg *protogen.Message, name string, ...)
- func GenerateInterface(p Printer, msg *protogen.Message)
- func GenerateOneofDiscriminatedUnionType(p Printer, msgName string, info *annotations.OneofDiscriminatorInfo)
- func GenerateStandardInterface(p Printer, msg *protogen.Message, name string, ...)
- func HeaderNameToPropertyName(headerName string) string
- func IsOptionalField(field *protogen.Field) bool
- func RootUnwrapTSType(msg *protogen.Message) string
- func SnakeToLowerCamel(s string) string
- func SnakeToUpperCamel(s string) string
- func TSElementType(field *protogen.Field) string
- func TSEnumUnspecifiedValue(field *protogen.Field) string
- func TSFieldType(field *protogen.Field) string
- func TSScalarType(kind protoreflect.Kind) string
- func TSScalarTypeForField(field *protogen.Field) string
- func TSTimestampType(field *protogen.Field) string
- func TSZeroCheck(fieldKind string) string
- func TSZeroCheckForField(field *protogen.Field) string
- func WriteErrorTypes(p Printer)
- type MessageSet
- type Printer
Constants ¶
const ( TSString = "string" TSNumber = "number" TSBoolean = "boolean" )
Variables ¶
This section is empty.
Functions ¶
func BuildOneofFieldSet ¶
func BuildOneofFieldSet(discriminatedOneofs []*annotations.OneofDiscriminatorInfo) map[*protogen.Field]bool
BuildOneofFieldSet returns a set of fields that belong to discriminated oneofs.
func GenerateEnumType ¶
GenerateEnumType writes a TypeScript string union type for a protobuf enum. Uses custom enum_value annotations if present, otherwise uses proto names.
func GenerateFieldDeclaration ¶
GenerateFieldDeclaration generates a single TypeScript field declaration line.
func GenerateFlattenedFields ¶
GenerateFlattenedFields inlines child message fields at the parent level with optional prefix.
func GenerateFlattenedOneofInterface ¶
func GenerateFlattenedOneofInterface( p Printer, msg *protogen.Message, name string, discriminatedOneofs []*annotations.OneofDiscriminatorInfo, )
GenerateFlattenedOneofInterface generates a type alias with intersection for messages with flattened discriminated oneofs.
func GenerateInterface ¶
GenerateInterface writes a TypeScript interface for a protobuf message. If the message has discriminated oneofs, it generates appropriate union types.
func GenerateOneofDiscriminatedUnionType ¶
func GenerateOneofDiscriminatedUnionType(p Printer, msgName string, info *annotations.OneofDiscriminatorInfo)
GenerateOneofDiscriminatedUnionType generates a TypeScript discriminated union type for a oneof.
func GenerateStandardInterface ¶
func GenerateStandardInterface( p Printer, msg *protogen.Message, name string, discriminatedOneofs []*annotations.OneofDiscriminatorInfo, )
GenerateStandardInterface generates a standard interface, handling non-flattened discriminated oneofs as optional union properties.
func HeaderNameToPropertyName ¶
HeaderNameToPropertyName converts "X-API-Key" to "apiKey".
func IsOptionalField ¶
IsOptionalField returns true if the field should be optional in TypeScript.
func RootUnwrapTSType ¶
RootUnwrapTSType returns the TypeScript type for a root-unwrapped message.
func SnakeToLowerCamel ¶
SnakeToLowerCamel converts "user_id" to "userId".
func SnakeToUpperCamel ¶
SnakeToUpperCamel converts snake_case to UpperCamelCase.
func TSElementType ¶
TSElementType returns the TypeScript type for the element of a repeated field.
func TSEnumUnspecifiedValue ¶ added in v0.8.0
TSEnumUnspecifiedValue returns the first enum value (UNSPECIFIED variant) as a quoted string. For enum fields, this is the zero-value equivalent used in TS zero checks.
func TSFieldType ¶
TSFieldType returns the TypeScript type string for a protobuf field.
func TSScalarType ¶
func TSScalarType(kind protoreflect.Kind) string
TSScalarType returns the TypeScript type for a protobuf scalar kind. This is the base helper that uses only kind information (no field context). For int64/uint64 fields, callers should use TSScalarTypeForField to check encoding annotations.
func TSScalarTypeForField ¶
TSScalarTypeForField returns the TypeScript type for a protobuf field, checking encoding annotations for int64/uint64 fields.
func TSTimestampType ¶
TSTimestampType returns the TypeScript type for a google.protobuf.Timestamp field based on its timestamp_format annotation. UNIX_SECONDS and UNIX_MILLIS serialize as integers -> number RFC3339, DATE, and default serialize as strings -> string.
func TSZeroCheck ¶
TSZeroCheck returns the TypeScript zero-value check expression for a query param. Uses the proto field kind (not TS type) to determine the appropriate check. For int64/uint64 fields, this returns the STRING encoding check; use TSZeroCheckForField when the full field context is available to check encoding annotations.
func TSZeroCheckForField ¶
TSZeroCheckForField returns the TypeScript zero-value check expression for a field, checking encoding annotations for int64/uint64 fields.
func WriteErrorTypes ¶
func WriteErrorTypes(p Printer)
WriteErrorTypes writes the shared error types (FieldViolation, ValidationError, ApiError).
Types ¶
type MessageSet ¶
type MessageSet struct {
// contains filtered or unexported fields
}
MessageSet tracks collected messages by full name to deduplicate.
func CollectServiceMessages ¶
func CollectServiceMessages(file *protogen.File) *MessageSet
CollectServiceMessages collects all messages transitively referenced by services in a file. It also includes messages whose names end with "Error" (convention for proto-defined custom errors).
func (*MessageSet) AddEnum ¶
func (ms *MessageSet) AddEnum(enum *protogen.Enum)
AddEnum adds an enum to the collection.
func (*MessageSet) AddMessage ¶
func (ms *MessageSet) AddMessage(msg *protogen.Message)
AddMessage adds a message and recursively adds all referenced messages.
func (*MessageSet) OrderedEnums ¶
func (ms *MessageSet) OrderedEnums() []*protogen.Enum
OrderedEnums returns enums sorted by full name.
func (*MessageSet) OrderedMessages ¶
func (ms *MessageSet) OrderedMessages() []*protogen.Message
OrderedMessages returns messages in discovery order.