Skip to content

Documentation: 'base_path' Swagger attribute confuses users #918

Closed
@nu11ptr

Description

@nu11ptr

Steps you follow to reproduce the error:

  1. I start with a working REST API and with properly generating Swagger definitions
  2. I added a 'base_path' attribute to the 'openapiv2_swagger' annotation in my proto file
  3. I removed the equivalent base_path prefix from each 'google.api.http' annotation (base_path = "/api/v1")
  4. I regenerated my Go code and restarted my API
  5. All my REST APIs now return 404 errors

What did you expect to happen instead:

I expected the API to remain working

What's your theory on why it isn't working:

The generated code was previously generating this:

pattern_Provider_EncryptClientSecret_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "provider", "client_secret_encrypter"}, ""))

It is now generating this:

pattern_Provider_EncryptClientSecret_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"provider", "client_secret_encrypter"}, ""))

It seems like the generator is not aware of the 'base_path' attribute and expects the 'google.api.http' to hold the entire path. However, adding this path back on (while retaining 'base_path' attribute) has the impact of:

  1. Adding that path to all endpoints displayed in the Swagger UI which makes it very 'noisy' and hard to read
  2. Breaking the Swagger UI "try it out" feature which doubles up the 'base_path' be prefixing base_path to all operations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions