Skip to content

Commit

Permalink
Merge pull request #3944 from 3scale/disable-sent-empty-value-by-default
Browse files Browse the repository at this point in the history
Disable 'Send empty value' checkbox by default
  • Loading branch information
mayorova authored Nov 20, 2024
2 parents 898ea9b + 480efb4 commit 3c65d41
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/javascript/src/ActiveDocs/ThreeScaleApiDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { autocompleteRequestInterceptor } from 'ActiveDocs/OAS3Autocomplete'
import type { AccountDataResponse, ApiDocsServices, BackendApiReportBody, BackendApiTransaction, BodyValue, BodyValueObject, FormData } from 'Types/SwaggerTypes'
import type { ExecuteData } from 'swagger-client/es/execute'
import type { SwaggerUIPlugin } from 'swagger-ui'
import type { Component } from 'react'
import type { SwaggerUIContext, ParameterIncludeEmptyProperties } from 'swagger-ui-utils'

const getApiSpecUrl = (baseUrl: string, specPath: string): string => {
return `${baseUrl.replace(/\/$/, '')}${specPath}`
Expand Down Expand Up @@ -118,6 +120,18 @@ const RequestBodyTransformerPlugin: SwaggerUIPlugin = () => {
}
}

const UncheckSendEmptyValuePlugin: SwaggerUIPlugin = () => {
return {
wrapComponents: {
// eslint-disable-next-line @typescript-eslint/naming-convention
ParameterIncludeEmpty: (originalComponent: Component, { React }: SwaggerUIContext ) => function ParameterIncludeEmptyWrapped (props: ParameterIncludeEmptyProperties) {
props.isIncludedOptions.defaultValue = false
return React.createElement(originalComponent, props)
}
}
}
}

export const renderSwaggerUI = async (container: HTMLElement, apiDocsPath: string, baseUrl: string, accountDataUrl: string): Promise<void> => {
const apiSpecs: ApiDocsServices = await fetchData<ApiDocsServices>(apiDocsPath)

Expand All @@ -134,7 +148,7 @@ export const renderSwaggerUI = async (container: HTMLElement, apiDocsPath: strin
requestInterceptor: (request) => autocompleteRequestInterceptor(request, accountData, ''),
tryItOutEnabled: true,
plugins: [
RequestBodyTransformerPlugin
RequestBodyTransformerPlugin, UncheckSendEmptyValuePlugin
]
})
})
Expand Down
19 changes: 19 additions & 0 deletions app/javascript/src/Types/swagger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,22 @@ declare module 'swagger-client/es/execute' {
function execute (req: ExecuteData): unknown
export { execute }
}

declare module 'swagger-ui-utils' {
import type { Component } from 'react'

export interface ReactType {
createElement: (Original: Component, props: ParameterIncludeEmptyProperties) => Component;
}

export interface SwaggerUIContext {
// eslint-disable-next-line @typescript-eslint/naming-convention
React: ReactType;
}

export interface ParameterIncludeEmptyProperties {
isIncludedOptions: {
defaultValue: boolean;
};
}
}

0 comments on commit 3c65d41

Please sign in to comment.