discord-gophers/goapi-gen

Read file input from stdin

Karitham opened this issue · 1 comments

Why

Reading from stdin is very common in command lines tool, because it is much more versatile, and makes chaining a whole lot easier.

Example

I have multiple repos that depend of the same open-api spec file, one where I'm generating the client, and the other where I'm generating the server.

Having the ability to pipe the file directly from the repo it is contained in, rather than having to maintain 2 separate versions would be appreciable.

The command would also be much clearer. For this use case we switch from

curl -o petstore-expanded.yaml https://raw.githubusercontent.com/discord-gophers/goapi-gen/master/examples/petstore-expanded/petstore-expanded.yaml
goapi-gen petstore-expanded.yaml  > petstore.gen.go

To

curl https://raw.githubusercontent.com/discord-gophers/goapi-gen/master/examples/petstore-expanded/petstore-expanded.yaml | goapi-gen - > petstore.gen.go

This also brings better maintainability, since we would re-generate the interfaces every time the remote file changes.

Other use cases

This also gives us the ability to chain that with other tools, for example to combine multiple spec files into one, which would essentially fix deepmap/oapi-codegen#400.

Taken care of by #32