proto

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMessages

func BuildMessages(entries []*parser.SchemaEntry, ctx *Context) (*internal.DependencyGraph, error)

BuildMessages processes all schemas and returns messages and dependency graph

func Generate

func Generate(packageName string, packagePath string, ctx *Context) ([]byte, error)

Generate creates proto3 output from messages and enums in order

func MapScalarType

func MapScalarType(ctx *Context, typ, format string) (string, error)

MapScalarType maps OpenAPI type+format to proto3 scalar type.

func ProtoType

func ProtoType(schema *base.Schema, propertyName string, propProxy *base.SchemaProxy, ctx *Context, parentMsg *ProtoMessage) (string, bool, []string, error)

ProtoType returns the proto3 type for an OpenAPI schema. Returns type name, whether it's repeated, enum values (for string enums), and error. For inline enums and objects, hoists them appropriately in the context. parentMsg is used for nested messages (can be nil for top-level).

func ResolveArrayItemType

func ResolveArrayItemType(schema *base.Schema, propertyName string, propProxy *base.SchemaProxy, ctx *Context, parentMsg *ProtoMessage) (string, []string, error)

ResolveArrayItemType determines the proto3 type for array items. Returns type name, enum values (for string enums), and error. For inline objects/enums: validates property name is not plural.

Types

type Context

type Context struct {
	Tracker       *internal.NameTracker
	Messages      []*ProtoMessage
	Enums         []*ProtoEnum
	Definitions   []interface{} // Mixed enums and messages in processing order
	FieldNumbers  *FieldNumbers // nil → positional numbering
	UsesTimestamp bool
}

Context holds state during conversion

func NewContext

func NewContext() *Context

NewContext creates a new conversion context

type EnumNumbers added in v0.10.0

type EnumNumbers struct {
	Variants map[string]int // literal enum value → proto number
	Reserved []int          // rendered as `reserved N, M;`
}

EnumNumbers pins a proto enum's variant numbers and its reserved numbers.

type FieldNumbers added in v0.10.0

type FieldNumbers struct {
	Messages map[string]MessageNumbers
	Enums    map[string]EnumNumbers
}

FieldNumbers carries an explicit, name-keyed proto field-number assignment that overrides the library's positional numbering. When a *FieldNumbers is supplied on ConvertOptions it fully drives numbering for any message or enum it has an entry for; messages/enums without an entry fall back to positional assignment.

Keys are OpenAPI-native so they join cleanly to what the builder already tracks:

  • Messages key → ProtoMessage.OriginalSchema (component schema name)
  • Fields key → ProtoField.JSONName (JSON field name)
  • Enums key → the enum's OpenAPI schema name
  • Variants key → the literal OpenAPI enum value

Limitation: only top-level component schemas are addressable. The fields of an inline nested object (an inline `type: object` property) are always numbered positionally and cannot be pinned, because an inline nested type has no globally unique key — only its property name, which is not unique across messages. Use a $ref to a named component schema for any type whose field numbers must be wire-stable across regeneration.

type MessageNumbers added in v0.10.0

type MessageNumbers struct {
	Fields   map[string]int // JSON field name → proto field number
	Reserved []int          // rendered as `reserved N, M;`
}

MessageNumbers pins a message's field numbers and the numbers retired via removal.

type ProtoEnum

type ProtoEnum struct {
	Name        string
	Description string
	Values      []*ProtoEnumValue
	Reserved    []int // proto numbers retired via removal (rendered as `reserved N, M;`)
}

ProtoEnum represents a proto3 enum definition

type ProtoEnumValue

type ProtoEnumValue struct {
	Name   string
	Number int
}

ProtoEnumValue represents an enum value

type ProtoField

type ProtoField struct {
	Name        string
	Type        string
	Number      int
	JSONName    string
	Description string
	Repeated    bool
	EnumValues  []string
}

ProtoField represents a proto3 field

type ProtoMessage

type ProtoMessage struct {
	Name           string
	Description    string
	Fields         []*ProtoField
	Nested         []*ProtoMessage
	Oneofs         []*ProtoOneof // proto3 oneof groups; members are a subset of Fields
	Reserved       []int         // proto field numbers retired via removal (rendered as `reserved N, M;`)
	OriginalSchema string        // Original schema name before name tracker renaming
}

ProtoMessage represents a proto3 message definition

type ProtoOneof added in v0.11.0

type ProtoOneof struct {
	Name   string
	Fields []*ProtoField
}

ProtoOneof represents a proto3 oneof group. Its Fields are a subset of the owning message's Fields (referenced by identity); the group never assigns or alters field numbers, it only groups already-numbered fields. The group Name is cosmetic and not wire-significant.

Jump to

Keyboard shortcuts

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