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 @@ -266,6 +266,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"));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
"license": "Unlicense",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
{{#supportsES6}}
"module": "./dist/esm/index.js",
"sideEffects": false,
{{/supportsES6}}
"scripts": {
"build": "tsc --outDir dist/",
"build": "tsc {{#supportsES6}}&& tsc -p tsconfig.esm.json{{/supportsES6}}",
Comment thread
macjohnny marked this conversation as resolved.
"prepare": "npm run build"
},
"dependencies": {
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 @@ -2,7 +2,7 @@
"compilerOptions": {
"declaration": true,
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
"module": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}CommonJS{{/supportsES6}}",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist",
"rootDir": ".",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.openapitools.codegen.typescript.axios;

import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen;
import org.openapitools.codegen.typescript.TypeScriptGroups;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

@Test(groups = {TypeScriptGroups.TYPESCRIPT, TypeScriptGroups.TYPESCRIPT_AXIOS})
public class TypeScriptAxiosClientCodegenTest {
Expand Down Expand Up @@ -80,4 +82,33 @@ public void testToEnumVarNameUpperCaseNamingType() {
assertEquals(codegen.toEnumVarName("b", "string"), "B");
}

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

codegen.additionalProperties().put("npmName", "@openapi/typescript-axios-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() {
TypeScriptAxiosClientCodegen codegen = new TypeScriptAxiosClientCodegen();

codegen.additionalProperties().put("npmName", "@openapi/typescript-axios-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 @@ -8,4 +8,5 @@ configuration.ts
git_push.sh
index.ts
package.json
tsconfig.esm.json
tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"license": "Unlicense",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"module": "./dist/esm/index.js",
"sideEffects": false,
"scripts": {
"build": "tsc --outDir dist/",
"build": "tsc && tsc -p tsconfig.esm.json",
"prepare": "npm run build"
},
"dependencies": {
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 @@ -2,7 +2,7 @@
"compilerOptions": {
"declaration": true,
"target": "ES6",
"module": "ES6",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist",
"rootDir": ".",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc --outDir dist/",
"build": "tsc ",
"prepare": "npm run build"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"declaration": true,
"target": "ES5",
"module": "CommonJS",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist",
"rootDir": ".",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"scripts": {
"build": "tsc --outDir dist/",
"build": "tsc ",
"prepare": "npm run build"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"declaration": true,
"target": "ES5",
"module": "CommonJS",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist",
"rootDir": ".",
Expand Down