Skip to content

Commit 9e659d1

Browse files
JFCotemacjohnny
authored andcommitted
Fix NPM build for Typescript-fetch (#3403)
* -Fix bug in fetch -> Missing "runtime" -Move fetch files to an "src" folder instead of doing everything at the root which removes the bugs when using the library itself -Fix the distribution of fetch using npm * Move the .ts files to an `src` folder which is more common in npm package * Add missing mustache * Add missing .npmignore
1 parent b8295af commit 9e659d1

78 files changed

Lines changed: 12 additions & 14 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public TypeScriptFetchClientCodegen() {
5050
outputFolder = "generated-code/typescript-fetch";
5151
embeddedTemplateDir = templateDir = "typescript-fetch";
5252

53-
this.apiPackage = "apis";
53+
this.apiPackage = "src" + File.separator +"apis";
54+
this.modelPackage = "src" + File.separator + "models";
5455
this.apiTemplateFiles.put("apis.mustache", ".ts");
55-
this.modelPackage = "models";
5656
this.modelTemplateFiles.put("models.mustache", ".ts");
5757
this.addExtraReservedWords();
5858

@@ -84,8 +84,8 @@ public void processOpts() {
8484
super.processOpts();
8585
additionalProperties.put("isOriginalModelPropertyNaming", getModelPropertyNaming().equals("original"));
8686
additionalProperties.put("modelPropertyNaming", getModelPropertyNaming());
87-
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
88-
supportingFiles.add(new SupportingFile("runtime.mustache", "", "runtime.ts"));
87+
supportingFiles.add(new SupportingFile("index.mustache", "src", "index.ts"));
88+
supportingFiles.add(new SupportingFile("runtime.mustache", "src", "runtime.ts"));
8989
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
9090
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
9191

@@ -188,6 +188,7 @@ private void addNpmPackageGeneration() {
188188
//Files for building our lib
189189
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
190190
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
191+
supportingFiles.add(new SupportingFile("npmignore.mustache", "", ".npmignore"));
191192
}
192193

193194
@Override
@@ -216,7 +217,7 @@ private void addOperationModelImportInfomation(Map<String, Object> operations) {
216217
// models for a given operation.
217218
List<Map<String, Object>> imports = (List<Map<String, Object>>) operations.get("imports");
218219
for (Map<String, Object> im : imports) {
219-
im.put("className", im.get("import").toString().replace("models.", ""));
220+
im.put("className", im.get("import").toString().replace(modelPackage() + ".", ""));
220221
}
221222
}
222223

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

modules/openapi-generator/src/main/resources/typescript-fetch/package.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "./dist/index.js",
77
"typings": "./dist/index.d.ts",
88
"scripts" : {
9-
"build": "tsc --outDir dist/",
9+
"build": "tsc",
1010
"prepare": "npm run build"
1111
},
1212
"devDependencies": {

modules/openapi-generator/src/main/resources/typescript-fetch/tsconfig.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"module": "commonjs",
66
"moduleResolution": "node",
77
"outDir": "dist",
8-
"rootDir": ".",
98
{{^supportsES6}}
109
"lib": [
1110
"es6",

samples/client/petstore/typescript-fetch/builds/default/apis/PetApi.ts renamed to samples/client/petstore/typescript-fetch/builds/default/src/apis/PetApi.ts

File renamed without changes.

samples/client/petstore/typescript-fetch/builds/default/apis/StoreApi.ts renamed to samples/client/petstore/typescript-fetch/builds/default/src/apis/StoreApi.ts

File renamed without changes.

samples/client/petstore/typescript-fetch/builds/default/apis/UserApi.ts renamed to samples/client/petstore/typescript-fetch/builds/default/src/apis/UserApi.ts

File renamed without changes.

samples/client/petstore/typescript-fetch/builds/default/apis/index.ts renamed to samples/client/petstore/typescript-fetch/builds/default/src/apis/index.ts

File renamed without changes.

samples/client/petstore/typescript-fetch/builds/default/index.ts renamed to samples/client/petstore/typescript-fetch/builds/default/src/index.ts

File renamed without changes.

samples/client/petstore/typescript-fetch/builds/default/models/Category.ts renamed to samples/client/petstore/typescript-fetch/builds/default/src/models/Category.ts

File renamed without changes.

0 commit comments

Comments
 (0)