Protocol Buffers/Protobuf Option

Protocol Buffers

Protocol Buffers Option

Current ApiHug protobuf extension registrations and where each option applies.

ApiHug uses protobuf custom options as its contract layer. The important part is the actual extension registrations shipped in it-proto-extend, not generic examples from other protobuf ecosystems.

Descriptor Targets

Custom options are attached to protobuf descriptor types:

  • google.protobuf.FileOptions
  • google.protobuf.ServiceOptions
  • google.protobuf.MethodOptions
  • google.protobuf.MessageOptions
  • google.protobuf.FieldOptions
  • google.protobuf.EnumOptions
  • google.protobuf.EnumValueOptions

The same field number can be reused on different descriptor types. That is why several ApiHug extensions share 1042 or 31143 without conflicting.

Current Extension Packages

OpenAPI / Swagger

Import:

Proto
import "apihug/protobuf/swagger/annotations.proto";

Registered in swagger/annotations.proto:

DescriptorExtension pointField numberPayload type
MethodOptions(hope.swagger.operation)1042Operation
MessageOptions(hope.swagger.schema)1042Schema
ServiceOptions(hope.swagger.svc)1044ServiceSchema
FieldOptions(hope.swagger.field)1042JSONSchema
EnumOptions(hope.swagger.enm)1042JSONSchema

Use these when defining HTTP paths, request and response metadata, validation rules, enum display metadata, and mock data.

Persistence / Entity

Import:

Proto
import "apihug/protobuf/domain/annotations.proto";

Registered in domain/annotations.proto:

DescriptorExtension pointField numberPayload type
MessageOptions(hope.persistence.table)1772Table
FieldOptions(hope.persistence.column)1773Column

Use these when mapping domain messages to database tables, columns, views, and Liquibase customization.

Enum / Error Metadata

Import:

Proto
import "apihug/protobuf/extend/constant.proto";

Registered in constant.proto:

DescriptorExtension pointField numberPayload type
EnumValueOptions(hope.constant.field)37020Meta

Use this for business codes, localized labels, and structured error metadata on enum values.

Version Tracking

Import:

Proto
import "apihug/protobuf/extend/version.proto";

version.proto is deprecated, but it still exists in the source and should be understood when auditing older projects.

DescriptorExtension pointField numberPayload type
FileOptions(hope.version.file)31142repeated Version
MethodOptions(hope.version.method)31142repeated Version
MessageOptions(hope.version.msg)31143repeated Version
ServiceOptions(hope.version.svc)31143repeated Version
EnumOptions(hope.version.enm)31143repeated Version
FieldOptions(hope.version.field)31143repeated Version

Minimal Example

Proto
syntax = "proto3";
package com.example.pet;

import "apihug/protobuf/swagger/annotations.proto";
import "apihug/protobuf/domain/annotations.proto";
import "apihug/protobuf/extend/constant.proto";

service PetApi {
  option (hope.swagger.svc) = {
    path: "/pets";
    description: "Pet API";
  };

  rpc ListPets (PetQuery) returns (PetView) {
    option (hope.swagger.operation) = {
      get: "";
      description: "List pets";
    };
  }
}

message Pet {
  option (hope.persistence.table) = {
    name: "PET";
    description: "Pet table";
  };

  string name = 1 [(hope.persistence.column) = {
    name: "NAME";
    nullable: false;
    length: 64;
  }];
}

enum PetStatus {
  PET_STATUS_UNSPECIFIED = 0 [(hope.constant.field) = {
    code: 0;
    message: "unspecified";
    message2: "unspecified";
  }];
}

See Also

  1. API Directive Specification
  2. Database Directive Specification
  3. Enum Type Specification
  4. Version Change Specification
Copyright © 2026 ApiHug·AI-native Enterprise Architecture Factory