diff --git a/__fixtures__/output/swagger-client.merged.ts b/__fixtures__/output/swagger-client.merged.ts index cb648c4..99a47ef 100644 --- a/__fixtures__/output/swagger-client.merged.ts +++ b/__fixtures__/output/swagger-client.merged.ts @@ -1,4 +1,4 @@ -import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; export interface MutatingWebhook { admissionReviewVersions: string[]; clientConfig: WebhookClientConfig; @@ -10199,7 +10199,7 @@ export interface LogFileHandlerRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { diff --git a/__fixtures__/output/swagger-client.ts b/__fixtures__/output/swagger-client.ts index a830150..881ed0e 100644 --- a/__fixtures__/output/swagger-client.ts +++ b/__fixtures__/output/swagger-client.ts @@ -1,4 +1,4 @@ -import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; /* io.k8s.api.admissionregistration.v1.MutatingWebhook */ /* MutatingWebhook describes an admission webhook and the resources and operations it applies to. */ export interface MutatingWebhook { @@ -11592,7 +11592,7 @@ export interface LogFileHandlerRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { diff --git a/__fixtures__/output/swagger-extended-client.merged.ts b/__fixtures__/output/swagger-extended-client.merged.ts index 3ce5d3c..85de1ec 100644 --- a/__fixtures__/output/swagger-extended-client.merged.ts +++ b/__fixtures__/output/swagger-extended-client.merged.ts @@ -1,4 +1,4 @@ -import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; export interface Alertmanager { apiVersion?: string; kind?: string; @@ -33376,7 +33376,7 @@ export interface WatchStorageV1VolumeAttachmentRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { diff --git a/__fixtures__/output/swagger-extended-client.ts b/__fixtures__/output/swagger-extended-client.ts index 9c09aa0..2b754b3 100644 --- a/__fixtures__/output/swagger-extended-client.ts +++ b/__fixtures__/output/swagger-extended-client.ts @@ -1,4 +1,4 @@ -import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; /* com.coreos.monitoring.v1.Alertmanager */ /* The `Alertmanager` custom resource definition (CRD) defines a desired [Alertmanager](https://prometheus.io/docs/alerting) setup to run in a Kubernetes cluster. It allows to specify many options such as the number of replicas, persistent storage and many more. @@ -38192,7 +38192,7 @@ export interface WatchStorageV1VolumeAttachmentRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { diff --git a/packages/schema-sdk/__tests__/__snapshots__/openapi.extended.generate.test.ts.snap b/packages/schema-sdk/__tests__/__snapshots__/openapi.extended.generate.test.ts.snap index bd735b5..b85b6b6 100644 --- a/packages/schema-sdk/__tests__/__snapshots__/openapi.extended.generate.test.ts.snap +++ b/packages/schema-sdk/__tests__/__snapshots__/openapi.extended.generate.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`merged 1`] = ` -"import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +"import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; export interface Alertmanager { apiVersion?: string; kind?: string; @@ -33379,7 +33379,7 @@ export interface WatchStorageV1VolumeAttachmentRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { @@ -37854,7 +37854,7 @@ export class KubernetesClient extends APIClient { `; exports[`swagger 1`] = ` -"import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +"import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; /* com.coreos.monitoring.v1.Alertmanager */ /* The \`Alertmanager\` custom resource definition (CRD) defines a desired [Alertmanager](https://prometheus.io/docs/alerting) setup to run in a Kubernetes cluster. It allows to specify many options such as the number of replicas, persistent storage and many more. @@ -76048,7 +76048,7 @@ export interface WatchStorageV1VolumeAttachmentRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { diff --git a/packages/schema-sdk/__tests__/__snapshots__/openapi.generate.test.ts.snap b/packages/schema-sdk/__tests__/__snapshots__/openapi.generate.test.ts.snap index c68ddb7..9659525 100644 --- a/packages/schema-sdk/__tests__/__snapshots__/openapi.generate.test.ts.snap +++ b/packages/schema-sdk/__tests__/__snapshots__/openapi.generate.test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`merged 1`] = ` -"import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +"import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; export interface MutatingWebhook { admissionReviewVersions: string[]; clientConfig: WebhookClientConfig; @@ -10202,7 +10202,7 @@ export interface LogFileHandlerRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { @@ -13345,7 +13345,7 @@ export class KubernetesClient extends APIClient { `; exports[`swagger 1`] = ` -"import { APIClient, APIClientRequestOpts } from "@interweb/fetch-api-client"; +"import { APIClient, APIClientRequestOpts, APIClientOptions } from "@interweb/fetch-api-client"; /* io.k8s.api.admissionregistration.v1.MutatingWebhook */ /* MutatingWebhook describes an admission webhook and the resources and operations it applies to. */ export interface MutatingWebhook { @@ -24939,7 +24939,7 @@ export interface LogFileHandlerRequest { export interface GetServiceAccountIssuerOpenIDKeysetRequest {} export interface GetCodeVersionRequest {} export class KubernetesClient extends APIClient { - constructor(options) { + constructor(options: APIClientOptions) { super(options); } async getSwaggerJSON() { diff --git a/packages/schema-sdk/src/openapi.ts b/packages/schema-sdk/src/openapi.ts index 643b75b..a4c518a 100644 --- a/packages/schema-sdk/src/openapi.ts +++ b/packages/schema-sdk/src/openapi.ts @@ -608,11 +608,16 @@ export function generateOpenApiClient( } methods.push(...generateMethods(options, patchedSchema)); + const constructorOptionsParam = t.identifier('options'); + constructorOptionsParam.typeAnnotation = t.tsTypeAnnotation( + t.tsTypeReference(t.identifier('APIClientOptions')) + ); + const classBody = t.classBody([ t.classMethod( 'constructor', t.identifier('constructor'), - [t.identifier('options')], + [constructorOptionsParam], t.blockStatement([ t.expressionStatement( t.callExpression(t.super(), [t.identifier('options')]) @@ -656,6 +661,10 @@ export function generateOpenApiClient( t.identifier('APIClientRequestOpts'), t.identifier('APIClientRequestOpts') ), + t.importSpecifier( + t.identifier('APIClientOptions'), + t.identifier('APIClientOptions') + ), ], t.stringLiteral(options.npmApiClient) ),