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

fix(openapi): remove spec file generation from live code path #1290

Merged
merged 2 commits into from
Mar 23, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Mar 23, 2022

Summary

This PR removes the openapi spec generation from the production CLI and removes the possibility that it could run when the server starts. We continue to run the spec generation in tests, and it can be run manually from the makefile.

More comments inline.

Related Issues

Builds on #1270, and #1207

Comment on lines -3324 to -3328
"example": "email@example.com",
"in": "query",
"name": "email",
"schema": {
"example": "email@example.com",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised to see these changes, but running the test on main showed the same changes.

I guess that the API definitions changed in another PR that was merged at the same time as the openapi spec generation changes.

Comment on lines -13 to -19
wd, err := os.Getwd()
require.NoError(t, err)

parts := strings.Split(wd, string(os.PathSeparator))

if parts[len(parts)-1] != "infra" {
err := os.Chdir("../..")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go test always runs tests with the package directory as the working directory. So we can use a specific path instead of a conditional.

@@ -92,8 +92,6 @@ func (a *API) registerRoutes(router *gin.RouterGroup) {

get(unauthorized, "/version", a.Version)
}

generateOpenAPI()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the main goal of this PR, to remove this from the production code path.

s.GenerateRoutes()

filename := "../../docs/api/openapi3.json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't assume the test will always run from this directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment, you can! (although I can't find a good docs link right now, I'll keep looking)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm mistaken. I tested different run methods and couldn't find a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where it is documented, but I've always seen it work this way. Somewhere in go test it checked to the directory for the package before running the test binary.

@@ -3321,11 +3321,9 @@
"operationId": "ListUsers",
"parameters": [
{
"example": "email@example.com",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is weird. should not have changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below :)

It happens on main as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this and you are correct, it was removed in main and not regenerated

Copy link
Contributor Author

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry my comments took a while to post because of the github outage. But they respond to the two comments you left.

@@ -3321,11 +3321,9 @@
"operationId": "ListUsers",
"parameters": [
{
"example": "email@example.com",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below :)

It happens on main as well.

s.GenerateRoutes()

filename := "../../docs/api/openapi3.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment, you can! (although I can't find a good docs link right now, I'll keep looking)

@dnephin dnephin force-pushed the dnephin/openapi-spec-gen branch 2 times, most recently from 846e1a0 to e6ade05 Compare March 23, 2022 17:38
Previously it could have run if the binary was run from any directory
which contains a `docs` or `.git` directory.
Generating the openapi spec is a developer operation, not an end-user
operation. This PR removes the sub-command from the CLI and adds a new
internal/openapigen command. This matches the pattern we use for
generating the user documentation (internal/docsgen).
@dnephin dnephin merged commit e625e53 into main Mar 23, 2022
@dnephin dnephin deleted the dnephin/openapi-spec-gen branch March 23, 2022 19:08
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