Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag skipDefaultUserAgent to skip setting user agent in TypeScrip… #20611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/configs/typescript-axios-es6-target.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ additionalProperties:
npmName: '@openapitools/typescript-axios-petstore'
npmRepository: https://skimdb.npmjs.com/registry
snapshot: false
skipDefaultUserAgent: true
1 change: 1 addition & 0 deletions docs/generators/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|paramNaming|Naming convention for parameters: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
|platform|Specifies the platform the code should run on. The default is 'node' for the 'request' framework and 'browser' otherwise.|<dl><dt>**browser**</dt><dd>browser</dd><dt>**node**</dt><dd>node</dd><dt>**deno**</dt><dd>deno</dd></dl>|browser|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|skipDefaultUserAgent|Skip setting default user-agent in configuration.ts| |false|
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class TypeScriptClientCodegen extends AbstractTypeScriptClientCodegen imp

private static final String USE_OBJECT_PARAMS_SWITCH = "useObjectParameters";
private static final String USE_OBJECT_PARAMS_DESC = "Use aggregate parameter objects as function arguments for api operations instead of passing each parameter as a separate function argument.";
public static final String SKIP_DEFAULT_USER_AGENT = "skipDefaultUserAgent";
public static final String SKIP_DEFAULT_USER_AGENT_DESC = "Skip setting default user-agent in configuration.ts";

private final Map<String, String> frameworkToHttpLibMap;

Expand Down Expand Up @@ -120,6 +122,7 @@ public TypeScriptClientCodegen() {
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_OBJECT_PARAMS_SWITCH, TypeScriptClientCodegen.USE_OBJECT_PARAMS_DESC).defaultValue("false"));
cliOptions.add(new CliOption(TypeScriptClientCodegen.USE_INVERSIFY_SWITCH, TypeScriptClientCodegen.USE_INVERSIFY_SWITCH_DESC).defaultValue("false"));
cliOptions.add(new CliOption(TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH, TypeScriptClientCodegen.IMPORT_FILE_EXTENSION_SWITCH_DESC));
cliOptions.add(new CliOption(TypeScriptClientCodegen.SKIP_DEFAULT_USER_AGENT, TypeScriptClientCodegen.SKIP_DEFAULT_USER_AGENT_DESC).defaultValue("false"));

CliOption frameworkOption = new CliOption(TypeScriptClientCodegen.FRAMEWORK_SWITCH, TypeScriptClientCodegen.FRAMEWORK_SWITCH_DESC);
for (String option : TypeScriptClientCodegen.FRAMEWORKS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ export class Configuration {
this.baseOptions = {
...param.baseOptions,
headers: {
{{^skipDefaultUserAgent}}
{{#httpUserAgent}}
'User-Agent': "{{httpUserAgent}}",
{{/httpUserAgent}}
{{/skipDefaultUserAgent}}
...param.baseOptions?.headers,
},
};
Expand Down