Skip to content

Commit

Permalink
fix string type in c++ generator
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Apr 8, 2018
1 parent 665f0bd commit f192613
Show file tree
Hide file tree
Showing 58 changed files with 186 additions and 205 deletions.
2 changes: 1 addition & 1 deletion bin/cpprest-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -t modules/openapi-generator/src/main/resources/cpprest -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l cpprest -o samples/client/petstore/cpprest"
ags="generate -t modules/openapi-generator/src/main/resources/cpprest -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -l cpp-restsdk -o samples/client/petstore/cpprest $@"

java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/pistache-server-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 -l pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/pistache-server"
ags="$@ generate -l cpp-pistache-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -o samples/server/petstore/pistache-server"

java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/windows/cpprest-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 -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l cpprest -o samples\client\petstore\cpprest
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l cpp-restsdk -o samples\client\petstore\cpprest

java %JAVA_OPTS% -jar %executable% %ags%
2 changes: 1 addition & 1 deletion bin/windows/restbed-petstore-server.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 -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l restbed -o samples\server\petstore\restbed\
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -l cpp-restbed-server -o samples\server\petstore\restbed\

java %JAVA_OPTS% -jar %executable% %ags%
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {

op.bodyParam.vendorExtensions.put("x-codegen-pistache-isStringOrDate", op.bodyParam.isString || op.bodyParam.isDate);
}
if(op.consumes != null) {
if (op.consumes != null) {
for (Map<String, String> consume : op.consumes) {
if (consume.get("mediaType") != null && consume.get("mediaType").equals("application/json")) {
consumeJson = true;
Expand All @@ -189,17 +189,17 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {

op.httpMethod = op.httpMethod.substring(0, 1).toUpperCase() + op.httpMethod.substring(1).toLowerCase();

for(CodegenParameter param : op.allParams){
if (param.isFormParam) isParsingSupported=false;
if (param.isFile) isParsingSupported=false;
if (param.isCookieParam) isParsingSupported=false;
for (CodegenParameter param : op.allParams) {
if (param.isFormParam) isParsingSupported = false;
if (param.isFile) isParsingSupported = false;
if (param.isCookieParam) isParsingSupported = false;

//TODO: This changes the info about the real type but it is needed to parse the header params
if (param.isHeaderParam) {
param.dataType = "Optional<Net::Http::Header::Raw>";
param.baseType = "Optional<Net::Http::Header::Raw>";
} else if(param.isQueryParam){
if(param.isPrimitiveType) {
} else if (param.isQueryParam) {
if (param.isPrimitiveType) {
param.dataType = "Optional<" + param.dataType + ">";
} else {
param.dataType = "Optional<" + param.baseType + ">";
Expand Down Expand Up @@ -227,15 +227,15 @@ public String toModelFilename(String name) {
public String apiFilename(String templateName, String tag) {
String result = super.apiFilename(templateName, tag);

if ( templateName.endsWith("impl-header.mustache") ) {
if (templateName.endsWith("impl-header.mustache")) {
int ix = result.lastIndexOf('/');
result = result.substring(0, ix) + result.substring(ix, result.length() - 2) + "Impl.h";
result = result.replace(apiFileFolder(), implFileFolder());
} else if ( templateName.endsWith("impl-source.mustache") ) {
} else if (templateName.endsWith("impl-source.mustache")) {
int ix = result.lastIndexOf('/');
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "Impl.cpp";
result = result.replace(apiFileFolder(), implFileFolder());
} else if ( templateName.endsWith("api-server.mustache") ) {
} else if (templateName.endsWith("api-server.mustache")) {
int ix = result.lastIndexOf('/');
result = result.substring(0, ix) + result.substring(ix, result.length() - 4) + "MainServer.cpp";
result = result.replace(apiFileFolder(), outputFolder);
Expand All @@ -254,11 +254,11 @@ public String toApiFilename(String name) {
* for different property types
*
* @return a string value used as the `dataType` field for model templates,
* `returnType` for api templates
* `returnType` for api templates
*/
@Override
public String getTypeDeclaration(Schema p) {
String swaggerType = getSchemaType(p);
String openAPIType = getSchemaType(p);

if (p instanceof ArraySchema) {
ArraySchema ap = (ArraySchema) p;
Expand All @@ -269,13 +269,14 @@ public String getTypeDeclaration(Schema p) {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "<std::string, " + getTypeDeclaration(inner) + ">";
}
if (p instanceof StringSchema || p instanceof DateSchema
if (p instanceof StringSchema || SchemaTypeUtil.STRING_TYPE.equals(p.getType())
|| p instanceof DateSchema
|| p instanceof DateTimeSchema || p instanceof FileSchema
|| languageSpecificPrimitives.contains(swaggerType)) {
return toModelName(swaggerType);
|| languageSpecificPrimitives.contains(openAPIType)) {
return toModelName(openAPIType);
}

return "std::shared_ptr<" + swaggerType + ">";
return "std::shared_ptr<" + openAPIType + ">";
}

@Override
Expand Down Expand Up @@ -358,14 +359,14 @@ private String implFileFolder() {
*/
@Override
public String getSchemaType(Schema p) {
String swaggerType = super.getSchemaType(p);
String openAPIType = super.getSchemaType(p);
String type = null;
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (languageSpecificPrimitives.contains(type))
return toModelName(type);
} else
type = swaggerType;
type = openAPIType;
return toModelName(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,12 @@ public String getTypeDeclaration(Schema p) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
}
if (isMapSchema(p)) {
} else if (isMapSchema(p)) {
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
}
if (p instanceof StringSchema || p instanceof DateSchema
|| p instanceof DateTimeSchema || p instanceof FileSchema
} else if (p instanceof StringSchema || SchemaTypeUtil.STRING_TYPE.equals(p.getType())
|| p instanceof DateSchema || p instanceof DateTimeSchema
|| p instanceof FileSchema
|| languageSpecificPrimitives.contains(openAPIType)) {
return toModelName(openAPIType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{#bodyParam}}
nlohmann::json request_body = nlohmann::json::parse(request.body());
{{^isPrimitiveType}}
{{paramName}}.fromJson(request_body); {{/isPrimitiveType}}
{{paramName}}.fromJson(request_body);
{{/isPrimitiveType}}
{{#isPrimitiveType}}
// The conversion is done automatically by the json library
{{paramName}} = request_body;
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0-SNAPSHOT
3.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ApiConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ApiConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ApiException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ApiException.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/HttpContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/HttpContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/IHttpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/JsonBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/JsonBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/MultipartFormData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/MultipartFormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpprest/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* OpenAPI spec version: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
Expand Down
Loading

0 comments on commit f192613

Please sign in to comment.