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

[typescript-axios] Implement useSingleRequestParameter option #6288

Merged
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/typescript-axios-petstore-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
./bin/typescript-axios-petstore-with-npm-version.sh
./bin/typescript-axios-petstore-with-npm-version-and-separate-models-and-api.sh
./bin/typescript-axios-petstore-with-complex-headers.sh
./bin/typescript-axios-petstore-with-single-request-parameters.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also add a windows version to the corresponding bin/windows/typescript-axios-petstore-all.bat

./bin/typescript-axios-petstore-interfaces.sh
./bin/typescript-axios-petstore.sh
32 changes: 32 additions & 0 deletions bin/typescript-axios-petstore-with-single-request-parameters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn -B clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g typescript-axios -o samples/client/petstore/typescript-axios/builds/with-single-request-parameters --additional-properties useSingleRequestParameter=true $@"

java $JAVA_OPTS -jar $executable $ags
1 change: 1 addition & 0 deletions bin/windows/typescript-axios-petstore-all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
call bin\windows\typescript-axios-petstore.bat
call bin\windows\typescript-axios-petstore-target-es6.bat
call bin\windows\typescript-axios-petstore-with-complex-headers.bat
call bin\windows\typescript-axios-petstore-with-single-request-parameters.bat
call bin\windows\typescript-axios-petstore-with-npm-version.bat
call bin\windows\typescript-axios-petstore-interfaces.bat
call bin\windows\typescript-axios-petstore-with-npm-version-and-separate-models-and-api.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@ECHO OFF

set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g typescript-axios -o samples\client\petstore\typescript-axios\builds\with-single-request-parameters --additional-properties useSingleRequestParameter=true

java %JAVA_OPTS% -jar %executable% %ags%
1 change: 1 addition & 0 deletions docs/generators/typescript-axios.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sidebar_label: typescript-axios
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|supportsES6|Generate code that conforms to ES6.| |false|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
|withSeparateModelsAndApi|Put the model and api in separate folders and in separate classes| |false|
|withoutPrefixEnums|Don't prefix enum names with class names| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
public static final String WITH_INTERFACES = "withInterfaces";
public static final String SEPARATE_MODELS_AND_API = "withSeparateModelsAndApi";
public static final String WITHOUT_PREFIX_ENUMS = "withoutPrefixEnums";
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";

protected String npmRepository = null;

Expand All @@ -57,6 +58,7 @@ public TypeScriptAxiosClientCodegen() {
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(SEPARATE_MODELS_AND_API, "Put the model and api in separate folders and in separate classes", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(WITHOUT_PREFIX_ENUMS, "Don't prefix enum names with class names", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
}

@Override
Expand Down Expand Up @@ -205,7 +207,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
}
}
}

// Apply the model file name to the imports as well
for (Map<String, String> m : (List<Map<String, String>>) objs.get("imports")) {
String javaImport = m.get("import").substring(modelPackage.length() + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,31 @@ export interface {{classname}}Interface {
}

{{/withInterfaces}}
{{#useSingleRequestParameter}}
{{#operation}}
{{#allParams.0}}
/**
* Request parameters for {{nickname}} operation in {{classname}}.
* @export
* @interface {{classname}}{{operationIdCamelCase}}Request
*/
export interface {{classname}}{{operationIdCamelCase}}Request {
{{#allParams}}
/**
* {{description}}
* @type {{=<% %>=}}{<%&dataType%>}<%={{ }}=%>
* @memberof {{classname}}{{operationIdCamelCase}}
*/
readonly {{paramName}}{{^required}}?{{/required}}: {{{dataType}}}
{{^-last}}

{{/-last}}
{{/allParams}}
}

{{/allParams.0}}
{{/operation}}
{{/useSingleRequestParameter}}
/**
* {{classname}} - object-oriented interface{{#description}}
* {{{description}}}{{/description}}
Expand All @@ -311,17 +336,33 @@ export class {{classname}} extends BaseAPI {
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{#useSingleRequestParameter}}
{{#allParams.0}}
* @param {{=<% %>=}}{<%& classname %><%& operationIdCamelCase %>Request}<%={{ }}=%> requestParameters Request parameters.
{{/allParams.0}}
{{/useSingleRequestParameter}}
{{^useSingleRequestParameter}}
{{#allParams}}
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
{{/allParams}}
{{/useSingleRequestParameter}}
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof {{classname}}
*/
{{#useSingleRequestParameter}}
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}options?: any) {
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams.0}}{{#allParams}}requestParameters.{{paramName}}, {{/allParams}}{{/allParams.0}}options).then((request) => request(this.axios, this.basePath));
}
{{/useSingleRequestParameter}}
{{^useSingleRequestParameter}}
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options).then((request) => request(this.axios, this.basePath));
}
{{/useSingleRequestParameter}}
{{^-last}}

{{/-last}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@ export class PetApi extends BaseAPI {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, options?: any) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1313,7 +1312,6 @@ export class StoreApi extends BaseAPI {
public placeOrder(body: Order, options?: any) {
return StoreApiFp(this.configuration).placeOrder(body, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1953,7 +1951,6 @@ export class UserApi extends BaseAPI {
public updateUser(username: string, body: User, options?: any) {
return UserApiFp(this.configuration).updateUser(username, body, options).then((request) => request(this.axios, this.basePath));
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@ export class PetApi extends BaseAPI {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, options?: any) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1313,7 +1312,6 @@ export class StoreApi extends BaseAPI {
public placeOrder(body: Order, options?: any) {
return StoreApiFp(this.configuration).placeOrder(body, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1953,7 +1951,6 @@ export class UserApi extends BaseAPI {
public updateUser(username: string, body: User, options?: any) {
return UserApiFp(this.configuration).updateUser(username, body, options).then((request) => request(this.axios, this.basePath));
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,6 @@ export class PetApi extends BaseAPI {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, options?: any) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1368,7 +1367,6 @@ export class StoreApi extends BaseAPI {
public placeOrder(order: Order, options?: any) {
return StoreApiFp(this.configuration).placeOrder(order, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -2008,7 +2006,6 @@ export class UserApi extends BaseAPI {
public updateUser(username: string, user: User, options?: any) {
return UserApiFp(this.configuration).updateUser(username, user, options).then((request) => request(this.axios, this.basePath));
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ export class PetApi extends BaseAPI implements PetApiInterface {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, options?: any) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1453,7 +1452,6 @@ export class StoreApi extends BaseAPI implements StoreApiInterface {
public placeOrder(body: Order, options?: any) {
return StoreApiFp(this.configuration).placeOrder(body, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -2182,7 +2180,6 @@ export class UserApi extends BaseAPI implements UserApiInterface {
public updateUser(username: string, body: User, options?: any) {
return UserApiFp(this.configuration).updateUser(username, body, options).then((request) => request(this.axios, this.basePath));
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -762,5 +762,4 @@ export class PetApi extends BaseAPI {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, options?: any) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,4 @@ export class StoreApi extends BaseAPI {
public placeOrder(body: Order, options?: any) {
return StoreApiFp(this.configuration).placeOrder(body, options).then((request) => request(this.axios, this.basePath));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -656,5 +656,4 @@ export class UserApi extends BaseAPI {
public updateUser(username: string, body: User, options?: any) {
return UserApiFp(this.configuration).updateUser(username, body, options).then((request) => request(this.axios, this.basePath));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,6 @@ export class PetApi extends BaseAPI {
public uploadFile(petId: number, additionalMetadata?: string, file?: any, options?: any) {
return PetApiFp(this.configuration).uploadFile(petId, additionalMetadata, file, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1313,7 +1312,6 @@ export class StoreApi extends BaseAPI {
public placeOrder(body: Order, options?: any) {
return StoreApiFp(this.configuration).placeOrder(body, options).then((request) => request(this.axios, this.basePath));
}

}


Expand Down Expand Up @@ -1953,7 +1951,6 @@ export class UserApi extends BaseAPI {
public updateUser(username: string, body: User, options?: any) {
return UserApiFp(this.configuration).updateUser(username, body, options).then((request) => request(this.axios, this.basePath));
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
wwwroot/*.js
node_modules
typings
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0-SNAPSHOT
Loading