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

How to omit certain headers from hook args during codegen? #3006

Open
blwinters opened this issue Dec 14, 2022 · 0 comments
Open

How to omit certain headers from hook args during codegen? #3006

blwinters opened this issue Dec 14, 2022 · 0 comments

Comments

@blwinters
Copy link

blwinters commented Dec 14, 2022

I'm guessing that this isn't currently possible, but I wanted to ask and start a discussion. I'm using RTK Query and the codegen tool with OpenAPI on our server. Our server requires a custom Organization-ID header for almost all endpoints to identify which of the user's organizations is active/relevant on the client (like different teams on Slack). Because this header is required everywhere, I'm adding it to headers via the prepareHeaders function in the RTK Query base query.

This part works great. However, when I run codegen all of the endpoint hooks now require Organization-ID as an argument.

Generated hook arg type:

export type VehiclesInspectionCreateApiArg = {
  'Organization-ID': string
  vehicleInspectionReport: VehicleInspectionReport
}

which gets called like:

const [submitInspectionData] = useVehiclesInspectionCreateMutation()
const onPressSubmit = () => {
  submitInspectionData({
    'Organization-ID': '',
    vehicleInspectionReport: {
      // ...
    },
  })
}

Presumably I can pass it an empty string and that will get overwritten during prepareHeaders, but I'd like to clean that up if possible. Is there any way that I can tell codegen to skip that header when generating the arg type for the hooks? If not, does anyone have ideas for how this capability could be added while keeping with the intent and patterns of this project? I'd be interested in contributing if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants