oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Generate functions to get operation URLs

Open tschaub opened this issue 5 years ago • 1 comments

For handlers that generate links to other resources, it would be useful to be able to call a function that generates a URL for an operation. The current NewOperationRequest type functions could be split into two functions. Roughly like this:

func NewOperationRequest(server string, params *OperationParams) (*http.Request, error) {
	operationURL, err := OperationURL(server, params)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("GET", operationURL.String(), nil)
	if err != nil {
		return nil, err
	}

	return req, nil
}

func OperationURL(server string, params *OperationParams) (*url.URL, error) {
	// use existing logic to generate the URL...
}

Would a pull request for something like this be acceptable?

tschaub avatar Mar 28 '20 17:03 tschaub

This would indeed be a really useful feature, especially when trying to implement HATEOAS. Another solution could be to use a URL store such as https://github.com/alehano/reverse.

acabarbaye avatar Feb 11 '21 09:02 acabarbaye