forked from loafle/openapi-generator-original
Merge pull request #2791 from leonyu/typescript-fetch-package-json
Typescript fetch update
This commit is contained in:
commit
e367a74504
3
bin/typescript-fetch-petstore-target-es6.json
Normal file
3
bin/typescript-fetch-petstore-target-es6.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"supportsES6": true
|
||||
}
|
31
bin/typescript-fetch-petstore-target-es6.sh
Executable file
31
bin/typescript-fetch-petstore-target-es6.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -c bin/typescript-fetch-petstore-target-es6.json -o samples/client/petstore/typescript-fetch/default-es6"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-fetch-petstore",
|
||||
"npmVersion": "0.0.1"
|
||||
}
|
31
bin/typescript-fetch-petstore-target-with-package-metadata.sh
Executable file
31
bin/typescript-fetch-petstore-target-with-package-metadata.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -c bin/typescript-fetch-petstore-target-with-package-metadata.json -o samples/client/petstore/typescript-fetch/with-package-metadata"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -o samples/client/petstore/typescript-fetch/"
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -o samples/client/petstore/typescript-fetch/default"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,11 +1,47 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
|
||||
public static final String NPM_NAME = "npmName";
|
||||
public static final String NPM_VERSION = "npmVersion";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
|
||||
public TypeScriptFetchClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-fetch";
|
||||
embeddedTemplateDir = templateDir = "TypeScript-Fetch";
|
||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
final String defaultFolder = apiPackage().replace('.', File.separatorChar);
|
||||
|
||||
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("assign.ts", defaultFolder, "assign.ts"));
|
||||
supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.json.mustache", "", "typings.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.json.mustache", "", "tsconfig.json"));
|
||||
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(NPM_VERSION)) {
|
||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-fetch";
|
||||
@ -16,23 +52,20 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
return "Generates a TypeScript client library using Fetch API (beta).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
final String defaultFolder = apiPackage().replace('.', File.separatorChar);
|
||||
|
||||
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("assign.ts", defaultFolder, "assign.ts"));
|
||||
supportingFiles.add(new SupportingFile("package.json", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.json", "", "typings.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.json", "", "tsconfig.json"));
|
||||
public String getNpmName() {
|
||||
return npmName;
|
||||
}
|
||||
|
||||
public TypeScriptFetchClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-fetch";
|
||||
embeddedTemplateDir = templateDir = "TypeScript-Fetch";
|
||||
public void setNpmName(String npmName) {
|
||||
this.npmName = npmName;
|
||||
}
|
||||
|
||||
public String getNpmVersion() {
|
||||
return npmVersion;
|
||||
}
|
||||
|
||||
public void setNpmVersion(String npmVersion) {
|
||||
this.npmVersion = npmVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,14 +23,14 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
||||
}
|
||||
|
||||
{{#hasEnums}}
|
||||
export namespace {{classname}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
|
||||
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||
{{.}} = <any> '{{.}}'{{^-last}},{{/-last}}{{/values}}{{/allowableValues}}
|
||||
}
|
||||
export type {{datatypeWithEnum}} = {{#allowableValues}}{{#values}}'{{.}}'{{^-last}} | {{/-last}}{{/values}}{{/allowableValues}};
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
@ -119,8 +119,8 @@ export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response.json();
|
||||
} else {
|
||||
var error = new Error(response.statusText);
|
||||
error['response'] = response;
|
||||
let error = new Error(response.statusText);
|
||||
(error as any).response = response;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
export function assign (target, ...args) {
|
||||
export function assign (target: any, ...args: any[]) {
|
||||
'use strict';
|
||||
if (target === undefined || target === null) {
|
||||
throw new TypeError('Cannot convert undefined or null to object');
|
||||
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^0.8.1"
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "{{#npmName}}{{{npmName}}}{{/npmName}}{{^npmName}}typescript-fetch-api{{/npmName}}",
|
||||
"version": "{{#npmVersion}}{{{npmVersion}}}{{/npmVersion}}{{^npmVersion}}0.0.0{{/npmVersion}}",
|
||||
"private": true,
|
||||
"main": "dist/api.js",
|
||||
"browser": "dist/api.js",
|
||||
"dependencies": {
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"scripts" : {
|
||||
"install" : "typings install && tsc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^0.8.1"
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
]
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
]
|
||||
}
|
@ -2,8 +2,8 @@
|
||||
"version": false,
|
||||
"dependencies": {},
|
||||
"ambientDependencies": {
|
||||
"es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
|
||||
"node": "registry:dt/node#4.0.0+20160423143914",
|
||||
{{^supportsES6}} "es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
|
||||
{{/supportsES6}} "node": "registry:dt/node#4.0.0+20160423143914",
|
||||
"isomorphic-fetch": "github:leonyu/DefinitelyTyped/isomorphic-fetch/isomorphic-fetch.d.ts#isomorphic-fetch-fix-module"
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package io.swagger.codegen.options;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.languages.TypeScriptFetchClientCodegen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -10,6 +11,8 @@ public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
|
||||
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||
public static final Boolean SUPPORTS_ES6_VALUE = false;
|
||||
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||
private static final String NMP_NAME = "npmName";
|
||||
private static final String NMP_VERSION = "1.0.0";
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
@ -23,6 +26,8 @@ public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
|
||||
.put(CodegenConstants.SUPPORTS_ES6, String.valueOf(SUPPORTS_ES6_VALUE))
|
||||
.put(TypeScriptFetchClientCodegen.NPM_NAME, NMP_NAME)
|
||||
.put(TypeScriptFetchClientCodegen.NPM_VERSION, NMP_VERSION)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user