You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor your transformers and move them into their own functions / files
Because we are using typescript and want to type our function parameters,
we need access to both OpenAPIObject which is what is passed to an InputTransformer and VerbOptions which is passed to an OutputTransformer.
However, Orval does not expose these types.
The OpenAPIObject type can be accessed by adding and importing the openapi3-ts/oas30 package.
The VerbOptions can only be accessed if we employ longwinded and arcane typescript unpacking magic.
This is the code I have written to gain access to VerbOptions:
import{defineConfig}from'orval';typeConfigType=Parameters<typeofdefineConfig>[0];typeValueOf<T>=T[keyofT];typeUnwrappedConfigValueType=Unwrap<ValueOf<Unwrap<ConfigType>>>;typeUnwrap<T>=TextendsPromise<infer U> ? Unwrap<U> : Textends()=> infer U ? Unwrap<U> : T;typeOutputOptionsType=ExtractOutput<UnwrappedConfigValueType>;typeExtractOutput<T>=Textends{output?: infer O}
? Oextendsstring|undefined
? never
: O
: never;typeOverrideOutputType=ExtractOverride<OutputOptionsType>;typeExtractOverride<T>=Textends{override?: infer O}
? Oextendsundefined
? never
: O
: never;typeExtractTransformer<T>=Textends{transformer?: infer O}
? Oextends(options: infer U)=>unknown
? U
: never
: never;exporttypeVerbOptions=ExtractTransformer<OverrideOutputType>;
What happens?
I have to add and import extra packages as well as write a vast amount of boiler plate code so that my transformer functions can be typed safely and correctly.
What were you expecting to happen?
I expect the orval package to export these types so I can use them right away.
Any logs, error output, etc?
N/A
Any other comments?
These types are inferred, but that only works as long as the transformer function is inline.
As soon as we refactor because we have a larger amount of configuration / extras, we run into this issue.
You are right, these types are exported by @orval/core! @orval/core was not in my direct dependencies and the installation docs didn't specify I need to install it,
and therefore it didnt show up in the autocomplete of my IDE.
It doesn't look like I am meant to directly depend on @orval/core,
and importing things from an indirect dependency is discouraged.
Do you think it would be sensible to re-export these types in orval, considering its public functions use it?
The Orval package combines all the dependencies, and for me, it's not an issue to re-export the types from it. All the other packages were meant to enable more advanced functionality, such as using a specific version of a client or performing custom generation.
What are the steps to reproduce this issue?
orval.config.ts
defineConfig
to create your configBecause we are using typescript and want to type our function parameters,
we need access to both
OpenAPIObject
which is what is passed to anInputTransformer
andVerbOptions
which is passed to anOutputTransformer
.However, Orval does not expose these types.
The
OpenAPIObject
type can be accessed by adding and importing theopenapi3-ts/oas30
package.The
VerbOptions
can only be accessed if we employ longwinded and arcane typescript unpacking magic.This is the code I have written to gain access to
VerbOptions
:What happens?
I have to add and import extra packages as well as write a vast amount of boiler plate code so that my transformer functions can be typed safely and correctly.
What were you expecting to happen?
I expect the orval package to export these types so I can use them right away.
Any logs, error output, etc?
N/A
Any other comments?
These types are inferred, but that only works as long as the transformer function is inline.
As soon as we refactor because we have a larger amount of configuration / extras, we run into this issue.
What versions are you using?
The text was updated successfully, but these errors were encountered: