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

Required path params are generated as pointers #50

Open
dmlambea opened this issue May 17, 2024 · 0 comments
Open

Required path params are generated as pointers #50

dmlambea opened this issue May 17, 2024 · 0 comments

Comments

@dmlambea
Copy link

Running the latest released Docker image with following args: --with-zero-values --validate-required --skip-default-additional-properties

And feeding it with the following test input:

{
 "openapi": "3.0.3",
 "info": {
  "title": "Test API",
  "description": "Wrong pointer types in required path",
  "version": "1.0"
 },
 "paths": {
  "/v1/sample/operation": {
   "delete": {
    "tags": [
     "sample tag"
    ],
    "summary": "Required path parameters cannot be pointers",
    "description": "Sample test.",
    "parameters": [
     {
      "name": "ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "version",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     }
    ],
    "responses": {
     "204": {
      "description": "No Content"
     }
    }
   }
  }
 }
}

The resulting request is generated with pointer types. Moreover, the encoding method does not take the params into account when generating the URL:

// DeleteV1SampleOperationRequest is operation request value.
type DeleteV1SampleOperationRequest struct {
        Ref     *string  // Ref is a required `ref` parameter in path.
        Version *int64   // Version is a required `version` parameter in path.
}

// encode creates *http.Request for request data.
func (request *DeleteV1SampleOperationRequest) encode(ctx context.Context, baseURL string) (*http.Request, error) {
        requestURI := baseURL + "/v1/sample/operation"

        req, err := http.NewRequest(http.MethodDelete, requestURI, nil)
        if err != nil {
                return nil, err
        }

        req = req.WithContext(ctx)

        return req, err
}

Removing the arg --with-zero-values will not work because it disables generating optional attributes as pointers.

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

No branches or pull requests

1 participant