Skip to content

Commit 226f80f

Browse files
Add filename option for generated name
1 parent 3a96905 commit 226f80f

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+
1010
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
1111
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
1212
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
13-
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
1413
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
1514
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
1615
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -46,7 +45,6 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
4645
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
4746
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
4847
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
49-
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
5048
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
5149
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5250
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=

internal/generator/generator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Config struct {
2020
ContentType *string
2121
DefaultResponse *string
2222
Description *string
23+
Filename *string
2324
Host *string
2425
Ignore *string
2526
JSONOutput *bool
@@ -54,7 +55,7 @@ func (g *Generator) Run() error {
5455
return err
5556
}
5657

57-
filename := "openapi.yaml"
58+
filename := *g.config.Filename + ".yaml"
5859

5960
fileBuffer := bytes.Buffer{}
6061
jsonBytes, err := doc.MarshalJSON()
@@ -63,7 +64,7 @@ func (g *Generator) Run() error {
6364
}
6465

6566
if useJSON {
66-
filename = "openapi.json"
67+
filename = *g.config.Filename + ".json"
6768
fileBuffer.Write(jsonBytes)
6869
} else {
6970
// Extra hops to get JSON to YAML.

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
56
"github.com/technicallyjosh/protoc-gen-openapi/internal/generator"
67
"google.golang.org/protobuf/compiler/protogen"
78
)
@@ -13,6 +14,7 @@ func main() {
1314
ContentType: flags.String("content_type", "application/json", "Default content-type for all paths."),
1415
DefaultResponse: flags.String("default_response", "", "Default response message to use for API responses not defined."),
1516
Description: flags.String("description", "", "Description of the API."),
17+
Filename: flags.String("filename", "openapi", "Name of the file generated without the extension."),
1618
Host: flags.String("host", "", "Host to be used for all routes."),
1719
Ignore: flags.String("ignore", "", "Packages to ignore."),
1820
JSONOutput: flags.Bool("json_out", false, "Generate a JSON file instead of YAML."),

0 commit comments

Comments
 (0)