Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ private void addNpmPackageGeneration() {
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
// in case ECMAScript 6 is supported add another tsconfig for an ESM (ECMAScript Module)
if (supportsES6) {
supportingFiles.add(new SupportingFile("tsconfig.esm.mustache", "", "tsconfig.esm.json"));
}
supportingFiles.add(new SupportingFile("npmignore.mustache", "", ".npmignore"));
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
{{^packageAsSourceOnlyLibrary}}
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
{{#supportsES6}}
"module": "./dist/esm/index.js",
"sideEffects": false,
{{/supportsES6}}
"scripts": {
"build": "tsc"{{^sagasAndRecords}},
"prepare": "npm run build"
{{/sagasAndRecords}}
"build": "tsc{{#supportsES6}} && tsc -p tsconfig.esm.json{{/supportsES6}}"{{^sagasAndRecords}},
"prepare": "npm run build"{{/sagasAndRecords}}
},
{{/packageAsSourceOnlyLibrary}}
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.*;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.TestUtils;
import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen;
import org.openapitools.codegen.utils.ModelUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class TypeScriptFetchClientCodegenTest {
@Test
Expand Down Expand Up @@ -102,4 +104,33 @@ public void getTypeDeclarationTest() {
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }");
}

@Test
public void containsESMTSConfigFileInCaseOfES6AndNPM() {
TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();

codegen.additionalProperties().put("npmName", "@openapi/typescript-fetch-petstore");
codegen.additionalProperties().put("snapshot", false);
codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT");
codegen.setSupportsES6(true);

codegen.processOpts();

assertThat(codegen.supportingFiles()).contains(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
assertThat(codegen.supportingFiles()).contains(new SupportingFile("tsconfig.esm.mustache", "", "tsconfig.esm.json"));
}

@Test
public void doesNotContainESMTSConfigFileInCaseOfES5AndNPM() {
TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen();

codegen.additionalProperties().put("npmName", "@openapi/typescript-fetch-petstore");
codegen.additionalProperties().put("snapshot", false);
codegen.additionalProperties().put("npmVersion", "1.0.0-SNAPSHOT");
codegen.setSupportsES6(false);

codegen.processOpts();

assertThat(codegen.supportingFiles()).contains(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
assertThat(codegen.supportingFiles()).doesNotContain(new SupportingFile("tsconfig.esm.mustache", "", "tsconfig.esm.json"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ src/models/Tag.ts
src/models/User.ts
src/models/index.ts
src/runtime.ts
tsconfig.esm.json
tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"author": "OpenAPI-Generator",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"module": "./dist/esm/index.js",
"sideEffects": false,
"scripts": {
"build": "tsc",
"build": "tsc && tsc -p tsconfig.esm.json",
"prepare": "npm run build"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ src/models/WarningCodeRecord.ts
src/models/index.ts
src/runtime.ts
src/runtimeSagasAndRecords.ts
tsconfig.esm.json
tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
"author": "OpenAPI-Generator",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"module": "./dist/esm/index.js",
"sideEffects": false,
"scripts": {
"build": "tsc" },
"build": "tsc && tsc -p tsconfig.esm.json"
},
"devDependencies": {
"immutable": "^4.0.0-rc.12",
"normalizr": "^3.6.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm"
}
}