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:
171171 created :
172172 type : string
173173 format : date-time
174+ x-alpha-transform :
175+ fn : (it) => new Date(it)
176+ type : Date
174177 updated :
175178 type : string
176179 format : date-time
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export type t_CreateUpdateTodoList = {
1212}
1313
1414export type t_TodoList = {
15- created : string
15+ created : Date
1616 id : string
1717 incompleteItemCount : number
1818 name : string
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export type t_CreateUpdateTodoList = {
1212}
1313
1414export type t_TodoList = {
15- created : string
15+ created : Date
1616 id : string
1717 incompleteItemCount : number
1818 name : string
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export type t_CreateUpdateTodoList = {
1212}
1313
1414export type t_TodoList = {
15- created : string
15+ created : Date
1616 id : string
1717 incompleteItemCount : number
1818 name : string
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export type t_Error = {
88}
99
1010export type t_TodoList = {
11- created : string
11+ created : Date
1212 id : string
1313 incompleteItemCount : number
1414 name : string
Original file line number Diff line number Diff line change @@ -11,7 +11,10 @@ export const s_TodoList = z.object({
1111 name : z . string ( ) ,
1212 totalItemCount : z . coerce . number ( ) ,
1313 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 ) ) ,
1518 updated : z . string ( ) . datetime ( { offset : true } ) ,
1619} )
1720
Original file line number Diff line number Diff line change @@ -9,7 +9,12 @@ export interface IRModelBase {
99 nullable : boolean /* false */
1010 readOnly : boolean /* false */
1111
12- "x-alpha-transform" ?: string | undefined
12+ "x-alpha-transform" ?:
13+ | {
14+ fn ?: string | undefined
15+ type ?: string | undefined
16+ }
17+ | undefined
1318}
1419
1520export type IRModelNumericFormat = "int32" | "int64" | "float" | "double"
Original file line number Diff line number Diff line change @@ -249,8 +249,13 @@ export interface Schema {
249249 deprecated ?: boolean | undefined
250250 // xml?: XML | undefined
251251
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
254259}
255260
256261export interface Discriminator {
Original file line number Diff line number Diff line change @@ -180,8 +180,10 @@ export abstract class AbstractSchemaBuilder<
180180 oneOf : [ ] ,
181181 required : [ ] ,
182182 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+ } ,
185187 }
186188 } else {
187189 model . properties [ parameter . name ] = parameter . schema
@@ -326,8 +328,8 @@ export abstract class AbstractSchemaBuilder<
326328
327329 result = required ? this . required ( result ) : this . optional ( result )
328330
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 )
331333 }
332334
333335 return result
Original file line number Diff line number Diff line change @@ -145,7 +145,9 @@ export class TypeBuilder implements ICompilable {
145145 result . push ( ...schemaObject . anyOf . flatMap ( this . schemaObjectToTypes ) )
146146 }
147147
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 ) {
149151 switch ( schemaObject . type ) {
150152 case "array" : {
151153 result . push ( array ( this . schemaObjectToType ( schemaObject . items ) ) )
You can’t perform that action at this time.
0 commit comments