Skip to content

Commit

Permalink
🏷️ move swagger-client types to d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
josemigallas committed Apr 13, 2023
1 parent a7a2e45 commit 44a5be5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
5 changes: 3 additions & 2 deletions app/javascript/src/ActiveDocs/ThreeScaleApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { fetchData } from 'utilities/fetchData'
import { safeFromJsonString } from 'utilities/json-utils'
import { autocompleteRequestInterceptor } from 'ActiveDocs/OAS3Autocomplete'

import type { ApiDocsServices, BackendApiReportBody, BackendApiTransaction, BodyValue, BodyValueObject, FormData, ExecuteData } from 'Types/SwaggerTypes'
import type { ApiDocsServices, BackendApiReportBody, BackendApiTransaction, BodyValue, BodyValueObject, FormData } from 'Types/SwaggerTypes'
import type { ExecuteData } from 'swagger-client/es/execute'
import type { SwaggerUIPlugin } from 'swagger-ui'

const getApiSpecUrl = (baseUrl: string, specPath: string): string => {
Expand Down Expand Up @@ -110,7 +111,7 @@ const RequestBodyTransformerPlugin: SwaggerUIPlugin = () => {
&& req.requestBody) {
req.requestBody = transformReportRequestBody(req.requestBody as BackendApiReportBody)
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-call

return execute(req)
}
}
Expand Down
21 changes: 0 additions & 21 deletions app/javascript/src/Types/SwaggerTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { Request, Response, SupportedHTTPMethods } from 'swagger-ui'

export type AccountData = Record<string, {
name: string;
Expand All @@ -19,26 +18,6 @@ export interface ApiDocsServices {
apis: ApiDocsService[];
}

export interface ExecuteData {
contextUrl: string;
fetch: (arg: unknown) => unknown;
method: SupportedHTTPMethods;
operation: unknown;
operationId: string;
parameters: unknown;
pathName: string;
requestBody?: unknown;
requestContentType: string;
requestInterceptor?: ((request: Request) => Promise<Request> | Request) | undefined;
responseContentType: string;
responseInterceptor?: ((response: Response) => Promise<Response> | Response) | undefined;
scheme: string;
securities: unknown;
server: string;
serverVariables: unknown;
spec: unknown;
}

export interface BackendApiTransaction extends BodyValueObject {
app_id?: string;
user_key?: string;
Expand Down
26 changes: 25 additions & 1 deletion app/javascript/src/Types/swagger.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
// There are no official types for swagger-client. These has been inspired by:
// - https://github.com/swagger-api/swagger-js/blob/master/src/execute/index.js
declare module 'swagger-client/es/execute' {
export function execute (req: unknown): unknown
import type { Request, Response, SupportedHTTPMethods } from 'swagger-ui'

export interface ExecuteData {
contextUrl: string;
fetch: (arg: unknown) => unknown;
method: SupportedHTTPMethods;
operation: unknown;
operationId: string;
parameters: unknown;
pathName: string;
requestBody?: unknown;
requestContentType: string;
requestInterceptor?: ((request: Request) => Promise<Request> | Request) | undefined;
responseContentType: string;
responseInterceptor?: ((response: Response) => Promise<Response> | Response) | undefined;
scheme: string;
securities: unknown;
server: string;
serverVariables: unknown;
spec: unknown;
}
function execute (req: ExecuteData): unknown
export { execute }
}

0 comments on commit 44a5be5

Please sign in to comment.