Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate only for specific protos #47

Open
0xC0D3D00D opened this issue Feb 7, 2025 · 0 comments
Open

Generate only for specific protos #47

0xC0D3D00D opened this issue Feb 7, 2025 · 0 comments

Comments

@0xC0D3D00D
Copy link

0xC0D3D00D commented Feb 7, 2025

Hello!

Thank you for the great work!

I'm working on a project that only a few of the protos are used for the pubsub. I'd like to generate pubsub scheme only for those protos but it generates it also for all its imported types.

What I did is to create a separate generation template buf.pubsub.gen.yaml not to generate pubsub inlines for all the protos yet I couldn't exclude the sub types.

buf.yaml

version: v2

managed:
    enabled: true
    disable:
      - file_option: go_package
        module: buf.build/googleapis/googleapis
      - file_option: go_package
        module: buf.build/protocolbuffers/wellknowntypes
    override:
      - file_option: go_package_prefix
        value: example.com/theproject/packages/go/proto

plugins:
  - remote: buf.build/protocolbuffers/go:v1.36.4
    out: packages/go/proto
    opt: paths=source_relative
  - remote: buf.build/grpc/go:v1.5.1
    out: packages/go/proto
    opt: paths=source_relative

buf.pubsub.gen.yaml

version: v2

managed:
    enabled: true

plugins:
  - remote: buf.build/bufbuild/protoschema-pubsub
    out: gen/proto/infra/pubsub
    include_imports: false
    include_wkt: false

inputs:
  - directory: proto
    types:
      - "com.example.eventsystem.event.v1.Event"

Proto directory structure:

proto
└── org
    └── example
        └── eventsystem
            └── event
                └── v1
                    ├── event.proto
                    ├── event_data.proto
                    └── service.proto

event.proto

syntax = "proto3";

package com.example.eventsystem.event.v1;

import "com.example.eventsystem/event/v1/event_data.proto";
import "google/protobuf/timestamp.proto";

// Represents a generic event that can carry various types of event data.
message Event {
  // A unique identifier for this event.
  string id = 1;

  // The name of the event.
  string name = 2;

  // The user identifier associated with this event.
  string user_id = 3;

  // The source of the event (e.g., "web", "mobile", "system").
  string source = 4;

  // The timestamp indicating when the event was created.
  google.protobuf.Timestamp created_at = 5;

  // A oneof field containing different types of event data.
  oneof event_data {
    com.example.eventsystem.event.v1.EventDataEmpty emptyEvent = 9;
    com.example.eventsystem.event.v1.EventDataEvent1 event1 = 10;
    com.example.eventsystem.event.v1.EventDataEvent2 event2 = 11;
    com.example.eventsystem.event.v1.EventDataEvent3 event3 = 12;
    com.example.eventsystem.event.v1.EventDataEvent4 event4 = 13;
    com.example.eventsystem.event.v1.EventDataEvent5 event5 = 14;
    com.example.eventsystem.event.v1.EventDataEvent6 event6 = 15;
  }
}

event_data.proto

syntax = "proto3";

package com.example.eventsystem.event.v1;

message EventDataEmpty {}

message EventDataEvent1 {
  string field1 = 1;
}

message EventDataEvent2 {
  int32 field2 = 1;
}

message EventDataEvent3 {
  bool field3 = 1;
}

message EventDataEvent4 {
  ...
}

message EventDataEvent5 {
  ...
}

message EventDataEvent6 {
  ...
}

Generated proto:

gen
└── proto
    └── infra
        └── pubsub
            ├── com.example.eventsystem.event.v1.Event.pubsub.proto
            ├── com.example.eventsystem.event.v1.EventDataEmpty.pubsub.proto
            ├── com.example.eventsystem.event.v1.EventDataEvent1.pubsub.proto
            ├── com.example.eventsystem.event.v1.EventDataEvent2.pubsub.proto
            ├── com.example.eventsystem.event.v1.EventDataEvent3.pubsub.proto
            ├── com.example.eventsystem.event.v1.EventDataEvent4.pubsub.proto
            ├── com.example.eventsystem.event.v1.EventDataEvent5.pubsub.proto
            └── com.example.eventsystem.event.v1.EventDataEvent6.pubsub.proto

From these I only need com.example.eventsystem.event.v1.Event.pubsub.proto, Is it possible to only generate this one?

@0xC0D3D00D 0xC0D3D00D changed the title Generate only specific protos Generate only for specific protos Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant