diff --git a/generator/konfig-dash/.changeset/cold-carrots-attend.md b/generator/konfig-dash/.changeset/cold-carrots-attend.md new file mode 100644 index 0000000000..f5536f8bc7 --- /dev/null +++ b/generator/konfig-dash/.changeset/cold-carrots-attend.md @@ -0,0 +1,5 @@ +--- +'konfig-lib': minor +--- + +support globally required security in TypeScript SDK diff --git a/generator/konfig-dash/packages/konfig-lib/src/__snapshots__/transformSpec.test.ts.snap b/generator/konfig-dash/packages/konfig-lib/src/__snapshots__/transformSpec.test.ts.snap index 3b54edd4f5..311a1f23e0 100644 --- a/generator/konfig-dash/packages/konfig-lib/src/__snapshots__/transformSpec.test.ts.snap +++ b/generator/konfig-dash/packages/konfig-lib/src/__snapshots__/transformSpec.test.ts.snap @@ -29,6 +29,7 @@ info: version: 3.0.0 x-konfig-ignore: object-with-no-properties: true + x-konfig-has-globally-required-security: true servers: - description: Production server url: https://api.humanloop.com/v3 @@ -5351,6 +5352,7 @@ info: email: api@snaptrade.com x-konfig-ignore: potential-incorrect-type: true + x-konfig-has-globally-required-security: true servers: - description: SnapTrade Production API url: https://api.snaptrade.com/api/v1 @@ -15134,6 +15136,7 @@ info: x-konfig-ignore: object-with-no-properties: true potential-incorrect-type: true + x-konfig-has-globally-required-security: true x-konfig-uses-multipart-form-data: true servers: - url: https://in.staging.decentro.tech @@ -22760,6 +22763,7 @@ info: potential-incorrect-type: true contact: email: admin@decentro.tech + x-konfig-has-globally-required-security: true x-konfig-uses-multipart-form-data: true servers: - url: https://in.staging.decentro.tech @@ -30491,6 +30495,7 @@ info: potential-incorrect-type: true contact: name: Decentro + x-konfig-has-globally-required-security: true x-konfig-uses-multipart-form-data: true servers: - url: https://in.staging.decentro.tech @@ -38222,6 +38227,7 @@ info: potential-incorrect-type: true contact: url: https://decentro.tech + x-konfig-has-globally-required-security: true x-konfig-uses-multipart-form-data: true servers: - url: https://in.staging.decentro.tech @@ -46108,6 +46114,7 @@ info: x-konfig-ignore: object-with-no-properties: true potential-incorrect-type: true + x-konfig-has-globally-required-security: true servers: - url: https://in.staging.decentro.tech tags: @@ -48216,6 +48223,7 @@ info: version: 1.0.0 x-konfig-ignore: potential-incorrect-type: true + x-konfig-has-globally-required-security: true servers: - url: https://api.nlite.ml/v1.0 tags: @@ -102397,6 +102405,7 @@ info: version: 3.0.0 x-konfig-ignore: object-with-no-properties: true + x-konfig-has-globally-required-security: true servers: - description: Production server url: https://api.humanloop.com/v3 @@ -107712,6 +107721,7 @@ info: x-konfig-ignore: object-with-no-properties: true potential-incorrect-type: true + x-konfig-has-globally-required-security: true x-konfig-uses-multipart-form-data: true servers: - url: https://in.staging.decentro.tech @@ -115509,6 +115519,7 @@ info: version: 3.0.0 x-konfig-ignore: object-with-no-properties: true + x-konfig-has-globally-required-security: true servers: - description: Production server url: https://api.humanloop.com/v3 @@ -120834,6 +120845,7 @@ info: email: api@snaptrade.com x-konfig-ignore: potential-incorrect-type: true + x-konfig-has-globally-required-security: true servers: - description: SnapTrade Production API url: https://api.snaptrade.com/api/v1 @@ -129590,6 +129602,7 @@ info: x-konfig-ignore: object-with-no-properties: true potential-incorrect-type: true + x-konfig-has-globally-required-security: true servers: - url: https://in.staging.decentro.tech tags: @@ -131749,6 +131762,7 @@ info: x-konfig-ignore: object-with-no-properties: true potential-incorrect-type: true + x-konfig-has-globally-required-security: true x-konfig-uses-multipart-form-data: true servers: - url: https://in.staging.decentro.tech @@ -139922,6 +139936,7 @@ info: version: 3.0.0 x-konfig-ignore: object-with-no-properties: true + x-konfig-has-globally-required-security: true servers: - description: Production server url: https://api.humanloop.com/v3 @@ -145255,6 +145270,7 @@ info: contact: email: team@newscatcherapi.com version: 1.0.1 + x-konfig-has-globally-required-security: true externalDocs: description: Find out more about NewsCatcher url: https://docs.newscatcherapi.com/ diff --git a/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts b/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts index 64b4292166..276feeda31 100644 --- a/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts +++ b/generator/konfig-dash/packages/konfig-lib/src/transformSpec.ts @@ -359,10 +359,15 @@ export const transformSpec = async ({ return security in requirements }) : false + const isRequired = + isGloballyRequired || securityCount[security] === operations.length Object.assign(spec.spec.components.securitySchemes[security], { - 'x-konfig-globally-required-security': - isGloballyRequired || securityCount[security] === operations.length, + 'x-konfig-globally-required-security': isRequired, }) + if (isRequired) + Object.assign(spec.spec.info, { + 'x-konfig-has-globally-required-security': isRequired, + }) } } diff --git a/generator/konfig-generator-api/src/main/resources/typescript-axios/api_doc_example_setup.mustache b/generator/konfig-generator-api/src/main/resources/typescript-axios/api_doc_example_setup.mustache index d3f3d054e8..abd65fa642 100644 --- a/generator/konfig-generator-api/src/main/resources/typescript-axios/api_doc_example_setup.mustache +++ b/generator/konfig-generator-api/src/main/resources/typescript-axios/api_doc_example_setup.mustache @@ -7,10 +7,6 @@ const {{{clientNameLowercase}}} = new {{{clientName}}}({ {{{apiDocumentationAuthenticationPartial}}} {{/apiDocumentationAuthenticationPartial}} {{^apiDocumentationAuthenticationPartial}} -{{#includeFetchAdapter}} - // Use native Fetch API instead of axios - // useFetch: true, -{{/includeFetchAdapter}} {{> api_doc_example_setup_parameters}} {{/apiDocumentationAuthenticationPartial}} }) \ No newline at end of file diff --git a/generator/konfig-generator-api/src/main/resources/typescript-axios/client.mustache b/generator/konfig-generator-api/src/main/resources/typescript-axios/client.mustache index a3dae04649..1e8174588a 100644 --- a/generator/konfig-generator-api/src/main/resources/typescript-axios/client.mustache +++ b/generator/konfig-generator-api/src/main/resources/typescript-axios/client.mustache @@ -18,7 +18,7 @@ export class {{{clientName}}} extends {{{clientName}}}Custom { readonly {{> apiClassName}}: {{classname}}; {{/apis}} - constructor(configurationParameters: ConfigurationParameters = {}) { + constructor(configurationParameters: ConfigurationParameters{{> configuration_default}}) { super(configurationParameters); const configuration = new Configuration(configurationParameters); {{#apis}} diff --git a/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration.mustache b/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration.mustache index 826dd0c553..93b1f3af8b 100644 --- a/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration.mustache +++ b/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration.mustache @@ -24,7 +24,7 @@ export interface ConfigurationParameters { {{> securityKeyName}}?: string; {{/apiKeyMethods}} {{/hasMultipleApiKeys}} - apiKey?: ApiKey; + {{> configuration_api_key}} username?: string; password?: string; accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); @@ -55,12 +55,7 @@ export class Configuration { */ {{{name}}}?: string; {{/clientStateWithExamples}} - /** - * parameter for apiKey security - * @param name security name - * @memberof Configuration - */ - apiKey?: ApiKey; + {{> configuration_api_key}} /** * parameter for basic security * @@ -123,7 +118,7 @@ export class Configuration { */ userAgent: string; - constructor(param: ConfigurationParameters = {}) { + constructor(param: ConfigurationParameters{{> configuration_default}}) { {{#clientState}} this.{{{.}}} = param.{{{.}}} {{/clientState}} @@ -146,7 +141,7 @@ export class Configuration { this.basePath = param.basePath; this.baseOptions = param.baseOptions ?? {}; {{#includeFetchAdapter}} - if (param.useFetch) { + if (param.useFetch ?? true) { this.baseOptions["adapter"] = fetchAdapter } {{/includeFetchAdapter}} diff --git a/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration_api_key.mustache b/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration_api_key.mustache new file mode 100644 index 0000000000..a1c02524bc --- /dev/null +++ b/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration_api_key.mustache @@ -0,0 +1,8 @@ +{{^hasMultipleApiKeys}} +{{#apiKeyMethods}} +/** + * parameter for apiKey security + * @param name security name + * @memberof Configuration + */ +apiKey{{^vendorExtensions.x-konfig-globally-required-security}}?{{/vendorExtensions.x-konfig-globally-required-security}}: ApiKey;{{/apiKeyMethods}}{{/hasMultipleApiKeys}} \ No newline at end of file diff --git a/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration_default.mustache b/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration_default.mustache new file mode 100644 index 0000000000..c7604e5c1e --- /dev/null +++ b/generator/konfig-generator-api/src/main/resources/typescript-axios/configuration_default.mustache @@ -0,0 +1 @@ +{{^infoExtensions.x-konfig-has-globally-required-security}} = {}{{/infoExtensions.x-konfig-has-globally-required-security}} \ No newline at end of file