Import protos

How to import proto files to µSpecs or Specs #

We offer 2 different ways to import specs from proto.

  • protoc-gen-furo-specs which will generate specs
  • protoc-gen-furo-muspecs which will generate muspecs

The steps for any of these two generators are the same. This document describes the import process for *.proto to µSpecs.

 ➔  フロー µSpecs

graph TD Protoc(Proto)-- protoc-gen-furo-spec --> Spec Protoc -- protoc-gen-furo-muspec --> µSpec µSpec(µSpec) Spec(Spec) µSpec-. furo .->Spec Spec-. furo .->µSpec Spec-. furo .->Proto

Note: additional bindings are not supported at the moment

Installation #

To install the latest protoc-gen-furo-muspecs generator, just type:

1
go install github.com/eclipse/eclipsefuro/protoc-gen-furo-muspecs

Proto Config Options #

The only option you can set, is the exclude option. It will accept a regex which will not generate the matching file names.

Add the plugin to your buf config and define the output directory.

Define the buf template #

If you are not familiar with buf, read more about buf here.

1
2
3
4
version: v1beta1
plugins:
  - name: furo-muspecs
    out: dist/muspecs    

buf.protoimport.yaml

Example script to import protos from a folder #

1
2
3
4
5
#!/usr/bin/env bash
# exit when any command fails
set -e

buf generate --template ./buf.protoimport.yaml --path $(find sourceprotos/ -type d | grep sourceprotos/[^$] | tr '\n' , | sed 's/.$//')

scripts/import_proto.sh

Add the script to your flow #

If you want to use the proto files as source of truth, consider to add the import script to your flow config. And add it to your default flow.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
commands: #camelCase is not allowed, command scripts can only be executed from a flow
  gen_transcoder: "./scripts/gprcgateway/generate.sh" # shell script to generate a half grpc gateway
  buf_generate: "./scripts/buf_generate.sh"
  buf_braking: "./scripts/buf_breaking.sh"
  import_proto: "./scripts/import_proto.sh"
flows:
  default: #we choose µSpec as source https://fidl.furo.pro/docs/sourceoftruth/#%C2%B5spec-as-source
    - deprecated
    - import_proto
    - muSpec2Spec
    - checkImports
    - genMessageProtos
    - genServiceProtos
    - buf_generate

.furo

For more details, take a look in to the sample to see a complete example.