Skip to content

Commit cb29904

Browse files
committed
Add tests, make UUID a type alias of string
1 parent 32551b2 commit cb29904

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

src/main/java/io/swagger/codegen/v3/generators/typescript/TypeScriptFetchClientCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public TypeScriptFetchClientCodegen() {
4444
this.cliOptions.add(new CliOption(WITH_INTERFACES,
4545
"Setting this property to true will generate interfaces next to the default class implementations.",
4646
SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
47+
48+
typeMapping.remove("UUID");
4749
}
4850

4951
@Override
@@ -76,6 +78,7 @@ public void processOpts() {
7678

7779
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
7880
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
81+
supportingFiles.add(new SupportingFile("api_test.mustache", "", "api_test.spec.ts"));
7982
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts"));
8083
supportingFiles.add(new SupportingFile("custom.d.mustache", "", "custom.d.ts"));
8184
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));

src/main/resources/handlebars/typescript-fetch/api.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export class RequiredError extends Error {
6767
}
6868
}
6969

70+
/**
71+
* Type aliases
72+
* @export
73+
* @type
74+
*/
75+
export type UUID = string
76+
7077
{{#models}}
7178
{{#model}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}{{/model}}
7279
{{/models}}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{>licenseInfo}}
2+
3+
import * as api from "./api"
4+
5+
{{#apiInfo}}
6+
{{#apis}}
7+
{{#operations}}
8+
describe("{{classname}}", () => {
9+
let instance: api.{{classname}}
10+
beforeEach(function() {
11+
instance = new api.{{classname}}()
12+
});
13+
14+
{{#operation}}
15+
test("{{operationId}}", () => {
16+
{{#allParams}}
17+
const {{{paramName}}}: {{^isPrimitiveType}}api.{{/isPrimitiveType}}{{{dataType}}} = {{#example}}{{#isString}}"{{{example}}}"{{/isString}}{{#isUuid}}"{{{example}}}"{{/isUuid}}{{^isUuid}}{{^isString}}{{{example}}}{{/isString}}{{/isUuid}}{{/example}}{{^example}}undefined{{/example}}
18+
{{/allParams}}
19+
expect(instance.{{operationId}}({{#allParams}}{{{paramName}}}, {{/allParams}}{})).toBe(null)
20+
})
21+
{{/operation}}
22+
})
23+
24+
{{/operations}}
25+
{{/apis}}
26+
{{/apiInfo}}

src/main/resources/handlebars/typescript-fetch/licenseInfo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
66
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
77
*
8-
* NOTE: This class is auto generated by the swagger code generator program.
8+
* NOTE: This file is auto generated by the swagger code generator program.
99
* https://github.com/swagger-api/swagger-codegen.git
10-
* Do not edit the class manually.
10+
* Do not edit the file manually.
1111
*/

src/main/resources/handlebars/typescript-fetch/package.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
"portable-fetch": "^3.0.0"
2121
},
2222
"devDependencies": {
23-
"@types/node": "^8.0.9",
24-
"typescript": "^2.0"
23+
"@types/jest": "^25.2.1",
24+
"@types/node": "^13.13.0",
25+
"jest": "^25.4.0",
26+
"typescript": "^3.8.3"
2527
}{{#npmRepository}},{{/npmRepository}}
2628
{{#npmRepository}}
2729
"publishConfig":{

0 commit comments

Comments
 (0)