OpenAPITools / OpenAPITools/openapi-generator

[BUG] [go-server] code to marshal query parameters is missing from the API Controller when we wrap the parameter schema into content

Open
#13,310 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • [x ] Have you provided a full/minimal spec to reproduce the issue?
  • [x ] Have you validated the input using an OpenAPI validator (example)?
  • [ x] Have you tested with the latest master to confirm the issue still exists?
  • [ x] Have you searched for related issues/PRs?
  • [ x] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

code to marshal query parameters is missing from the API Controller when we wrap the parameter schema into content

openapi-generator version

7.0.0-20220719.043604-2

Yaml that produces the error : https://gist.github.com/blackgold/e1d5b96fbb453967a7371eafd1263329

Generation Details

java -Dhttp.proxyHost=fwdproxy -Dhttp.proxyPort=8080 -Dhttps.proxyHost=fwdproxy -Dhttps.proxyPort=8080 -Djava.net.preferIPv6Stack=true -jar ~/openapi-generator-cli-7.0.0-20220719.043604-2.jar generate -i a.yaml -p packageName=server -g go-server -o server

Steps to reproduce
  1. Download yaml https://gist.github.com/blackgold/e1d5b96fbb453967a7371eafd1263329
  2. java -Dhttp.proxyHost=fwdproxy -Dhttp.proxyPort=8080 -Dhttps.proxyHost=fwdproxy -Dhttps.proxyPort=8080 -Djava.net.preferIPv6Stack=true -jar ~/openapi-generator-cli-7.0.0-20220719.043604-2.jar generate -i a.yaml -p packageName=server -g go-server -o server
  3. Open file server/go/api_default.go and look for following generated code
// ReadSubscriptions - 
func (c *DefaultApiController) ReadSubscriptions(w http.ResponseWriter, r *http.Request) {
  query := r.URL.Query()
  **dataFilterParam := query.Get("data-filter")**
  result, err := c.service.ReadSubscriptions(r.Context(), **dataFilterParam**)
  // If an error occurred, encode the error with the status code
  if err != nil {
    c.errorHandler(w, r, err, &result)
    return
  }
  // If no error, encode the body and the result code
  EncodeJSONResponse(result.Body, &result.Code, w)

}
  1. Open server/go/api_default_service.go and look for following code.
// ReadSubscriptions - 
func (s *DefaultApiService) ReadSubscriptions(ctx context.Context, dataFilter DataFilter) (ImplResponse, error) {
  // TODO - update ReadSubscriptions with the required logic for this service method.
  // Add api_default_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.

  //TODO: Uncomment the next line to return response Response(200, {}) or use other options such as http.Ok ...
  //return Response(200, nil),nil

  return Response(http.StatusNotImplemented, nil), errors.New("ReadSubscriptions method not implemented")
}
  1. In step (3) expect code to marshal dataFilterParam to DataFilter
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the Go server from the linked YAML with the documented openapi-generator command, then inspect server/go/api_default.go and server/go/api_default_service.go. Compare the wrapped query parameter's generated handling with the expected DataFilter value and trace the Go server generator templates or tests that produce the controller. Done means the generated controller marshals the content-wrapped query parameter into DataFilter correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.