acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.2k stars 351 forks source link

schema-parser and name-resolver types don't work #545

Open aphofstede opened 1 year ago

aphofstede commented 1 year ago

We're using generateApi with ts-node (ts-node --project ./tsconfig.build.json -r tsconfig-paths/register src/scripts/generateApi.ts) and we're getting some errors resolving SchemaParser and ComponentTypeNameResolver under the hood.

node_modules/swagger-typescript-api/index.d.ts:217:51 - error TS7016: Could not find a declaration file for module './src/schema-parser/schema-parser'. '/home/runner/work/backend/backend/node_modules/swagger-typescript-api/src/schema-parser/schema-parser.js' implicitly has an 'any' type.

217 | ((schema: Record<string, any>, parser: import("./src/schema-parser/schema-parser").SchemaParser) => string);



node_modules/swagger-typescript-api/index.d.ts:511:46 - error TS70[16](https://github.com/redacted/backend/actions/runs/5525285980/jobs/10078714199?pr=41#step:5:17): Could not find a declaration file for module './src/util/name-resolver'. '/home/runner/work/backend/backend/node_modules/swagger-typescript-api/src/util/name-resolver.js' implicitly has an 'any' type.

511     componentTypeNameResolver: typeof import("./src/util/name-resolver").ComponentTypeNameResolver;

Is this a bug in the library?

My generate options:

generateApi({
      output: path.resolve(process.cwd(), '__generated__'),
      spec: {
        openapi: spec.openapi,
        info: spec.info,
        components: spec.components,
        security: spec.security,
        paths: spec.paths,
      } as unknown as Spec,
      httpClientType: 'axios',
      extractRequestBody: true,
      primitiveTypeConstructs: (constructs) => ({
        ...constructs,
        // @ts-ignore
        string: {
          'date-time': 'Date',
        },
      }),
      unwrapResponseData: true,
      extractRequestParams: true,
      extractEnums: true,
      modular: true,
      fileNames: {
        dataContracts: 'api',
        routeTypes: 'routeTypes',
        httpClient: 'httpClient',
      },
    })

(We'd like to keep "noImplicitAny": true in our tsconfig)

WhoisUnknown commented 10 months ago

I have the same problem. skipLibCheck: true in tsconfig helped me. https://stackoverflow.com/a/39917362