Skip to content

Commit e2656ff

Browse files
authored
Merge pull request #1204 from swagger-api/DonIsaac-master
typescript-axios pr conflict tweak
2 parents 059c507 + 6452f0c commit e2656ff

File tree

7 files changed

+127
-22
lines changed

7 files changed

+127
-22
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Log file
55
*.log
66

7+
# Temporary files
8+
*.tmp
9+
tmp/
10+
711
# BlueJ files
812
*.ctxt
913

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
## Overview
88
**Swagger Codegen Generators** project is a set of classes and templates ([Handlebars](https://jknack.github.io/handlebars.java)) used by [Swagger Codegen 3.0.0 project](https://github.com/swagger-api/swagger-codegen/tree/3.0.0) in its code generation process for a specific language or language framework. The main differents with **Swagger Codegen 2.x.x** are:
99

10-
- **Handlebars as template engine:** with Handelbars feature is possible to create more logic-less templates.
10+
- **Handlebars as template engine:** with Handlebars feature is possible to create more logic-less templates.
1111
- **OAS 3 support:** generator classes work with OpenAPI Specification V3.
1212

1313
More details about these and more differences are referenced at [https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.0](https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.0)
@@ -18,16 +18,16 @@ You need the following installed and available in your $PATH:
1818
* Java 8 (http://java.oracle.com)
1919
* Apache maven 3.0.4 or greater (http://maven.apache.org/)
2020

21-
## How to contribute.
22-
Right now the templates and generators classes are migrated from [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) **3.0.0** branch.
21+
## How to Contribute.
22+
Right now the templates and generators classes are migrated from [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) **3.0.0** branch.
2323
If you want to migrate an existing language/framework, you can follow this [guide](https://github.com/swagger-api/swagger-codegen/wiki/Swagger-Codegen-migration-(swagger-codegen-generators-repository)).
24-
Also you need to keep in mind that **Handlebars** is used as template engines and besides it's pretty similar to **Mustache** there are different that can not be ignored. So you can follow this [guide](https://github.com/swagger-api/swagger-codegen/wiki/Swagger-Codegen-migration-from-Mustache-and-Handlebars-templates.) which explains steps to migrate templates from **Mustaches** to **Handelbars**.
24+
Also you need to keep in mind that **Handlebars** is used as the template engine. It's pretty similar to **Mustache**, but there are differences that can not be ignored. So you can follow this [guide](https://github.com/swagger-api/swagger-codegen/wiki/Swagger-Codegen-migration-from-Mustache-and-Handlebars-templates.) which explains steps to migrate templates from **Mustaches** to **Handlebars**.
2525

26-
## Security contact
26+
## Security Contact
2727

2828
Please disclose any security-related issues or vulnerabilities by emailing [[email protected]](mailto:[email protected]), instead of using the public issue tracker.
2929

30-
## License information on Generated Code
30+
## License Information on Generated Code
3131

3232
The Swagger Codegen project is intended as a benefit for users of the Swagger / Open API Specification. The project itself has the [License](#license) as specified. In addition, please understand the following points:
3333

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegenConfig {
4242

43-
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
43+
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class);
4444

4545
private static final String UNDEFINED_VALUE = "undefined";
4646

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

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.swagger.codegen.v3.generators.typescript;
22

3+
import io.swagger.codegen.v3.CliOption;
34
import io.swagger.codegen.v3.CodegenConstants;
45
import io.swagger.codegen.v3.CodegenModel;
56
import io.swagger.codegen.v3.CodegenOperation;
@@ -19,18 +20,31 @@
1920
public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodegen {
2021

2122
public static final String NPM_NAME = "npmName";
23+
public static final String NPM_VERSION = "npmVersion";
2224
public static final String NPM_REPOSITORY = "npmRepository";
2325
public static final String DEFAULT_API_PACKAGE = "apis";
2426
public static final String DEFAULT_MODEL_PACKAGE = "models";
2527

2628
protected String npmRepository = null;
29+
protected String npmName = null;
30+
protected String npmVersion = "1.0.0";
31+
2732

2833
private String tsModelPackage = "";
2934

3035
public TypeScriptAxiosClientCodegen() {
3136
super();
3237
importMapping.clear();
3338
outputFolder = "generated-code/typescript-axios";
39+
LOGGER.info("Template folder: " + this.templateDir());
40+
LOGGER.info("Template engine: " + this.getTemplateEngine());
41+
reservedWords.add("query");
42+
43+
// Custom CLI options
44+
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
45+
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package. Defaults to 1.0.0"));
46+
this.cliOptions.add(new CliOption(NPM_REPOSITORY,
47+
"Use this property to set an url your private npm registry in the package.json"));
3448
}
3549

3650
@Override
@@ -43,14 +57,14 @@ public String getHelp() {
4357
return "Generates a TypeScript Axios client library.";
4458
}
4559

46-
public String getNpmRepository() {
47-
return npmRepository;
48-
}
49-
50-
public void setNpmRepository(String npmRepository) {
51-
this.npmRepository = npmRepository;
52-
}
53-
60+
/**
61+
* Creates a relative path to a file or folder. The resulting path is
62+
* relative to the root directory of the final client library.
63+
*
64+
* @param path The path to the file or folder.
65+
* @return A path to the file or folder which is relative to the client
66+
* library root directory.
67+
*/
5468
private static String getRelativeToRoot(String path) {
5569
StringBuilder sb = new StringBuilder();
5670
int slashCount = path.split("/").length;
@@ -99,6 +113,8 @@ public void processOpts() {
99113
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
100114
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
101115
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
116+
117+
addNpmPackageGeneration();
102118
}
103119

104120
@Override
@@ -162,7 +178,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
162178
cm.classFilename = cm.classname.replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(Locale.ROOT);
163179

164180
//processed enum names
165-
cm.imports = new TreeSet(cm.imports);
181+
cm.imports = new TreeSet<String>(cm.imports);
166182
// name enum with model name, e.g. StatusEnum => PetStatusEnum
167183
for (CodegenProperty var : cm.vars) {
168184
if (getBooleanValue(var, CodegenConstants.IS_ENUM_EXT_NAME)) {
@@ -191,6 +207,31 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
191207
return objs;
192208
}
193209

210+
/**
211+
* Extracts npm package fields from `additionalProperties`. These fields
212+
* are provided as custom CLI options.
213+
*/
214+
private void addNpmPackageGeneration() {
215+
// Name of the NPM package
216+
if (additionalProperties.containsKey(NPM_NAME)) {
217+
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
218+
}
219+
220+
// NPM package version (SemVer)
221+
if (additionalProperties.containsKey(NPM_VERSION)) {
222+
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
223+
}
224+
/* Package version has default value. Make internal version and
225+
* additionalProperties version consistent.
226+
*/
227+
additionalProperties.put(NPM_VERSION, npmVersion);
228+
229+
// NPM registry the package is pushed to
230+
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
231+
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
232+
}
233+
}
234+
194235
/**
195236
* Overriding toRegularExpression() to avoid escapeText() being called,
196237
* as it would return a broken regular expression if any escaped character / metacharacter were present.
@@ -214,4 +255,44 @@ public String toApiFilename(String name) {
214255
public String getDefaultTemplateDir() {
215256
return "typescript-axios";
216257
}
258+
259+
/**
260+
* Gets the name of the generated NPM package.
261+
*
262+
* @return The NPM package name.
263+
*/
264+
public String getNpmName() {
265+
return this.npmName;
266+
}
267+
268+
public void setNpmName(String npmName) {
269+
this.npmName = npmName;
270+
}
271+
272+
/**
273+
* Gets the generated NPM package SemVer string.
274+
*
275+
* @return The package version.
276+
*/
277+
public String getNpmVersion() {
278+
return this.npmVersion;
279+
}
280+
281+
public void setNpmVersion(String npmVersion) {
282+
this.npmVersion = npmVersion;
283+
}
284+
285+
/**
286+
* Gets the name of the NPM registry the package is published to.
287+
*
288+
* @return The NPM registry name.
289+
*/
290+
public String getNpmRepository() {
291+
return this.npmRepository;
292+
}
293+
294+
public void setNpmRepository(String npmRepository) {
295+
this.npmRepository = npmRepository;
296+
}
297+
217298
}

src/main/resources/handlebars/typescript-axios/configuration.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,48 @@ export interface ConfigurationParameters {
1212
}
1313

1414
export class Configuration {
15+
1516
/**
1617
* parameter for apiKey security
18+
*
1719
* @param name security name
1820
* @memberof Configuration
1921
*/
2022
apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
23+
2124
/**
2225
* parameter for basic security
2326
*
2427
* @type {string}
2528
* @memberof Configuration
2629
*/
2730
username?: string;
31+
2832
/**
2933
* parameter for basic security
3034
*
3135
* @type {string}
3236
* @memberof Configuration
3337
*/
3438
password?: string;
39+
3540
/**
3641
* parameter for oauth2 security
42+
*
3743
* @param name security name
3844
* @param scopes oauth2 scope
3945
* @memberof Configuration
4046
*/
4147
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
48+
4249
/**
4350
* override base path
4451
*
4552
* @type {string}
4653
* @memberof Configuration
4754
*/
4855
basePath?: string;
56+
4957
/**
5058
* base options for axios calls
5159
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
* NOTE: This class is auto generated by the swagger code generator program.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
11-
*/
11+
*/

src/main/resources/handlebars/typescript-axios/modelGeneric.mustache

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import {
2+
{{#imports}}{{.}},{{/imports}}
3+
} from ".";
4+
15
/**
26
* {{{description}}}
7+
*
38
* @export
49
* @interface {{classname}}
510
*/
@@ -9,10 +14,17 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
914

1015
{{/additionalPropertiesType}}
1116
{{#vars}}
17+
1218
/**
13-
* {{{description}}}
19+
{{#description}}
20+
* {{{.}}}
21+
*
22+
{{/description}}
1423
* @type {{braces "left"}}{{{datatype}}}{{braces "right"}}
15-
* @memberof {{{classname}}}
24+
* @memberof {{classname}}
25+
{{#example}}
26+
* @example {{{.}}}
27+
{{/example}}
1628
{{#deprecated}}
1729
* @deprecated
1830
{{/deprecated}}
@@ -24,9 +36,9 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
2436
{{#vars}}
2537
{{#isEnum}}
2638
/**
27-
* @export
28-
* @enum {string}
29-
*/
39+
* @export
40+
* @enum {string}
41+
*/
3042
export enum {{enumName}} {
3143
{{#allowableValues}}
3244
{{#enumVars}}

0 commit comments

Comments
 (0)