forked from OpenAPITools/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript-node] fixed enum generator for top level enums OpenAPIToo…
…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
1 parent
244eefc
commit 8417c5b
Showing
16 changed files
with
710 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...org/openapitools/codegen/typescript/typescriptnode/TypescriptNodeEnumIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...rator/src/test/resources/integrationtests/typescript/objectsWithEnums-expected/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
wwwroot/*.js | ||
node_modules | ||
typings |
23 changes: 23 additions & 0 deletions
23
...resources/integrationtests/typescript/objectsWithEnums-expected/.openapi-generator-ignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
...esources/integrationtests/typescript/objectsWithEnums-expected/.openapi-generator/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unset |
3 changes: 3 additions & 0 deletions
3
...generator/src/test/resources/integrationtests/typescript/objectsWithEnums-expected/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
3 changes: 3 additions & 0 deletions
3
...ator/src/test/resources/integrationtests/typescript/objectsWithEnums-expected/api/apis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
171 changes: 171 additions & 0 deletions
171
...rc/test/resources/integrationtests/typescript/objectsWithEnums-expected/api/defaultApi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ator/src/test/resources/integrationtests/typescript/objectsWithEnums-expected/git_push.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
17 changes: 17 additions & 0 deletions
17
...est/resources/integrationtests/typescript/objectsWithEnums-expected/model/externalEnum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
Oops, something went wrong.