protoc-gen-go-json icon indicating copy to clipboard operation
protoc-gen-go-json copied to clipboard

Maintain comments for licenses and build tags

Open ItalyPaleAle opened this issue 5 years ago • 1 comments

On generated .pb.go files, comments at the beginning of the .proto file are preserved. For example, assume a .proto file that started with:

/*
Copyright © 2020 Alessandro Segala (@ItalyPaleAle)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

// +build linux

syntax = "proto3";

package foo;

// < rest of file >

When compiling it and using the json plugin, I get two files.

The .pb.go file preserves the comments, so it starts with:

//
//Copyright © 2020 Alessandro Segala (@ItalyPaleAle)
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published
//by the Free Software Foundation, version 3 of the License.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Affero General Public License for more details.
//
//You should have received a copy of the GNU Affero General Public License
//along with this program.  If not, see <https://www.gnu.org/licenses/>.

// +build linux

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.25.0-devel
// 	protoc        v3.13.0
// source: foo.proto

package foo

// < rest of file >

However the .pb.json.go file starts with this only:

// Code generated by protoc-gen-go-json. DO NOT EDIT.
// source: foo.proto

package foo

// < rest of file >

As you can see, there are two important things missing:

  1. The license
  2. Optional build tags such as // +build linux

ItalyPaleAle avatar Oct 30 '20 04:10 ItalyPaleAle

Better late than never, but I ended up fixing this in https://github.com/mfridman/protoc-gen-go-json/pull/3.

mfridman avatar Mar 16 '24 19:03 mfridman