Skip to content

Commit

Permalink
Fix OpenAPITools#3349 : [typescript-fetch] Proposition to follow spec (
Browse files Browse the repository at this point in the history
…OpenAPITools#3351)

* Fix 3349 : Proposition to follow spec closely

* Fix OpenAPITools#3349 : Changes suggested by code review. Add an option for the single request parameter.

* Fix OpenAPITools#3349 : Add sample with the use of the single request parameter

* Fix OpenAPITools#3349 : Small fix that wasn't passing the tests

* Fix OpenAPITools#3349 : Remove cariage return that might create an error

* Fix OpenAPITools#3349 : Add chmod to make new sh file executable and fix the CircleCI issue

* Fix OpenAPITools#3349 : Add windows sample generation

* Fix OpenAPITools#3349 : Rename everything because of default value change

* Fix OpenAPITools#3349 : Indentation fix

* Fix OpenAPITools#3349 : Add 755 to typescript-fetch-petstore-multiple-parameters.sh

* Fix OpenAPITools#3349 : Auto generation of the documentations

* Fix OpenAPITools#3349 : Revert back a change that was auto-generated.
  • Loading branch information
JFCote authored and macjohnny committed Jul 17, 2019
1 parent 8417c5b commit 610ca28
Show file tree
Hide file tree
Showing 53 changed files with 2,046 additions and 2,776 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>TypeScriptAngularBuildPestoreClientTests</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>TS Fetch Multiple Parameters Petstore Client</name>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions bin/typescript-fetch-petstore-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
./bin/typescript-fetch-petstore-with-npm-version.sh
./bin/typescript-fetch-petstore-interfaces.sh
./bin/typescript-fetch-petstore.sh
./bin/typescript-fetch-petstore-multiple-parameters.sh
4 changes: 4 additions & 0 deletions bin/typescript-fetch-petstore-multiple-parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"snapshot" : false,
"useSingleRequestParameter": false
}
34 changes: 34 additions & 0 deletions bin/typescript-fetch-petstore-multiple-parameters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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-fetch -c bin/typescript-fetch-petstore-multiple-parameters.json -o samples/client/petstore/typescript-fetch/builds/multiple-parameters $@"

java $JAVA_OPTS -jar $executable $ags
cp CI/samples.ci/client/petstore/typescript-fetch/builds/multiple-parameters/pom.xml samples/client/petstore/typescript-fetch/builds/multiple-parameters/pom.xml
cp CI/samples.ci/client/petstore/typescript-fetch/tests/default/pom.xml samples/client/petstore/typescript-fetch/tests/default/pom.xml
1 change: 1 addition & 0 deletions bin/windows/typescript-fetch-petstore-all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ call bin\windows\typescript-fetch-petstore.bat
call bin\windows\typescript-fetch-petstore-target-es6.bat
call bin\windows\typescript-fetch-petstore-with-npm-version.bat
call bin\windows\typescript-fetch-petstore-interfaces.bat
call bin\windows\typescript-fetch-petstore-multiple-parameters.bat
12 changes: 12 additions & 0 deletions bin/windows/typescript-fetch-petstore-multiple-parameters.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-fetch -c bin\typescript-fetch-petstore-multiple-parameters.json -o samples\client\petstore\typescript-fetch\builds\multiple-parameters

java %JAVA_OPTS% -jar %executable% %ags%
1 change: 1 addition & 0 deletions docs/generators/typescript-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ sidebar_label: typescript-fetch
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |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.| |true|
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@
import org.openapitools.codegen.utils.ModelUtils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.TreeSet;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {

public static final String NPM_REPOSITORY = "npmRepository";
public static final String WITH_INTERFACES = "withInterfaces";
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";

protected String npmRepository = null;
private boolean useSingleRequestParameter = true;

public TypeScriptFetchClientCodegen() {
super();
Expand All @@ -56,6 +55,7 @@ public TypeScriptFetchClientCodegen() {

this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
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(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.TRUE.toString()));
}

@Override
Expand Down Expand Up @@ -87,6 +87,12 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("models.index.mustache", modelPackage().replace('.', File.separatorChar), "index.ts"));
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));

if (additionalProperties.containsKey(USE_SINGLE_REQUEST_PARAMETER)) {
this.setUseSingleRequestParameter(convertPropertyToBoolean(USE_SINGLE_REQUEST_PARAMETER));
}
writePropertyBack(USE_SINGLE_REQUEST_PARAMETER, getUseSingleRequestParameter());

if (additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration();
}
Expand Down Expand Up @@ -245,4 +251,12 @@ private void addExtraReservedWords() {
this.reservedWords.add("BlobApiResponse");
this.reservedWords.add("TextApiResponse");
}

private boolean getUseSingleRequestParameter() {
return useSingleRequestParameter;
}

private void setUseSingleRequestParameter(boolean useSingleRequestParameter) {
this.useSingleRequestParameter = useSingleRequestParameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,26 @@ export class {{classname}} extends runtime.BaseAPI {
{{/returnType}}
}

/**
{{#notes}}
* {{&notes}}
{{/notes}}
{{#summary}}
* {{&summary}}
{{/summary}}
*/
/**
{{#notes}}
* {{&notes}}
{{/notes}}
{{#summary}}
* {{&summary}}
{{/summary}}
*/
{{^useSingleRequestParameter}}
async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
{{#returnType}}
const response = await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} }{{/allParams.0}});
return await response.value();
{{/returnType}}
{{^returnType}}
await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} }{{/allParams.0}});
{{/returnType}}
}
{{/useSingleRequestParameter}}
{{#useSingleRequestParameter}}
async {{nickname}}({{#allParams.0}}requestParameters: {{operationIdCamelCase}}Request{{/allParams.0}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
{{#returnType}}
const response = await this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}});
Expand All @@ -246,6 +258,7 @@ export class {{classname}} extends runtime.BaseAPI {
await this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}});
{{/returnType}}
}
{{/useSingleRequestParameter}}

{{/operation}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Map<String, String> createOptions() {
.put(TypeScriptFetchClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
.put(TypeScriptFetchClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
.put(TypeScriptFetchClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString())
.put(TypeScriptFetchClientCodegen.USE_SINGLE_REQUEST_PARAMETER, Boolean.FALSE.toString())
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
.build();
Expand Down
Loading

0 comments on commit 610ca28

Please sign in to comment.