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: Add an example of generating openapi spec using tools pattern #409

Conversation

hiddenmarten
Copy link
Contributor

Hello everyone!

I'm new to the community, and I couldn't find an easy way to generate an OpenAPI spec during the build process. So, I came up with a straightforward solution that might be useful to others.

P.S. I use the generated OpenAPI spec to create clients for testing purposes.

P.P.S. If there is a way to generate it using cli or smth like that, I would be very happy. :)

@EwenQuim
Copy link
Member

Hi @hiddenmarten ! Thanks for this PR 🎉 That will be really useful for future developers.

I get what you're trying to show but i think there are other solutions than what you proposed. Here are 2 ways I'll do that:

Solution 1

From inside with environment variables. This might feel a bit like "side-effects" but it works well.

image

Solution 2

Via different Engine options in each case.

image
  • in main.go to run the server without spec:
image
  • in genspec.go to generate the spec without running the server:
image

@hiddenmarten
Copy link
Contributor Author

hiddenmarten commented Feb 19, 2025

Hi, @EwenQuim!

Thanks for the rapid answer!

Your solutions (especially the second one) seem to be more suitable at first glance. I'll try it a bit later, really appreciate your help.

@EwenQuim
Copy link
Member

I'll love it if you can change your PR so the best of these solution are available to the general public :)

@hiddenmarten
Copy link
Contributor Author

hiddenmarten commented Feb 19, 2025

I've updated the example.

I implemented it slightly differently than what was suggested, but I believe it still conveys the same idea. I intentionally left GetServer() without any parameters because I consider it a "central" configuration that should remain unchanged once set up. I believe the current implementation is a bit more straightforward, which can be particularly helpful for newcomers.

If this topic is really important to you, I'll modify it to match your proposed solution as closely as possible.

@EwenQuim
Copy link
Member

Really good idea, thank you!

@EwenQuim EwenQuim merged commit 276e81b into go-fuego:main Feb 20, 2025
5 checks passed
@EwenQuim
Copy link
Member

Thanks for your contribution 🎉

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.

2 participants