Skip to content

Commit fc7e083

Browse files
tsiq-jeremywing328
authored andcommitted
Add interfaces option (#7831)
[TypeScript][Fetch] Add interfaces option
1 parent 40c30dd commit fc7e083

File tree

20 files changed

+2594
-132
lines changed

20 files changed

+2594
-132
lines changed

bin/typescript-fetch-petstore-all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
./bin/typescript-fetch-petstore-target-es6.sh
44
./bin/typescript-fetch-petstore-with-npm-version.sh
5+
./bin/typescript-fetch-petstore-interfaces.sh
56
./bin/typescript-fetch-petstore.sh
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-fetch -o samples/client/petstore/typescript-fetch/builds/with-interfaces -D withInterfaces=true"
30+
31+
java $JAVA_OPTS -jar $executable $ags

bin/windows/typescript-fetch-petstore-all.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
call bin\windows\typescript-fetch-petstore.bat
44
call bin\windows\typescript-fetch-petstore-target-es6.bat
55
call bin\windows\typescript-fetch-petstore-with-npm-version.bat
6+
call bin\windows\typescript-fetch-petstore-interfaces.bat
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@ECHO OFF
2+
3+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
4+
5+
If Not Exist %executable% (
6+
mvn clean package
7+
)
8+
9+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
10+
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -o samples\client\petstore\typescript-fetch\builds\with-interfaces -D withInterfaces=true
11+
12+
java %JAVA_OPTS% -jar %executable% %ags%

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
1818
public static final String NPM_VERSION = "npmVersion";
1919
public static final String NPM_REPOSITORY = "npmRepository";
2020
public static final String SNAPSHOT = "snapshot";
21+
public static final String WITH_INTERFACES = "withInterfaces";
2122

2223
protected String npmName = null;
2324
protected String npmVersion = "1.0.0";
@@ -37,6 +38,7 @@ public TypeScriptFetchClientCodegen() {
3738
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
3839
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
3940
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
41+
this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
4042
}
4143

4244
@Override

modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
8585
* @summary {{&summary}}
8686
{{/summary}}
8787
{{#allParams}}
88-
* @param {{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
88+
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
8989
{{/allParams}}
9090
* @param {*} [options] Override http request option.
9191
* @throws {RequiredError}
@@ -255,7 +255,7 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
255255
* @summary {{&summary}}
256256
{{/summary}}
257257
{{#allParams}}
258-
* @param {{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
258+
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
259259
{{/allParams}}
260260
* @param {*} [options] Override http request option.
261261
* @throws {RequiredError}
@@ -290,7 +290,7 @@ export const {{classname}}Factory = function (configuration?: Configuration, fet
290290
* @summary {{&summary}}
291291
{{/summary}}
292292
{{#allParams}}
293-
* @param {{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
293+
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
294294
{{/allParams}}
295295
* @param {*} [options] Override http request option.
296296
* @throws {RequiredError}
@@ -302,22 +302,54 @@ export const {{classname}}Factory = function (configuration?: Configuration, fet
302302
};
303303
};
304304
305+
{{#withInterfaces}}
306+
/**
307+
* {{classname}} - interface{{#description}}
308+
* {{&description}}{{/description}}
309+
* @export
310+
* @interface {{classname}}
311+
*/
312+
export interface {{classname}}Interface {
313+
{{#operation}}
314+
/**
315+
* {{&notes}}
316+
{{#summary}}
317+
* @summary {{&summary}}
318+
{{/summary}}
319+
{{#allParams}}
320+
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
321+
{{/allParams}}
322+
* @param {*} [options] Override http request option.
323+
* @throws {RequiredError}
324+
* @memberof {{classname}}Interface
325+
*/
326+
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}>;
327+
328+
{{/operation}}
329+
}
330+
331+
{{/withInterfaces}}
305332
/**
306333
* {{classname}} - object-oriented interface{{#description}}
307334
* {{{description}}}{{/description}}
308335
* @export
309336
* @class {{classname}}
310337
* @extends {BaseAPI}
311338
*/
339+
{{#withInterfaces}}
340+
export class {{classname}} extends BaseAPI implements {{classname}}Interface {
341+
{{/withInterfaces}}
342+
{{^withInterfaces}}
312343
export class {{classname}} extends BaseAPI {
344+
{{/withInterfaces}}
313345
{{#operation}}
314346
/**
315347
* {{&notes}}
316348
{{#summary}}
317349
* @summary {{&summary}}
318350
{{/summary}}
319351
{{#allParams}}
320-
* @param {{=<% %>=}}{<%%dataType%%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
352+
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
321353
{{/allParams}}
322354
* @param {*} [options] Override http request option.
323355
* @throws {RequiredError}

modules/swagger-codegen/src/main/resources/typescript-fetch/modelGeneric.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
1111
{{#vars}}
1212
/**
1313
* {{{description}}}
14-
* @type {{=<% %>=}}{<%datatype%>}<%={{ }}=%>
14+
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
1515
* @memberof {{classname}}
1616
*/
1717
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};

modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptFetchClientOptionsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public Map<String, String> createOptions() {
3333
.put(TypeScriptFetchClientCodegen.NPM_VERSION, NMP_VERSION)
3434
.put(TypeScriptFetchClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
3535
.put(TypeScriptFetchClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
36+
.put(TypeScriptFetchClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString())
3637
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
3738
.build();
3839
}

samples/client/petstore-security-test/typescript-fetch/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class FakeApi extends BaseAPI {
191191
/**
192192
*
193193
* @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
194-
* @param {} [testCodeInjectEndRnNR] To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
194+
* @param {string} [testCodeInjectEndRnNR] To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
195195
* @param {*} [options] Override http request option.
196196
* @throws {RequiredError}
197197
* @memberof FakeApi

0 commit comments

Comments
 (0)