Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ samples/client/petstore/typescript-node/npm/node_modules
samples/client/petstore/typescript-node/**/typings
samples/client/petstore/typescript-angular/**/typings
samples/client/petstore/typescript-fetch/**/dist/
samples/client/petstore/typescript-fetch/**/typings
samples/client/petstore/typescript-fetch/**/npm-debug.log
samples/client/petstore/typescript-fetch/**/node_modules/
samples/client/petstore/typescript-angular2/npm/npm-debug.log
samples/client/petstore/typescript-node/npm/npm-debug.log

Expand Down
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ cache:
- $HOME/samples/client/petstore/python/.venv/
- $HOME/samples/client/petstore/typescript-node/npm/node_modules
- $HOME/samples/client/petstore/typescript-node/npm/typings/
- $HOME/samples/client/petstore/typescript-fetch/tests/default/node_modules
- $HOME/samples/client/petstore/typescript-fetch/tests/default/typings
- $HOME/samples/client/petstore/typescript-fetch/builds/default/node_modules
- $HOME/samples/client/petstore/typescript-fetch/builds/default/typings
- $HOME/samples/client/petstore/typescript-fetch/builds/es6-target/node_modules
- $HOME/samples/client/petstore/typescript-fetch/builds/es6-target/typings
- $HOME/samples/client/petstore/typescript-fetch/builds/with-npm-version/node_modules
- $HOME/samples/client/petstore/typescript-fetch/npm/with-npm-version/typings
- $HOME/samples/client/petstore/typescript-fetch/builds/es6/node_modules
- $HOME/samples/client/petstore/typescript-fetch/builds/npm/node_modules
- $HOME/samples/client/petstore/typescript-fetch/tests/npm/node_modules
- $HOME/samples/client/petstore/typescript-angular/node_modules
- $HOME/samples/client/petstore/typescript-angular/typings
- $HOME/.cocoapods/repos/master
Expand Down
Empty file modified bin/jaxrs-resteasy-eap-java8-petstore-server.sh
100755 → 100644
Empty file.
Empty file modified bin/swift3-petstore-unwraprequired.sh
100755 → 100644
Empty file.
Empty file modified bin/typescript-angular4-petstore-with-npm.sh
100755 → 100644
Empty file.
5 changes: 0 additions & 5 deletions bin/typescript-fetch-petstore-all.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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.yaml -l typescript-fetch -c bin/typescript-fetch-petstore-target-es6.json -o samples/client/petstore/typescript-fetch/builds/es6-target"

echo "Typescript-Fetch Petstore API client (default)"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -o samples/client/petstore/typescript-fetch/builds/default"

java $JAVA_OPTS -jar $executable $ags
7 changes: 7 additions & 0 deletions bin/typescript-fetch-petstore-es6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"npmName": "@swagger/typescript-fetch-petstore",
"npmVersion": "0.0.1",
"npmRepository" : "https://skimdb.npmjs.com/registry",
"snapshot" : false,
"supportsES6": true
}
4 changes: 3 additions & 1 deletion ...script-fetch-petstore-with-npm-version.sh → bin/typescript-fetch-petstore-es6.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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.yaml -l typescript-fetch -c bin/typescript-fetch-petstore-with-npm-version.json -o samples/client/petstore/typescript-fetch/builds/with-npm-version"

echo "Typescript-Fetch Petstore API client (ES6)"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -c bin/typescript-fetch-petstore-es6.json -o samples/client/petstore/typescript-fetch/builds/es6"

java $JAVA_OPTS -jar $executable $ags
6 changes: 6 additions & 0 deletions bin/typescript-fetch-petstore-npm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"npmName": "@swagger/typescript-fetch-petstore",
"npmVersion": "0.0.1",
"npmRepository" : "https://skimdb.npmjs.com/registry",
"snapshot" : false
}
33 changes: 33 additions & 0 deletions bin/typescript-fetch-petstore-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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"

echo "Typescript-Fetch Petstore API client (NPM version)"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -c bin/typescript-fetch-petstore-npm.json -o samples/client/petstore/typescript-fetch/builds/npm"

java $JAVA_OPTS -jar $executable $ags
3 changes: 0 additions & 3 deletions bin/typescript-fetch-petstore-target-es6.json

This file was deleted.

4 changes: 0 additions & 4 deletions bin/typescript-fetch-petstore-with-npm-version.json

This file was deleted.

31 changes: 3 additions & 28 deletions bin/typescript-fetch-petstore.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
#!/bin/sh

SCRIPT="$0"
./bin/typescript-fetch-petstore-default.sh
./bin/typescript-fetch-petstore-es6.sh
./bin/typescript-fetch-petstore-npm.sh

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.yaml -l typescript-fetch -o samples/client/petstore/typescript-fetch/builds/default"

java $JAVA_OPTS -jar $executable $ags
Empty file modified bin/windows/python2-flask-petstore.bat
100755 → 100644
Empty file.
Empty file modified bin/windows/python3-flask-petstore.bat
100755 → 100644
Empty file.
Empty file modified bin/windows/typescript-angular2-petstore-all.bat
100755 → 100644
Empty file.
5 changes: 4 additions & 1 deletion bin/windows/typescript-fetch.bat → ...ows/typescript-fetch-petstore-default.bat
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
@ECHO OFF
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -o samples\client\petstore\typescript-fetch

echo Typescript-Fetch Petstore API client (default)
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -o samples\client\petstore\typescript-fetch\builds\default

java %JAVA_OPTS% -jar %executable% %ags%
13 changes: 13 additions & 0 deletions bin/windows/typescript-fetch-petstore-es6.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@ECHO OFF
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M

echo Typescript-Fetch Petstore API client (ES6)
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -c bin\typescript-fetch-petstore-es6.json -o samples\client\petstore\typescript-fetch\builds\es6

java %JAVA_OPTS% -jar %executable% %ags%
13 changes: 13 additions & 0 deletions bin/windows/typescript-fetch-petstore-npm.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@ECHO OFF
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M

echo Typescript-Fetch Petstore API client (NPM version)
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -c bin/typescript-fetch-petstore-npm.json -o samples\client\petstore\typescript-fetch\builds\npm

java %JAVA_OPTS% -jar %executable% %ags%
13 changes: 13 additions & 0 deletions bin/windows/typescript-fetch-petstore-tsoa.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@ECHO OFF
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar

If Not Exist %executable% (
mvn clean package
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M

echo Typescript-Fetch Petstore API client (NPM version)
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\swagger.json -l typescript-fetch -c bin/typescript-fetch-petstore-npm.json -o samples\client\petstore\typescript-fetch\tsoa

java %JAVA_OPTS% -jar %executable% %ags%
5 changes: 5 additions & 0 deletions bin/windows/typescript-fetch-petstore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ECHO OFF

call bin\windows\typescript-fetch-petstore-default.bat
call bin\windows\typescript-fetch-petstore-es6.bat
call bin\windows\typescript-fetch-petstore-npm.bat
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package io.swagger.codegen.languages;

import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.SupportingFile;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;

import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.BooleanProperty;
import io.swagger.models.properties.FileProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.ObjectProperty;
import io.swagger.models.properties.Property;
import sun.rmi.runtime.Log;

public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");

public static final String NPM_NAME = "npmName";
public static final String NPM_VERSION = "npmVersion";
public static final String NPM_REPOSITORY = "npmRepository";
public static final String SNAPSHOT = "snapshot";

protected String npmName = null;
protected String npmVersion = "1.0.0";
protected String npmRepository = null;

public TypeScriptFetchClientCodegen() {
super();
Expand All @@ -29,28 +44,67 @@ public TypeScriptFetchClientCodegen() {
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"));
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
}

@Override
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) {
codegenModel.additionalPropertiesType = getTypeDeclaration(swaggerModel.getAdditionalProperties());
addImport(codegenModel, codegenModel.additionalPropertiesType);
}

@Override
public void processOpts() {
super.processOpts();
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
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"));
supportingFiles.add(new SupportingFile("tslint.json.mustache", "", "tslint.json"));
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
if(additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration();
}
}
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts"));

private void addNpmPackageGeneration() {
if(additionalProperties.containsKey(NPM_NAME)) {
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
}

if (additionalProperties.containsKey(NPM_VERSION)) {
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
}

if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
}
additionalProperties.put(NPM_VERSION, npmVersion);

if (additionalProperties.containsKey(NPM_REPOSITORY)) {
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
}

//Files for building our lib
supportingFiles.add(new SupportingFile("README.md.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json"));
supportingFiles.add(new SupportingFile("tsconfig.json.mustache", "", "tsconfig.json"));
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
}

@Override
public String getTypeDeclaration(Property p) {
if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
return this.getSwaggerType(p) + "<" + this.getTypeDeclaration(inner) + ">";
} else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
} else if (p instanceof FileProperty || p instanceof ObjectProperty) {
return "any";
} else {
return super.getTypeDeclaration(p);
}
}

@Override
Expand Down Expand Up @@ -79,24 +133,11 @@ public void setNpmVersion(String npmVersion) {
this.npmVersion = npmVersion;
}

@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
// process enum in models
List<Object> models = (List<Object>) postProcessModelsEnum(objs).get("models");
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
cm.imports = new TreeSet(cm.imports);
for (CodegenProperty var : cm.vars) {
// name enum with model name, e.g. StatuEnum => PetStatusEnum
if (Boolean.TRUE.equals(var.isEnum)) {
var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + var.enumName);
var.enumName = cm.classname + var.enumName;
}
}
}

return objs;
public String getNpmRepository() {
return npmRepository;
}

public void setNpmRepository(String npmRepository) {
this.npmRepository = npmRepository;
}
}
Loading