@@ -13,6 +13,7 @@ import {
1313import * as E from 'fp-ts/Either' ;
1414import * as fs from 'fs' ;
1515import * as p from 'path' ;
16+ import type { Expression } from '@swc/core' ;
1617
1718import { parseApiSpec } from './apiSpec' ;
1819import { getRefs } from './ref' ;
@@ -24,6 +25,7 @@ import { Project } from './project';
2425import { KNOWN_IMPORTS } from './knownImports' ;
2526import { findSymbolInitializer } from './resolveInit' ;
2627import { parseCodecInitializer } from './codec' ;
28+ import { SourceFile } from './sourceFile' ;
2729
2830const app = command ( {
2931 name : 'api-ts' ,
@@ -118,7 +120,18 @@ const app = command({
118120 continue ;
119121 } else if ( symbol . init . arguments . length === 0 ) {
120122 continue ;
123+ } else if (
124+ symbol . init . callee . type === 'Super' ||
125+ symbol . init . callee . type === 'Import'
126+ ) {
127+ console . error (
128+ `Skipping ${ symbol . name } because it is a ${ symbol . init . callee . type } ` ,
129+ ) ;
130+ continue ;
131+ } else if ( ! isApiSpec ( entryPoint , symbol . init . callee ) ) {
132+ continue ;
121133 }
134+ console . error ( `Found API spec in ${ symbol . name } ` ) ;
122135
123136 const result = parseApiSpec (
124137 project . right ,
@@ -127,7 +140,7 @@ const app = command({
127140 ) ;
128141 if ( E . isLeft ( result ) ) {
129142 console . error ( `Error parsing ${ symbol . name } : ${ result . left } ` ) ;
130- continue ;
143+ process . exit ( 1 ) ;
131144 }
132145
133146 apiSpec . push ( ...result . right ) ;
@@ -190,5 +203,33 @@ const app = command({
190203 } ,
191204} ) ;
192205
206+ function isApiSpec ( entryPoint : SourceFile , init : Expression ) : boolean {
207+ if ( init . type === 'Identifier' ) {
208+ return (
209+ entryPoint . symbols . imports . find (
210+ ( imp ) =>
211+ imp . type === 'named' &&
212+ imp . from === '@api-ts/io-ts-http' &&
213+ imp . importedName === 'apiSpec' &&
214+ imp . localName === init . value ,
215+ ) !== undefined
216+ ) ;
217+ } else if ( init . type === 'MemberExpression' ) {
218+ return (
219+ entryPoint . symbols . imports . find (
220+ ( imp ) =>
221+ imp . type === 'star' &&
222+ imp . from === '@api-ts/io-ts-http' &&
223+ init . object . type === 'Identifier' &&
224+ init . object . value === imp . localName &&
225+ init . property . type === 'Identifier' &&
226+ init . property . value === 'apiSpec' ,
227+ ) !== undefined
228+ ) ;
229+ } else {
230+ return false ;
231+ }
232+ }
233+
193234// parse arguments
194235run ( app , process . argv . slice ( 2 ) ) ;
0 commit comments