File tree Expand file tree Collapse file tree 10 files changed +33
-13
lines changed
integration-tests-definitions
typescript-angular/src/generated/todo-lists.yaml
typescript-axios/src/generated/todo-lists.yaml
typescript-fetch/src/generated/todo-lists.yaml
typescript-koa/src/generated/todo-lists.yaml
packages/openapi-code-generator/src Expand file tree Collapse file tree 10 files changed +33
-13
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,9 @@ components:
171
171
created :
172
172
type : string
173
173
format : date-time
174
+ x-alpha-transform :
175
+ fn : (it) => new Date(it)
176
+ type : Date
174
177
updated :
175
178
type : string
176
179
format : date-time
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export type t_CreateUpdateTodoList = {
12
12
}
13
13
14
14
export type t_TodoList = {
15
- created : string
15
+ created : Date
16
16
id : string
17
17
incompleteItemCount : number
18
18
name : string
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export type t_CreateUpdateTodoList = {
12
12
}
13
13
14
14
export type t_TodoList = {
15
- created : string
15
+ created : Date
16
16
id : string
17
17
incompleteItemCount : number
18
18
name : string
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export type t_CreateUpdateTodoList = {
12
12
}
13
13
14
14
export type t_TodoList = {
15
- created : string
15
+ created : Date
16
16
id : string
17
17
incompleteItemCount : number
18
18
name : string
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export type t_Error = {
8
8
}
9
9
10
10
export type t_TodoList = {
11
- created : string
11
+ created : Date
12
12
id : string
13
13
incompleteItemCount : number
14
14
name : string
Original file line number Diff line number Diff line change @@ -11,7 +11,10 @@ export const s_TodoList = z.object({
11
11
name : z . string ( ) ,
12
12
totalItemCount : z . coerce . number ( ) ,
13
13
incompleteItemCount : z . coerce . number ( ) ,
14
- created : z . string ( ) . datetime ( { offset : true } ) ,
14
+ created : z
15
+ . string ( )
16
+ . datetime ( { offset : true } )
17
+ . transform ( ( it ) => new Date ( it ) ) ,
15
18
updated : z . string ( ) . datetime ( { offset : true } ) ,
16
19
} )
17
20
Original file line number Diff line number Diff line change @@ -9,7 +9,12 @@ export interface IRModelBase {
9
9
nullable : boolean /* false */
10
10
readOnly : boolean /* false */
11
11
12
- "x-alpha-transform" ?: string | undefined
12
+ "x-alpha-transform" ?:
13
+ | {
14
+ fn ?: string | undefined
15
+ type ?: string | undefined
16
+ }
17
+ | undefined
13
18
}
14
19
15
20
export type IRModelNumericFormat = "int32" | "int64" | "float" | "double"
Original file line number Diff line number Diff line change @@ -249,8 +249,13 @@ export interface Schema {
249
249
deprecated ?: boolean | undefined
250
250
// xml?: XML | undefined
251
251
252
- // TODO: not yet supported by type-builder or joi
253
- "x-alpha-transform" ?: string | undefined
252
+ // TODO: not yet supported by joi
253
+ "x-alpha-transform" ?:
254
+ | {
255
+ fn ?: string | undefined
256
+ type ?: string | undefined
257
+ }
258
+ | undefined
254
259
}
255
260
256
261
export interface Discriminator {
Original file line number Diff line number Diff line change @@ -180,8 +180,10 @@ export abstract class AbstractSchemaBuilder<
180
180
oneOf : [ ] ,
181
181
required : [ ] ,
182
182
anyOf : [ parameter . schema , parameter . schema . items ] ,
183
- "x-alpha-transform" : ( ( it : unknown ) =>
184
- Array . isArray ( it ) || it === undefined ? it : [ it ] ) . toString ( ) ,
183
+ "x-alpha-transform" : {
184
+ fn : ( ( it : unknown ) =>
185
+ Array . isArray ( it ) || it === undefined ? it : [ it ] ) . toString ( ) ,
186
+ } ,
185
187
}
186
188
} else {
187
189
model . properties [ parameter . name ] = parameter . schema
@@ -326,8 +328,8 @@ export abstract class AbstractSchemaBuilder<
326
328
327
329
result = required ? this . required ( result ) : this . optional ( result )
328
330
329
- if ( model [ "x-alpha-transform" ] ) {
330
- result = this . transform ( result , model [ "x-alpha-transform" ] )
331
+ if ( model [ "x-alpha-transform" ] ?. fn ) {
332
+ result = this . transform ( result , model [ "x-alpha-transform" ] ?. fn )
331
333
}
332
334
333
335
return result
Original file line number Diff line number Diff line change @@ -145,7 +145,9 @@ export class TypeBuilder implements ICompilable {
145
145
result . push ( ...schemaObject . anyOf . flatMap ( this . schemaObjectToTypes ) )
146
146
}
147
147
148
- if ( result . length === 0 ) {
148
+ if ( schemaObject [ "x-alpha-transform" ] ?. type ) {
149
+ result . push ( schemaObject [ "x-alpha-transform" ] ?. type )
150
+ } else if ( result . length === 0 ) {
149
151
switch ( schemaObject . type ) {
150
152
case "array" : {
151
153
result . push ( array ( this . schemaObjectToType ( schemaObject . items ) ) )
You can’t perform that action at this time.
0 commit comments