Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/oapi-codegen): add flag to generate subset of code #7

Merged
merged 3 commits into from
May 13, 2019

Conversation

goller
Copy link
Contributor

@goller goller commented May 9, 2019

Hey @deepmap-marcinr , I wanted to get your feedback on how I did flags first before having the Generate code use them.

What do you think?

This adds a -generate option. It accepts, all, server, client, and types.

By default it uses all.

This is the output when an unknown option is passed:

./oapi-codegen  -generate howdy
invalid value "howdy" for flag -generate: must be "all", "server", "client", or "types"
Usage of ./oapi-codegen:
  -generate value
        The code to generate; valid options: all (default), server, client, types
  -package string
        The package name for generated code

@deepmap-marcinr
Copy link
Contributor

Does server or client imply types? For example, if I want only the server code, I would need both the types and the server, for the client, I would need the types and the client code.

Maybe -generate can take a list, like --generate=types,client? This way, you can default it to types,server,client instead of "all"?

@goller
Copy link
Contributor Author

goller commented May 9, 2019

@deepmap-marcinr Good call... I like the list. I'll make that change.

Are you ok with client/server and types being split out? Should server and client imply types?

@deepmap-marcinr
Copy link
Contributor

Hmm, that's an interesting question. Certainly, the Client and Server interfaces should be split out, and any helper functions. So, if there's a RequestParams object for an operation, it will be needed in both the client and server. You know, as a first attempt, just to make the code simpler, just generate all types together, independent of the client/server functions. They might be useful in code that operates on those types, so better to err on the side of too much than too little.

@goller
Copy link
Contributor Author

goller commented May 9, 2019

@deepmap-marcinr right on, ok

@goller
Copy link
Contributor Author

goller commented May 10, 2019

@deepmap-marcinr agreed... current code gets my go spidey-sense tingling... too complicated. I'll switch it to a straight up split for sure.

@goller goller marked this pull request as ready for review May 11, 2019 04:25
@goller
Copy link
Contributor Author

goller commented May 11, 2019

@deepmap-marcinr I've updated the CLI handling and did a small refactor of the server/client generation to use the options.

The CLI parameter is now a comma delimited set of choices.

Here is the error message with an unknown option:

./oapi-codegen -generate howdy swagger.yml
unknown generate option howdy
  -generate string
        Comma-separated list of code to generate; valid options: "client", "server"  (default client,server) (default "client,server")
  -package string
        The package name for generated code

@deepmap-marcinr
Copy link
Contributor

Thank you.

@goller goller deleted the feat/generate-flags branch May 13, 2019 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants