orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
2.96k stars 326 forks source link

Add custom header for each API spec or verb/operation #733

Open geekus opened 1 year ago

geekus commented 1 year ago

Thanks a lot for a great tool!

I'd like to add some config that adds a custom header to each spec verb/operation, or if this is not possible per API spec could suffice. Is either possible? Couldn't figure it out. Thought maybe this requestOptions (https://orval.dev/reference/configuration/output#requestoptions) could be used but it's not clear to me how to structure the object. Tried this but it did not seem to have any effect:

      requestOptions: {
        headers: {
          'X-Custom-Header': 'Foo',
        },
      },
anymaniax commented 1 year ago

Hello @geekus, if you want to add it at generation time and don't change it dynamically you can do it with a mutator. If you specify it in the spec and want to pass it at runtime you can use the flag headers.

geekus commented 1 year ago

Hi, yes, I want to add it at generation time. I could do that. I already have a mutator, but I also have several specs that would need different headers, and I'd like to use the same mutator for all specs, and there are no options to add arguments per spec to the mutator which would be the ideal solution, like with transformers. 🤔 Although I realize they are two different things.