Skip to content

make query optional if all params are optional #1092

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

Merged
merged 2 commits into from
May 8, 2023
Merged

Conversation

ysmood
Copy link
Contributor

@ysmood ysmood commented May 7, 2023

If all query parameters are optional we should use query?: { ... } instead of query: { ... }. Or when we use libs like openapi-fetch we have to always write an empty query: {} on the request like:

const res = await client.get('/do/{id}', {
  params: {
    query: {},
    path: {
        id: 123,
    },
  },
})

We expect to use code like this:

const res = await client.get('/do/{id}', {
  params: {
    path: {
        id: 123,
    },
  },
})

@drwpow
Copy link
Contributor

drwpow commented May 7, 2023

Thanks for adding this; this already happens for the overall parameters object (#940) but it seems we didn’t mirror that behavior for query. I’m in favor of this just for better consistency.

Also, openapi-fetch is still immature, and types will improve over time (such as the behavior you just described—that will go away eventually). So I don’t want to make changes to this library just yet just to support openapi-fetch. But again, there’s reason for this to pass independently of that. But as openapi-fetch matures, it is a good public implementation of how openapi-typescript can be used, so eventually it will be good arguments to change this or that based on solid implementation.

@ysmood
Copy link
Contributor Author

ysmood commented May 8, 2023

Sure, it's update to you to modify or closed this PR.

I think it's not just for openapi-fetch, we also need this feature for our custom lib to work better. I think other libs might also want this, it won't affect much on your refactoring. Also it's better to inline the behavior of query with parameters as you said.

I updated the tests and examples, the CI should pass now.

@drwpow drwpow merged commit c76a9ed into openapi-ts:main May 8, 2023
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

Successfully merging this pull request may close these issues.

2 participants