Skip to content

Commit

Permalink
Update Perl client samples (OAS2, OAS3) with various fixes (#204)
Browse files Browse the repository at this point in the history
* update perl client with various fixes

* update perl petstore with oas3, tests passed
  • Loading branch information
wing328 authored Apr 23, 2018
1 parent b908b73 commit f353f60
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 268 deletions.
2 changes: 0 additions & 2 deletions bin/openapi3/perl-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
ags="$@ generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -l perl -o samples/client/petstore/perl -DhideGenerationTimestamp=true"

java $JAVA_OPTS -jar $executable $ags

java $JAVA_OPTS -jar $executable $ags --additional-properties moduleName=Something::Deep -o samples/client/petstore/perl/deep_module_test
32 changes: 32 additions & 0 deletions bin/perl-deep-module-petstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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/openapi-generator-cli/target/openapi-generator-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"
# complex module name used for testing
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l perl -o samples/client/petstore/perl -DhideGenerationTimestamp=true"

java $JAVA_OPTS -jar $executable $ags --additional-properties moduleName=Something::Deep -o samples/client/petstore/perl/deep_module_test
5 changes: 5 additions & 0 deletions bin/perl-petstore-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

./bin/perl-petstore.sh
./bin/perl-deep-module-petstore.sh

2 changes: 0 additions & 2 deletions bin/perl-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l perl -o samples/client/petstore/perl -DhideGenerationTimestamp=true"

java $JAVA_OPTS -jar $executable $ags

java $JAVA_OPTS -jar $executable $ags --additional-properties moduleName=Something::Deep -o samples/client/petstore/perl/deep_module_test
2 changes: 1 addition & 1 deletion bin/windows/perl-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l perl -o samples\client\petstore\perl
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l perl -o samples\client\petstore\perl

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.openapitools.codegen.languages;

import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;

import io.swagger.v3.oas.models.OpenAPI;
Expand Down Expand Up @@ -80,6 +74,7 @@ public PerlClientCodegen() {
typeMapping.put("long", "int");
typeMapping.put("float", "double");
typeMapping.put("double", "double");
typeMapping.put("number", "double");
typeMapping.put("boolean", "boolean");
typeMapping.put("string", "string");
typeMapping.put("date", "DateTime");
Expand All @@ -88,10 +83,10 @@ public PerlClientCodegen() {
typeMapping.put("array", "ARRAY");
typeMapping.put("map", "HASH");
typeMapping.put("object", "object");
//TODO binary should be mapped to byte array
// mapped to String as a workaround
typeMapping.put("binary", "string");
typeMapping.put("file", "string");
typeMapping.put("ByteArray", "string");
typeMapping.put("UUID", "string");

cliOptions.clear();
cliOptions.add(new CliOption(MODULE_NAME, "Perl module name (convention: CamelCase or Long::Module).").defaultValue("SwaggerClient"));
Expand Down Expand Up @@ -383,18 +378,147 @@ public void setModuleVersion(String moduleVersion) {

@Override
public void setParameterExampleValue(CodegenParameter p) {
if (Boolean.TRUE.equals(p.isString) || Boolean.TRUE.equals(p.isBinary) ||
Boolean.TRUE.equals(p.isByteArray) || Boolean.TRUE.equals(p.isFile)) {
p.example = "'" + p.example + "'";
String example;

if (p.defaultValue == null) {
example = p.example;
} else {
example = p.defaultValue;
}

String type = p.baseType;
if (type == null) {
type = p.dataType;
}

if (Boolean.TRUE.equals(p.isInteger)) {
if (example == null) {
example = "56";
}
} else if (Boolean.TRUE.equals(p.isLong)) {
if (example == null) {
example = "789";
}
} else if (Boolean.TRUE.equals(p.isDouble)
|| Boolean.TRUE.equals(p.isFloat)
|| Boolean.TRUE.equals(p.isNumber)) {
if (example == null) {
example = "3.4";
}
} else if (Boolean.TRUE.equals(p.isBoolean)) {
if (Boolean.parseBoolean(p.example))
if (Boolean.parseBoolean(p.example)) {
p.example = "1";
else
} else {
p.example = "0";
} else if (Boolean.TRUE.equals(p.isDateTime) || Boolean.TRUE.equals(p.isDate)) {
p.example = "DateTime->from_epoch(epoch => str2time('" + p.example + "'))";
}
} else if (Boolean.TRUE.equals(p.isFile) || Boolean.TRUE.equals(p.isBinary)) {
if (example == null) {
example = "/path/to/file";
}
example = "\"" + escapeText(example) + "\"";
} else if (Boolean.TRUE.equals(p.isByteArray)) {
if (example == null) {
example = "YmFzZSA2NCBkYXRh";
}
example = "\"" + escapeText(example) + "\"";
} else if (Boolean.TRUE.equals(p.isDate)) {
if (example == null) {
example = "2013-10-20";
}
example = "DateTime->from_epoch(epoch => str2time('" + escapeText(p.example) + "'))";
} else if (Boolean.TRUE.equals(p.isDateTime)) {
if (example == null) {
example = "2013-10-20T19:20:30+01:00";
}
example = "DateTime->from_epoch(epoch => str2time('" + escapeText(p.example) + "'))";
} else if (Boolean.TRUE.equals(p.isString)) {
if (example == null) {
example = p.paramName + "_example";
}
example = "\"" + escapeText(example) + "\"";

} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
example = "new " + moduleName + "." + type + "()";
}

// container
if (Boolean.TRUE.equals(p.isListContainer)) {
example = setPropertyExampleValue(p.items);
example = "(" + example + ")";
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
example = setPropertyExampleValue(p.items);
example = "('key' => " + example + "}";
} else if (example == null) {
example = "null";
}

p.example = example;
}

protected String setPropertyExampleValue(CodegenProperty p) {
String example;

if (p == null) {
return "null";
}

if (p.defaultValue == null) {
example = p.example;
} else {
example = p.defaultValue;
}

String type = p.baseType;
if (type == null) {
type = p.datatype;
}

if (Boolean.TRUE.equals(p.isInteger)) {
if (example == null) {
example = "56";
}
} else if (Boolean.TRUE.equals(p.isLong)) {
if (example == null) {
example = "789";
}
} else if (Boolean.TRUE.equals(p.isDouble)
|| Boolean.TRUE.equals(p.isFloat)
|| Boolean.TRUE.equals(p.isNumber)) {
if (example == null) {
example = "3.4";
}
} else if (Boolean.TRUE.equals(p.isBoolean)) {
if (example == null) {
example = "true";
}
} else if (Boolean.TRUE.equals(p.isFile) || Boolean.TRUE.equals(p.isBinary)) {
if (example == null) {
example = "/path/to/file";
}
example = "\"" + escapeText(example) + "\"";
} else if (Boolean.TRUE.equals(p.isDate)) {
if (example == null) {
example = "2013-10-20";
}
example = "DateTime->from_epoch(epoch => str2time('" + escapeText(p.example) + "'))";
} else if (Boolean.TRUE.equals(p.isDateTime)) {
if (example == null) {
example = "2013-10-20T19:20:30+01:00";
}
example = "DateTime->from_epoch(epoch => str2time('" + escapeText(p.example) + "'))";
} else if (Boolean.TRUE.equals(p.isString)) {
if (example == null) {
example = p.name + "_example";
}
example = "\"" + escapeText(example) + "\"";

} else if (!languageSpecificPrimitives.contains(type)) {
// type is a model class, e.g. User
example = "new " + moduleName + "." + type + "()";
}

return example;
}

@Override
Expand Down
1 change: 0 additions & 1 deletion samples/client/petstore/perl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ Class | Method | HTTP request | Description
*FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite |
*FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number |
*FakeApi* | [**fake_outer_string_serialize**](docs/FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string |
*FakeApi* | [**test_body_with_query_params**](docs/FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params |
*FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
*FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FakeApi* | [**test_enum_parameters**](docs/FakeApi.md#test_enum_parameters) | **GET** /fake | To test enum parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use WWW::SwaggerClient::Object::ArrayOfArrayOfNumberOnly;
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_array_number** | **ARRAY[ARRAY[Number]]** | | [optional]
**array_array_number** | **ARRAY[ARRAY[double]]** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/perl/docs/ArrayOfNumberOnly.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use WWW::SwaggerClient::Object::ArrayOfNumberOnly;
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_number** | [**ARRAY[Number]**](Number.md) | | [optional]
**array_number** | **ARRAY[double]** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Loading

0 comments on commit f353f60

Please sign in to comment.