mirror of
https://github.com/arkadiyt/protodump.git
synced 2026-10-21 09:46:52 +02:00
Merge pull request #4 from arkadiyt/atetelman--defaults
Add support for proto2 default values
This commit is contained in:
5 files changed
+35
-6
No files matched your search
@@ -6,13 +6,13 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: '1.20'
|
||||||
- name: Install Protoc
|
- name: Install Protoc
|
||||||
run: |
|
run: |
|
||||||
sudo apt install -y protobuf-compiler
|
sudo apt install -y protobuf-compiler
|
||||||
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
|
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test
|
run: make test
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
syntax = "proto2";
|
||||||
|
|
||||||
|
package hello.world;
|
||||||
|
|
||||||
|
option go_package = "./;helloworld";
|
||||||
|
|
||||||
|
message SearchRequest {
|
||||||
|
optional string query = 1 [default = "hello"];
|
||||||
|
optional int32 page_number = 2;
|
||||||
|
optional int32 result_per_page = 3 [default = 10];
|
||||||
|
optional .hello.world.Corpus corpus = 4 [default = CORPUS_UNIVERSAL];
|
||||||
|
optional bool field = 5 [default = true];
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Corpus {
|
||||||
|
CORPUS_UNSPECIFIED = 0;
|
||||||
|
CORPUS_UNIVERSAL = 1;
|
||||||
|
}
|
||||||
|
|
||||||
File renamed without changes.
@@ -135,6 +135,19 @@ func (pd *ProtoDefinition) writeField(field protoreflect.FieldDescriptor) {
|
|||||||
pd.write(string(field.Name()))
|
pd.write(string(field.Name()))
|
||||||
pd.write(" = ")
|
pd.write(" = ")
|
||||||
pd.write(strconv.Itoa(int(field.Number())))
|
pd.write(strconv.Itoa(int(field.Number())))
|
||||||
|
if field.HasDefault() {
|
||||||
|
pd.write(" [default = ")
|
||||||
|
kind := field.Kind().String()
|
||||||
|
if kind == "string" {
|
||||||
|
pd.write(fmt.Sprintf("\"%s\"", field.Default().String()))
|
||||||
|
} else if kind == "enum" {
|
||||||
|
pd.write(string(field.Enum().Values().ByNumber(field.Default().Enum()).Name()))
|
||||||
|
} else {
|
||||||
|
pd.write(field.Default().String())
|
||||||
|
}
|
||||||
|
|
||||||
|
pd.write("]")
|
||||||
|
}
|
||||||
pd.write(";\n")
|
pd.write(";\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -15,8 +14,6 @@ import (
|
|||||||
|
|
||||||
const FIXTURES = "fixtures"
|
const FIXTURES = "fixtures"
|
||||||
|
|
||||||
var regex = regexp.MustCompile("(?m)var .* = \\[\\]byte{([^}]*)}")
|
|
||||||
|
|
||||||
func convertProtoToFileDescriptor(filePath string) (*descriptorpb.FileDescriptorProto, error) {
|
func convertProtoToFileDescriptor(filePath string) (*descriptorpb.FileDescriptorProto, error) {
|
||||||
dir, err := os.MkdirTemp("", "")
|
dir, err := os.MkdirTemp("", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user