Skip to content

Commit

Permalink
[cpp-restsdk] Support multi-line descriptions (OpenAPITools#753)
Browse files Browse the repository at this point in the history
* Update IndentedLambda to take optional prefix

* Add `multiline_comment_4` to CppRestSdkClient

* Update cpp-restsdk example
  • Loading branch information
Peaches491 authored and jimschubert committed Aug 9, 2018
1 parent 9075054 commit 1af8ed4
Show file tree
Hide file tree
Showing 39 changed files with 88 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@

import io.swagger.v3.oas.models.media.Schema;

import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.mustache.IndentedLambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Map;

abstract public class AbstractCppCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCppCodegen.class);
Expand Down Expand Up @@ -242,4 +246,23 @@ public String toBooleanGetter(String name) {
public String getTypeDeclaration(String str) {
return "std::shared_ptr<" + toModelName(str) + ">";
}

public void processOpts() {
super.processOpts();
addMustacheLambdas(additionalProperties);
}

private void addMustacheLambdas(Map<String, Object> objs) {

Map<String, Mustache.Lambda> lambdas = new ImmutableMap.Builder<String, Mustache.Lambda>()
.put("multiline_comment_4", new IndentedLambda(4, " ", "///"))
.build();

if (objs.containsKey("lambda")) {
LOGGER.warn("A property named 'lambda' already exists. Mustache lambdas renamed from 'lambda' to '_lambda'.");
objs.put("_lambda", lambdas);
} else {
objs.put("lambda", lambdas);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
*/
public class IndentedLambda implements Mustache.Lambda {
private final int prefixSpaceCount;
private final String prefix;
private int spaceCode;

/**
* Constructs a new instance of {@link IndentedLambda}, with an indent count of 4 spaces
*/
public IndentedLambda() {
this(4, " ");
this(4, " ", null);
}

/**
Expand All @@ -59,15 +60,38 @@ public IndentedLambda() {
* @param indentionCharacter String representation of the character used in the indent (e.g. " ", "\t", ".").
*/
public IndentedLambda(int prefixSpaceCount, String indentionCharacter) {
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0));
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0), null);
}

/**
* Constructs a new instance of {@link IndentedLambda}, with customized indent count and intention character
*
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment.
* @param indentionCharacter String representation of the character used in the indent (e.g. " ", "\t", ".").
* @param prefix An optional prefix to prepend before the line (useful for multi-line comments).
*/
public IndentedLambda(int prefixSpaceCount, String indentionCharacter, String prefix) {
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0), prefix);
}

/**
* Constructs a new instance of {@link IndentedLambda}
*
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment.
* @param indentionCodePoint Code point of the single character used for indentation.
*/
private IndentedLambda(int prefixSpaceCount, int indentionCodePoint) {
this(prefixSpaceCount, indentionCodePoint, null);
}

/**
* Constructs a new instance of {@link IndentedLambda}
*
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment.
* @param indentionCodePoint Code point of the single character used for indentation.
* @param prefix An optional prefix to prepend before the line (useful for multi-line comments).
*/
private IndentedLambda(int prefixSpaceCount, int indentionCodePoint, String prefix) {
if (prefixSpaceCount <= 0) {
throw new IllegalArgumentException("prefixSpaceCount must be greater than 0");
}
Expand All @@ -78,6 +102,7 @@ private IndentedLambda(int prefixSpaceCount, int indentionCodePoint) {

this.prefixSpaceCount = prefixSpaceCount;
this.spaceCode = indentionCodePoint;
this.prefix = prefix;
}

@Override
Expand All @@ -96,6 +121,7 @@ public void execute(Template.Fragment fragment, Writer writer) throws IOExceptio
// So, we want to skip the first line.
if (i > 0) {
sb.append(prefixedIndention);
if (prefix != null) sb.append(prefix);
}

sb.append(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public:
/// {{notes}}
/// </remarks>
{{#allParams}}
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
/// <param name="{{paramName}}">{{#lambda.multiline_comment_4}}{{description}}{{/lambda.multiline_comment_4}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}
pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {{operationId}}(
{{#allParams}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2-SNAPSHOT
3.2.1-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/IHttpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/PetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/StoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/ApiResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/Category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/Category.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/Order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/Order.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/model/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.1.2-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator 3.2.1-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Loading

0 comments on commit 1af8ed4

Please sign in to comment.