Skip to content

Commit

Permalink
[typescript-node] fixed enum generator for top level enums OpenAPIToo…
Browse files Browse the repository at this point in the history
…ls#665 (OpenAPITools#2266)

* [typescript-node] fixed enum generator for top level enums OpenAPITools#665

* [typescript-node] fixed enum generator for top level enums in models.mustache OpenAPITools#665

* Remove wrong copyright line
  • Loading branch information
christof-vollrath-spring-media authored and macjohnny committed Jul 15, 2019
1 parent 244eefc commit 8417c5b
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { {{classname}} } from './{{filename}}';
* {{{description}}}
*/
{{/description}}
{{^isEnum}}
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}}
{{#description}}
Expand Down Expand Up @@ -65,5 +66,15 @@ export namespace {{classname}} {
{{/vars}}
}
{{/hasEnums}}
{{/isEnum}}
{{#isEnum}}
export enum {{classname}} {
{{#allowableValues}}
{{#enumVars}}
{{name}} = <any> {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}}
{{/allowableValues}}
}
{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ let enumsMap: {[index: string]: any} = {
{{/isEnum}}
{{/vars}}
{{/hasEnums}}
{{#isEnum}}
"{{classname}}": {{classname}},
{{/isEnum}}
{{/model}}
{{/models}}
}

let typeMap: {[index: string]: any} = {
{{#models}}
{{#model}}
{{^isEnum}}
"{{classname}}": {{classname}},
{{/isEnum}}
{{/model}}
{{/models}}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.codegen.typescript.typescriptnode;

import org.openapitools.codegen.AbstractIntegrationTest;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen;
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
import org.openapitools.codegen.testutils.IntegrationTestPathsConfig;

import java.util.HashMap;
import java.util.Map;

public class TypescriptNodeEnumIntegrationTest extends AbstractIntegrationTest {

@Override
protected CodegenConfig getCodegenConfig() {
return new TypeScriptNodeClientCodegen();
}

@Override
protected Map<String, String> configProperties() {
Map<String, String> properties = new HashMap<>();
properties.put("npmName", "node-es6-test");
properties.put("npmVersion", "1.0.3");
properties.put("snapshot", "false");
properties.put("supportsES6", "false");

return properties;
}

@Override
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
return new IntegrationTestPathsConfig("typescript/objectsWithEnums");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wwwroot/*.js
node_modules
typings
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unset
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is the entrypoint for the package
export * from './api/apis';
export * from './model/models';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './defaultApi';
import { DefaultApi } from './defaultApi';
export const APIS = [DefaultApi];
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/**
* OpenAPI enums
* Tests generation of enums with open opi
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import localVarRequest = require('request');
import http = require('http');
import Promise = require('bluebird');

/* tslint:disable:no-unused-locals */
import { ObjectWithEnums } from '../model/objectWithEnums';

import { ObjectSerializer, Authentication, HttpBasicAuth, ApiKeyAuth, OAuth, VoidAuth } from '../model/models';

let defaultBasePath = 'http://enums.openapi3';

// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================

export enum DefaultApiApiKeys {
}

export class DefaultApi {
protected _basePath = defaultBasePath;
protected defaultHeaders : any = {};
protected _useQuerystring : boolean = false;

protected authentications = {
'default': <Authentication>new VoidAuth(),
}

constructor(basePath?: string);
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
if (basePath) {
this.basePath = basePath;
}
} else {
if (basePathOrUsername) {
this.basePath = basePathOrUsername
}
}
}

set useQuerystring(value: boolean) {
this._useQuerystring = value;
}

set basePath(basePath: string) {
this._basePath = basePath;
}

get basePath() {
return this._basePath;
}

public setDefaultAuthentication(auth: Authentication) {
this.authentications.default = auth;
}

public setApiKey(key: DefaultApiApiKeys, value: string) {
(this.authentications as any)[DefaultApiApiKeys[key]].apiKey = value;
}

/**
*
*/
public getObjectWithEnums (options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body: Array<ObjectWithEnums>; }> {
const localVarPath = this.basePath + '/getobjectwithenums';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};

(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;

let localVarRequestOptions: localVarRequest.Options = {
method: 'GET',
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
};

this.authentications.default.applyToRequest(localVarRequestOptions);

if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).formData = localVarFormParams;
} else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.ClientResponse; body: Array<ObjectWithEnums>; }>((resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
body = ObjectSerializer.deserialize(body, "Array<ObjectWithEnums>");
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
}
}
});
});
}
/**
*
* @param objectWithEnums
*/
public postObjectWithEnums (objectWithEnums: ObjectWithEnums, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> {
const localVarPath = this.basePath + '/postobjectwithenums';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this.defaultHeaders);
let localVarFormParams: any = {};

// verify required parameter 'objectWithEnums' is not null or undefined
if (objectWithEnums === null || objectWithEnums === undefined) {
throw new Error('Required parameter objectWithEnums was null or undefined when calling postObjectWithEnums.');
}

(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;

let localVarRequestOptions: localVarRequest.Options = {
method: 'POST',
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
body: ObjectSerializer.serialize(objectWithEnums, "ObjectWithEnums")
};

this.authentications.default.applyToRequest(localVarRequestOptions);

if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).formData = localVarFormParams;
} else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.ClientResponse; body?: any; }>((resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
resolve({ response: response, body: body });
} else {
reject({ response: response, body: body });
}
}
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"

git_user_id=$1
git_repo_id=$2
release_note=$3

if [ "$git_user_id" = "" ]; then
git_user_id=""
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi

if [ "$git_repo_id" = "" ]; then
git_repo_id=""
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi

if [ "$release_note" = "" ]; then
release_note=""
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
fi

# Initialize the local directory as a Git repository
git init

# Adds the files in the local repository and stages them for commit.
git add .

# Commits the tracked changes and prepares them to be pushed to a remote repository.
git commit -m "$release_note"

# Sets the new remote
git_remote=`git remote`
if [ "$git_remote" = "" ]; then # git remote not defined

if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
fi

fi

git pull origin master

# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* OpenAPI enums
* Tests generation of enums with open opi
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


export enum ExternalEnum {
Green = <any> 'green',
Yellow = <any> 'yellow'
}
Loading

0 comments on commit 8417c5b

Please sign in to comment.