oapi-codegen
oapi-codegen copied to clipboard
Remove common path from generated function names
Hello,
I have an OpenAPI spec that has a bunch of endpoints like this:
"paths": {
"/api/v1.0/Application/{id}": {
"post": { ... }
"get": { ... }
"/api/v1.0/Application/{id}/providers": {
"get": { ... }
}
}
And a basic config:
package: authzApiClient
output: internal/authzApiClient/v1/client.gen.go
generate:
models: true
client: true
compatibility:
circular-reference-limit: 10
output-options:
include-tags:
- Application
Subsequently the generated client methods look like this:
type ClientInterface interface {
// GetApiV10Application request
GetApiV10Application(ctx context.Context, params *GetApiV10ApplicationParams, reqEditors ...RequestEditorFn) (*http.Response, error)
// PostApiV10ApplicationWithBody request with any body
PostApiV10ApplicationWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
// GetApiV10ApplicationIdProviders request
GetApiV10ApplicationIdProviders(ctx context.Context, params *GetApiV10ApplicationIdProvidersParams, reqEditors ...RequestEditorFn) (*http.Response, error)
...
}
Is it possible to remove the common /api/v1.0/ / ApiV10 prefix from the generated function and struct names?
I looked into name-normalizers, but that doesn't seem to apply here.
Thanks!
Had the same issue. But you are able to set operationId for a given path see OpenAPI docs. If you specify an operationId, the specified ID is used for function name generation.
It does require spec updates.
Hope that helps.