-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
Support replacing types with custom ones when transforming the input #1222
Comments
I marked as question. I feel like what you want to do is possible with Orval but I have not done it myself. Hopefully someone who has done this can chime in like @soartec-lab ? |
no, I haven't tried it too. |
I have done a similar thing as OP with openapi-generator. Orval seems much more lightweight, but sadly the lack of this feature is a deal breaker for truly type-safe APIs. |
I inspected this. https://github.com/anymaniax/orval/blob/master/packages/core/src/getters/object.ts#L207 If there is a better way to determine the user-defined one, I will fix this issue. |
I think the easiest way to solve this would be to create a new configuration option - something like Some other inspiration could be found in a similar feature for schema-first GraphQL for NestJS (see With that in mind, based on OP's example, I would suggest the following API: Say the OpenAPI schema looks like this: type: object
properties:
id:
type: string
format: 'x-user-id' # for example
name:
type: string I would lean towards using the The configuration could then look as follows: customFormatMapping: {
'x-user-id': {
typeName: 'UserId', // use the type name as a string
importFrom: './custom-types' // optionally add an import (although a custom static header could be enough)
}
} |
(Not using the standard issue template as this is a feature request)
I'm migrating from
openapi-typescript
to orval. In my current setup I've added what could be called "nominal types" - so for instance instead oftype userId = number
it would usetype userId = UserId
with the following implementation:Then I have a transformer on the API TS generation that modifies all instances of a
userId
to use this custom type, and injects animport {UserId} from './types'
Such that we end up with something like:
Arguments about the use-cases of this approach and such aside, would this be possible with
orval
?I'm trying something like this in the orval config:
But this just generates the type
userId: unknown
- so ideally there would be a supported way to do this.When using
openapi-typescript
I just transform the type and basically set it to"UserId"
, so that it then appears as the string content. And I inject theimport
statement at the top of the file manually (they have a way to inject anything at the top of the file)The text was updated successfully, but these errors were encountered: