@@ -6,12 +6,11 @@ import type {
66 ApiEndpoint ,
77 TypeDefinition ,
88 Entity ,
9- ConfidenceLevel ,
10- } from '../semantic/model' ;
9+ } from '../semantic/model.js' ;
1110
12- import { isJunkEntity } from './model-generator' ;
13- import type { GeneratedFile } from './swiftui-generator' ;
14- import { pascalCase , camelCase , isMarketingScreen , pluralize , cleanSourceName , cleanStoreName } from './swiftui-generator' ;
11+ import { isJunkEntity } from './model-generator.js ' ;
12+ import type { GeneratedFile } from './swiftui-generator.js ' ;
13+ import { pascalCase , camelCase , isMarketingScreen , pluralize , cleanSourceName , cleanStoreName } from './swiftui-generator.js ' ;
1514
1615// ---------------------------------------------------------------------------
1716// Helpers
@@ -82,21 +81,14 @@ function typeDefToSwift(td: TypeDefinition): string {
8281}
8382
8483/**
85- * Sanitize a raw typeName from the analyzer — map leaked JS/TS types to their
86- * Swift equivalents or return undefined if the name is not usable .
84+ * Sanitize a raw typeName from the analyzer — map leaked JS/TS capitalized
85+ * type names to undefined so the kind-based default is used instead .
8786 */
8887function sanitizeTypeName ( name : string | undefined ) : string | undefined {
8988 if ( ! name ) return undefined ;
9089
91- // Map capitalized JS types to Swift equivalents
92- if ( name === 'Number' ) return undefined ; // handled by kind='number' → Double
93- if ( name === 'Boolean' ) return undefined ; // handled by kind='boolean' → Bool
94-
95- // Reject names containing TS syntax (Promise<...>, unions, arrow fns, object literals)
96- if ( / [ < > | { } ] | = > / . test ( name ) ) return undefined ;
97-
98- // Reject function signature types
99- if ( / \( .* \) \s * = > / . test ( name ) ) return undefined ;
90+ // Capitalized JS types should fall through to kind-based defaults (Double, Bool)
91+ if ( name === 'Number' || name === 'Boolean' ) return undefined ;
10092
10193 return name ;
10294}
@@ -1144,19 +1136,17 @@ function generateEndpointMethod(endpoint: ApiEndpoint, entities: Entity[] = []):
11441136
11451137 const hasBody = method !== 'GET' && endpoint . requestBody != null ;
11461138
1139+ // Build the function signature based on return type and HTTP method
1140+ const funcSignature = ` func ${ functionName } (${ params . join ( ', ' ) } ) async throws` ;
1141+
11471142 if ( effectiveReturnType && effectiveReturnType !== 'Void' ) {
1148- lines . push ( ` func ${ functionName } (${ params . join ( ', ' ) } ) async throws -> ${ effectiveReturnType } {` ) ;
1149- } else if ( method === 'DELETE' ) {
1150- // DELETE endpoints don't return a value
1151- lines . push ( ` func ${ functionName } (${ params . join ( ', ' ) } ) async throws {` ) ;
1152- } else if ( method === 'GET' && ! effectiveReturnType ) {
1153- // GET endpoints should always return something — use [String] as placeholder
1154- lines . push ( ` func ${ functionName } (${ params . join ( ', ' ) } ) async throws -> [String] {` ) ;
1155- } else if ( ( method === 'POST' || method === 'PUT' || method === 'PATCH' ) && ! effectiveReturnType ) {
1156- // Mutation endpoints without known return type — return void
1157- lines . push ( ` func ${ functionName } (${ params . join ( ', ' ) } ) async throws {` ) ;
1143+ lines . push ( `${ funcSignature } -> ${ effectiveReturnType } {` ) ;
1144+ } else if ( method === 'DELETE' || method === 'POST' || method === 'PUT' || method === 'PATCH' ) {
1145+ // Mutation/delete endpoints without known return type — return void
1146+ lines . push ( `${ funcSignature } {` ) ;
11581147 } else {
1159- lines . push ( ` func ${ functionName } (${ params . join ( ', ' ) } ) async throws -> ${ effectiveReturnType ?? '[String]' } {` ) ;
1148+ // GET or other methods without known return type — use [String] as placeholder
1149+ lines . push ( `${ funcSignature } -> [String] {` ) ;
11601150 }
11611151
11621152 // Build query items for list endpoints with pagination
0 commit comments