ajaishankar / openapi-typescript-fetch

A typed fetch client for openapi-typescript
MIT License
233 stars 54 forks source link

.create() incorrectly expects single argument #28

Closed duncanbeevers closed 2 years ago

duncanbeevers commented 2 years ago

🗣 Discussion

Defining and OpenAPI3 operation with both a requestBody and query causes the .create() signature to expect an argument for the query portion.

export type paths = {
  '/openapiv3/body': {
    post: {
      parameters: {
        path: { id: number }
        query: { name: string }
      }
      requestBody: {
        content: {
          'application/json': { 200: { schema: Data } }
        }
      }
    }
  }
}

const fetcher = Fetcher.for<paths>()
fetcher.path('/openapiv3/body').method('post').create()
// Expected 1 arguments, but got 0.

image

ajaishankar commented 2 years ago

@duncanbeevers this is by design.

When there is both a query and request body then the library needs to know what params to pass in query vs body when the method is called.

To handle this, we need to provide a hint via the extra argument at time of creating a fetcher.

See test here

djMax commented 1 year ago

(why does it need to know this, doesn't the spec already say so?)