@@ -4,7 +4,9 @@ import { generateInterface, InterfaceProperty } from '@ts/generateInterface';
44import { generateStatements } from '@ts/generateStatements' ;
55import { convertToTypeScriptType } from '@utils/openapi/convertToTypeScriptType' ;
66import {
7- isEnumSchemaObject , isFilterPathsSchemaObject , isFilterPropertySchemaObject ,
7+ isEnumSchemaObject ,
8+ isFilterPathsSchemaObject ,
9+ isFilterPropertySchemaObject ,
810 isNonArraySchemaObject ,
911 isObjectSchemaObject ,
1012 isReferenceObject ,
@@ -49,7 +51,10 @@ export const generateEntities = (
4951 const filterableInterfaceProperties : InterfaceProperty [ ] = [ ] ;
5052 const properties = new Map < string , PropertyMetaData > ( ) ;
5153
52- const processProperties = ( props : Record < string , OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject > = { } , isXweclappFilterProp ?: boolean ) => {
54+ const processProperties = (
55+ props : Record < string , OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject > = { } ,
56+ isXweclappFilterProp ?: boolean
57+ ) => {
5358 for ( const [ name , property ] of Object . entries ( props ) ) {
5459 const meta = isRelatedEntitySchema ( property ) ? property [ 'x-weclapp' ] : { } ;
5560 const type = convertToTypeScriptType ( property , name ) . toString ( ) ;
@@ -61,11 +66,11 @@ export const generateEntities = (
6166 : undefined
6267 : undefined ;
6368
64- if ( meta . filterable !== false ) {
69+ if ( meta . filterable !== false ) {
6570 filterableInterfaceProperties . push ( { name, type } ) ;
6671 }
6772
68- if ( ! isXweclappFilterProp ) {
73+ if ( ! isXweclappFilterProp ) {
6974 entityInterfaceProperties . push ( {
7075 name,
7176 type,
@@ -87,15 +92,15 @@ export const generateEntities = (
8792 } else if ( isObjectSchemaObject ( item ) ) {
8893 processProperties ( item . properties ) ;
8994
90- if ( isFilterPropertySchemaObject ( item ) ) {
95+ if ( isFilterPropertySchemaObject ( item ) ) {
9196 processProperties ( item [ 'x-weclapp-filterProperties' ] , true ) ;
9297 }
9398
94- if ( isFilterPathsSchemaObject ( item ) ) {
99+ if ( isFilterPathsSchemaObject ( item ) ) {
95100 const fPaths : Record < string , string > = item [ 'x-weclapp-filterPaths' ] ;
96- for ( const path in fPaths ) {
97- if ( ! path . includes ( '.' ) ) {
98- filterableInterfaceProperties . push ( { name : path , type : fPaths [ path ] } ) ;
101+ for ( const path in fPaths ) {
102+ if ( ! path . includes ( '.' ) ) {
103+ filterableInterfaceProperties . push ( { name : path , type : fPaths [ path ] } ) ;
99104 }
100105 }
101106 }
@@ -108,7 +113,9 @@ export const generateEntities = (
108113 entities . set ( schemaName , {
109114 name : schemaName ,
110115 properties,
111- filterableInterfaceProperties : filterableInterfaceProperties . sort ( ( propA , propB ) => propA . name . localeCompare ( propB . name ) ) ,
116+ filterableInterfaceProperties : filterableInterfaceProperties . sort ( ( propA , propB ) =>
117+ propA . name . localeCompare ( propB . name )
118+ ) ,
112119 parentName : parentEntityInterfaceName ? camelCase ( parentEntityInterfaceName ) : undefined ,
113120 source : generateStatements (
114121 generateInterface ( entityInterfaceName , entityInterfaceProperties , parentEntityInterfaceName )
@@ -119,32 +126,41 @@ export const generateEntities = (
119126 return entities ;
120127} ;
121128
122- export const generateEntityFilterProps = ( entities : Map < string , GeneratedEntity > , enums : Map < string , GeneratedEnum > ) : Map < string , GeneratedEntityFilterProp > => {
129+ export const generateEntityFilterProps = (
130+ entities : Map < string , GeneratedEntity > ,
131+ enums : Map < string , GeneratedEnum >
132+ ) : Map < string , GeneratedEntityFilterProp > => {
123133 const entityFilterProps : Map < string , GeneratedEntityFilterProp > = new Map ( ) ;
124134
125135 const transformFilterProps = ( props : InterfaceProperty [ ] ) => {
126136 return props . map ( ( prop ) => {
127- if ( ! prop . type || enums . has ( prop . type ) || prop . type === 'string' || prop . type === 'number' || prop . type === 'boolean' || prop . type . endsWith ( '[]' ) ) {
137+ if (
138+ ! prop . type ||
139+ enums . has ( prop . type ) ||
140+ prop . type === 'string' ||
141+ prop . type === 'number' ||
142+ prop . type === 'boolean' ||
143+ prop . type . endsWith ( '[]' ) ||
144+ prop . type === '{}'
145+ ) {
128146 return prop ;
129147 }
130148
131- return { ...prop , type : `${ pascalCase ( prop . type ) } _${ FILTER_PROPS_SUFFIX } ` }
132- } )
133- }
149+ return { ...prop , type : `${ pascalCase ( prop . type ) } _${ FILTER_PROPS_SUFFIX } ` } ;
150+ } ) ;
151+ } ;
134152
135153 entities . forEach ( ( entity , name ) => {
136- const entityFilterName = `${ pascalCase ( name ) } _${ FILTER_PROPS_SUFFIX } `
154+ const entityFilterName = `${ pascalCase ( name ) } _${ FILTER_PROPS_SUFFIX } ` ;
137155 const parentName = entity . parentName ? `${ pascalCase ( entity . parentName ) } _${ FILTER_PROPS_SUFFIX } ` : undefined ;
138156 const filterableInterfaceProperties = transformFilterProps ( entity . filterableInterfaceProperties ) ;
139157
140158 entityFilterProps . set ( entityFilterName , {
141159 name : entityFilterName ,
142160 parentName,
143- source : generateStatements (
144- generateInterface ( entityFilterName , filterableInterfaceProperties , parentName )
145- )
161+ source : generateStatements ( generateInterface ( entityFilterName , filterableInterfaceProperties , parentName ) )
146162 } ) ;
147163 } ) ;
148164
149165 return entityFilterProps ;
150- }
166+ } ;
0 commit comments