swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

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

Open aphofstede opened this issue 2 years ago • 1 comments

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 TS7016: 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)

aphofstede avatar Jul 11 '23 22:07 aphofstede

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

WhoisUnknown avatar Oct 17 '23 18:10 WhoisUnknown