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

Refactor/set openapi server url #272

Closed
wants to merge 2 commits into from

Conversation

dylanhitt
Copy link
Collaborator

closes #248

Will conflict with #245 but it does solve the issue of creating the server too early so that code could be simplified I believe. This also adds native option to configure the openapi.Description() server.

Thanks

@dylanhitt dylanhitt force-pushed the refactor/set-openapi-serverURL branch 2 times, most recently from 9a126be to f03071d Compare December 13, 2024 20:22
Copy link
Member

@EwenQuim EwenQuim left a comment

Choose a reason for hiding this comment

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

Thank you very much! I'm suggesting a much more simple PR by not taking care of Server in the config but keeping the late initialisation with s.proto(), but don't hesitate to challenge!

Comment on lines +346 to +348
Get(s, "/", func(*ContextNoBody) (MyStruct, error) {
return MyStruct{}, nil
})
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: You can use dummyController for lisibility

Comment on lines 19 to +23
type OpenAPIConfig struct {
DisableSwagger bool // If true, the server will not serve the Swagger UI nor the OpenAPI JSON spec
DisableSwaggerUI bool // If true, the server will not serve the Swagger UI
DisableLocalSave bool // If true, the server will not save the OpenAPI JSON spec locally
SwaggerUrl string // URL to serve the swagger UI
UIHandler func(specURL string) http.Handler // Handler to serve the OpenAPI UI from spec URL
JsonUrl string // URL to serve the OpenAPI JSON spec
JsonFilePath string // Local path to save the OpenAPI JSON spec
PrettyFormatJson bool // Pretty prints the OpenAPI spec with proper JSON indentation
// Overrides the server description generated by fuego
Server *openapi3.Server
// If true, the server will not serve the Swagger UI nor the OpenAPI JSON spec
DisableSwagger bool
Copy link
Member

Choose a reason for hiding this comment

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

Not sure that a chunk (*openapi3.Server) of the OpenAPI Description should be in the OpenAPIConfig.

OpenAPIConfig is more about "How will Fuego handle the output of the OpenAPI Description". But as there's no comment, you wouldn't have guessed it, sorry about that!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I figured as much. I personally think this does have to do with the OpenApi description. That's all this change is really focusing on.

Comment on lines 146 to 149
}

s.OpenAPI.Description().Servers = append(s.OpenAPI.Description().Servers, &openapi3.Server{
URL: "http://" + s.Addr,
Description: "local server",
})

s.startTime = time.Now()

Copy link
Member

Choose a reason for hiding this comment

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

Good thing to get rid of this here, thanks!

Comment on lines 84 to 91
s := NewServer(
WithOpenAPIConfig(OpenAPIConfig{
Server: &openapi3.Server{
URL: "foo",
Description: "bar",
},
SwaggerUrl: "/api",
JsonUrl: "/api/openapi.json",
Copy link
Member

Choose a reason for hiding this comment

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

Mmh I prefer our users to code themselves:

s.OpenAPI.Description().Servers = append(...)

Rather than giving them a shortcut that does exactly the same. I mean, we have no added value of doing this

@@ -95,6 +95,14 @@ func declareAllTagsFromOperations(s *Server) {
// Also serves a Swagger UI.
// To modify its behavior, use the [WithOpenAPIConfig] option.
func (s *Server) OutputOpenAPISpec() openapi3.T {
if s.OpenAPIConfig.Server == nil {
s.OpenAPIConfig.Server = &openapi3.Server{
URL: s.proto() + "://" + s.Addr,
Copy link
Member

Choose a reason for hiding this comment

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

So to sum up, the strong point of this PR is mostly this s.proto am I right?

Nice!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it's to provide a way to configure a value that we've been setting for our users. This leads into #248.

If you don't think the configurability is worth it. Please let me just revert the single commit that adds the feature. Thanks

@dylanhitt dylanhitt force-pushed the refactor/set-openapi-serverURL branch from f03071d to 90312b0 Compare December 13, 2024 20:52
@dylanhitt dylanhitt closed this Dec 13, 2024
@dylanhitt
Copy link
Collaborator Author

Closing per suggestions and #273

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.

refactor setting of - Server.OpenApiSpec.Servers
2 participants