mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
* add ESM support to typescript-axios client * add module path to the package json template * module must be commonjs * generate samples
This commit is contained in:
@@ -266,6 +266,10 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
|
||||
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
|
||||
|
||||
@@ -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}}",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
7
modules/openapi-generator/src/main/resources/typescript-axios/tsconfig.esm.mustache
vendored
Normal file
7
modules/openapi-generator/src/main/resources/typescript-axios/tsconfig.esm.mustache
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"outDir": "dist/esm"
|
||||
}
|
||||
}
|
||||
@@ -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": ".",
|
||||
|
||||
@@ -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 {
|
||||
@@ -80,4 +82,33 @@ public class TypeScriptAxiosClientCodegenTest {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ configuration.ts
|
||||
git_push.sh
|
||||
index.ts
|
||||
package.json
|
||||
tsconfig.esm.json
|
||||
tsconfig.json
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"outDir": "dist/esm"
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "ES6",
|
||||
"module": "ES6",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "ES5",
|
||||
"module": "CommonJS",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "ES5",
|
||||
"module": "CommonJS",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": ".",
|
||||
|
||||
Reference in New Issue
Block a user