Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !11368

[typescript-axios] Add stringEnums option

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/ty-v1/add-string-enums-option-to-axios-generator into master 3 years ago
  • Overview 0
  • Commits 12
  • Pipelines 0
  • Changes 30

Created by: ty-v1

This PR adds stringEnums option to typescript-axios generator. Closes #10943 (closed)

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02)

Compare
  • master (base)

and
  • latest version
    043417db
    12 commits, 2 years ago

30 files
+ 2664
- 426

    Preferences

    File browser
    Compare changes
bin/c‎onfigs‎
typescript-axios-wi‎th-string-enums.yaml‎ +6 -0
docs/ge‎nerators‎
typescrip‎t-axios.md‎ +1 -0
modules/openapi-g‎enerator/src/main‎
java/org/openapitoo‎ls/codegen/languages‎
TypeScriptAxiosC‎lientCodegen.java‎ +9 -0
resources/typ‎escript-axios‎
modelEnum‎.mustache‎ +6 -12
modelGener‎ic.mustache‎ +18 -0
modelObjectE‎num.mustache‎ +14 -0
modelStringE‎num.mustache‎ +12 -0
samples/clie‎nt/…/…/builds‎
composed‎-schemas‎
api‎.ts‎ +22 -28
def‎ault‎
api‎.ts‎ +14 -18
es6-t‎arget‎
api‎.ts‎ +14 -18
test-p‎etstore‎
api‎.ts‎ +121 -132
with-compl‎ex-headers‎
api‎.ts‎ +14 -18
with-fake-endpoints-models-fo‎r-testing-with-http-signature‎
api‎.ts‎ +105 -110
with-in‎terfaces‎
api‎.ts‎ +14 -18
with-nod‎e-imports‎
api‎.ts‎ +14 -18
with-npm‎-version‎
api‎.ts‎ +14 -18
with-single-req‎uest-parameters‎
api‎.ts‎ +14 -18
with-str‎ing-enums‎
.openapi-‎generator‎
FI‎LES‎ +8 -0
VER‎SION‎ +1 -0
.giti‎gnore‎ +4 -0
.npmi‎gnore‎ +1 -0
.openapi-gen‎erator-ignore‎ +23 -0
api‎.ts‎ +1816 -0
bas‎e.ts‎ +71 -0
comm‎on.ts‎ +138 -0
configur‎ation.ts‎ +101 -0
git_p‎ush.sh‎ +57 -0
inde‎x.ts‎ +18 -0
…/…/‎…/…/…‎
orde‎r.ts‎ +7 -9
pet‎.ts‎ +7 -9
bin/configs/typescript-axios-with-string-enums.yaml 0 → 100644
+ 6
- 0
  • View file @ 043417db

  • Edit in single-file editor

  • Open in Web IDE

generatorName: typescript-axios
outputDir: samples/client/petstore/typescript-axios/builds/with-string-enums
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-axios
additionalProperties:
stringEnums: true
docs/generators/typescript-axios.md
+ 1
- 0
  • View file @ 043417db

  • Edit in single-file editor

  • Open in Web IDE


@@ -31,6 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|stringEnums|Generate string enums instead of objects for enum values.| |false|
|supportsES6|Generate code that conforms to ES6.| |false|
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
|withInterfaces|Setting this property to true will generate interfaces next to the default class implementations.| |false|
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java
+ 9
- 0
  • View file @ 043417db

  • Edit in single-file editor

  • Open in Web IDE


@@ -34,8 +34,11 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
public static final String WITHOUT_PREFIX_ENUMS = "withoutPrefixEnums";
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";
public static final String WITH_NODE_IMPORTS = "withNodeImports";
public static final String STRING_ENUMS = "stringEnums";
public static final String STRING_ENUMS_DESC = "Generate string enums instead of objects for enum values.";
protected String npmRepository = null;
protected Boolean stringEnums = false;
private String tsModelPackage = "";
@@ -57,6 +60,7 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
this.cliOptions.add(new CliOption(WITHOUT_PREFIX_ENUMS, "Don't prefix enum names with class names", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(WITH_NODE_IMPORTS, "Setting this property to true adds imports for NodeJS", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString()));
this.cliOptions.add(new CliOption(STRING_ENUMS, STRING_ENUMS_DESC).defaultValue(String.valueOf(this.stringEnums)));
// Templates have no mapping between formatted property names and original base names so use only "original" and remove this option
removeOption(CodegenConstants.MODEL_PROPERTY_NAMING);
}
@@ -127,6 +131,11 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege
}
}
if (additionalProperties.containsKey(STRING_ENUMS)) {
this.stringEnums = Boolean.parseBoolean(additionalProperties.get(STRING_ENUMS).toString());
additionalProperties.put("stringEnums", this.stringEnums);
}
if (additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration();
}
modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache
+ 6
- 12
  • View file @ 043417db

  • Edit in single-file editor

  • Open in Web IDE


@@ -8,16 +8,10 @@ export type {{classname}} = {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last
{{/isBoolean}}
{{^isBoolean}}
export enum {{classname}} {
{{#allowableValues}}
{{#enumVars}}
{{#enumDescription}}
/**
* {{.}}
*/
{{/enumDescription}}
{{{name}}} = {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
}
{{^stringEnums}}
{{>modelObjectEnum}}
{{/stringEnums}}
{{#stringEnums}}
{{>modelStringEnum}}
{{/stringEnums}}
{{/isBoolean}}
modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache
+ 18
- 0
  • View file @ 043417db

  • Edit in single-file editor

  • Open in Web IDE


@@ -23,6 +23,7 @@ export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
{{#vars}}
{{#isEnum}}
{{#stringEnums}}
/**
* @export
* @enum {string}
@@ -39,6 +40,23 @@ export enum {{enumName}} {
{{/enumVars}}
{{/allowableValues}}
}
{{/stringEnums}}
{{^stringEnums}}
export const {{enumName}} = {
{{#allowableValues}}
{{#enumVars}}
{{#enumDescription}}
/**
* {{.}}
*/
{{/enumDescription}}
{{{name}}}: {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
} as const;
export type {{enumName}} = typeof {{enumName}}[keyof typeof {{enumName}}];
{{/stringEnums}}
{{/isEnum}}
{{/vars}}
{{/hasEnums}}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Breaking change (with fallback) Client: TypeScript
2
Breaking change (with fallback) Client: TypeScript
    Assign labels
  • Manage project labels

Milestone
5.4.0
5.4.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: OpenAPITools/openapi-generator!11368
Source branch: github/fork/ty-v1/add-string-enums-option-to-axios-generator

Menu

Explore Projects Groups Snippets