fixed lambda to not strip line breaks (#16930)

This commit is contained in:
devhl-labs
2023-10-28 23:08:04 -04:00
committed by GitHub
parent 677b6e64c1
commit 5a5ee163dc
17 changed files with 143 additions and 1 deletions

View File

@@ -112,7 +112,7 @@ public class IndentedLambda implements Mustache.Lambda {
String prefixedIndention = StringUtils.repeat(new String(Character.toChars(spaceCode)), prefixSpaceCount);
StringBuilder sb = new StringBuilder();
// use \n instead of System.lineSeparator (e.g. \r\n in Windows) as templates use \n
String[] lines = text.split("\n");
String[] lines = text.split("\n", -1);
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
// Mustache will apply correct indentation to the first line of a template (to match declaration location).

View File

@@ -1,9 +1,13 @@
package org.openapitools.codegen.templating.mustache;
import static org.junit.Assert.assertEquals;
import java.util.Map;
import org.testng.annotations.Test;
import com.samskivert.mustache.Mustache;
public class IndentedLambdaTest extends LambdaTest {
String lineSeparator = "\n";
@@ -30,5 +34,13 @@ public class IndentedLambdaTest extends LambdaTest {
"{{#indented}}first line" + lineSeparator + "second line{{/indented}}", ctx);
}
@Test
public void lineBreaksPreservedTest() {
Map<String, Object> ctx = context("indented", new IndentedLambda(4, " ", true, true));
String actual = execute(Mustache.compiler(), "{{#indented}}first line\nsecond line\n\nthird line\n\n\nfourth line\n\n{{/indented}}", ctx);
String expected = " first line\n second line\n\n third line\n\n\n fourth line\n\n";
assertEquals(expected, actual);
}
}

View File

@@ -51,6 +51,7 @@ export interface Capitalization {
sCAETHFlowPoints?: string;
/**
* Name of the pet
*
* @type {string}
* @memberof Capitalization
*/

View File

@@ -51,6 +51,7 @@ export interface Capitalization {
sCAETHFlowPoints?: string;
/**
* Name of the pet
*
* @type {string}
* @memberof Capitalization
*/

View File

@@ -197,6 +197,8 @@ void Another_fakeDummyResource::handler_PATCH_internal(const std::shared_ptr<res
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -191,6 +191,8 @@ void FooResource::handler_GET_internal(const std::shared_ptr<restbed::Session> s
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -193,6 +193,8 @@ void FakeBigDecimalMapResource::handler_GET_internal(const std::shared_ptr<restb
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -304,6 +306,8 @@ void FakeHealthResource::handler_GET_internal(const std::shared_ptr<restbed::Ses
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -421,6 +425,8 @@ void FakeHttp_signature_testResource::handler_GET_internal(const std::shared_ptr
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -535,6 +541,8 @@ void FakeOuterBooleanResource::handler_POST_internal(const std::shared_ptr<restb
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -650,6 +658,8 @@ void FakeOuterCompositeResource::handler_POST_internal(const std::shared_ptr<res
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -764,6 +774,8 @@ void FakeOuterNumberResource::handler_POST_internal(const std::shared_ptr<restbe
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -879,6 +891,8 @@ void FakeOuterStringResource::handler_POST_internal(const std::shared_ptr<restbe
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -994,6 +1008,8 @@ void FakePropertyEnum_intResource::handler_POST_internal(const std::shared_ptr<r
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -1107,6 +1123,8 @@ void FakeBody_with_binaryResource::handler_PUT_internal(const std::shared_ptr<re
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -1220,6 +1238,8 @@ void FakeBody_with_file_schemaResource::handler_PUT_internal(const std::shared_p
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -1335,6 +1355,8 @@ void FakeBody_with_query_paramsResource::handler_PUT_internal(const std::shared_
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -1459,6 +1481,8 @@ void FakeResource::handler_PATCH_internal(const std::shared_ptr<restbed::Session
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
@@ -1519,6 +1543,8 @@ void FakeResource::handler_POST_internal(const std::shared_ptr<restbed::Session>
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
void FakeResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {
@@ -1587,6 +1613,8 @@ void FakeResource::handler_GET_internal(const std::shared_ptr<restbed::Session>
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
void FakeResource::handler_DELETE_internal(const std::shared_ptr<restbed::Session> session) {
@@ -1632,6 +1660,8 @@ void FakeResource::handler_DELETE_internal(const std::shared_ptr<restbed::Sessio
return;
}
defaultSessionClose(session, status_code, result);
}
std::pair<int, Client> FakeResource::handler_PATCH(
@@ -1759,6 +1789,8 @@ void FakeInline_additionalPropertiesResource::handler_POST_internal(const std::s
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -1872,6 +1904,8 @@ void FakeInline_freeform_additionalPropertiesResource::handler_POST_internal(con
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -1984,6 +2018,8 @@ void FakeJsonFormDataResource::handler_GET_internal(const std::shared_ptr<restbe
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -2097,6 +2133,8 @@ void FakeNullableResource::handler_POST_internal(const std::shared_ptr<restbed::
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -2240,6 +2278,8 @@ void FakeTest_query_parametersResource::handler_PUT_internal(const std::shared_p
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -197,6 +197,8 @@ void Fake_classname_testResource::handler_PATCH_internal(const std::shared_ptr<r
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -205,6 +205,8 @@ void PetResource::handler_POST_internal(const std::shared_ptr<restbed::Session>
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
@@ -270,6 +272,8 @@ void PetResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> s
return;
}
defaultSessionClose(session, status_code, result);
}
int PetResource::handler_POST(
@@ -400,6 +404,8 @@ void PetPetIdResource::handler_DELETE_internal(const std::shared_ptr<restbed::Se
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
@@ -458,6 +464,8 @@ void PetPetIdResource::handler_GET_internal(const std::shared_ptr<restbed::Sessi
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
void PetPetIdResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) {
@@ -509,6 +517,8 @@ void PetPetIdResource::handler_POST_internal(const std::shared_ptr<restbed::Sess
return;
}
defaultSessionClose(session, status_code, result);
}
int PetPetIdResource::handler_DELETE(
@@ -641,6 +651,8 @@ void PetFindByStatusResource::handler_GET_internal(const std::shared_ptr<restbed
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -764,6 +776,8 @@ void PetFindByTagsResource::handler_GET_internal(const std::shared_ptr<restbed::
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -880,6 +894,8 @@ void PetPetIdUploadImageResource::handler_POST_internal(const std::shared_ptr<re
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -996,6 +1012,8 @@ void FakePetIdUploadImageWithRequiredFileResource::handler_POST_internal(const s
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -201,6 +201,8 @@ void StoreOrderOrder_idResource::handler_DELETE_internal(const std::shared_ptr<r
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
@@ -259,6 +261,8 @@ void StoreOrderOrder_idResource::handler_GET_internal(const std::shared_ptr<rest
return;
}
defaultSessionClose(session, status_code, result);
}
int StoreOrderOrder_idResource::handler_DELETE(
@@ -374,6 +378,8 @@ void StoreInventoryResource::handler_GET_internal(const std::shared_ptr<restbed:
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -496,6 +502,8 @@ void StoreOrderResource::handler_POST_internal(const std::shared_ptr<restbed::Se
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -193,6 +193,8 @@ void UserResource::handler_POST_internal(const std::shared_ptr<restbed::Session>
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -304,6 +306,8 @@ void UserCreateWithArrayResource::handler_POST_internal(const std::shared_ptr<re
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -415,6 +419,8 @@ void UserCreateWithListResource::handler_POST_internal(const std::shared_ptr<res
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -537,6 +543,8 @@ void UserUsernameResource::handler_DELETE_internal(const std::shared_ptr<restbed
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
@@ -595,6 +603,8 @@ void UserUsernameResource::handler_GET_internal(const std::shared_ptr<restbed::S
return;
}
defaultSessionClose(session, status_code, result);
}
// x-extension
void UserUsernameResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) {
@@ -645,6 +655,8 @@ void UserUsernameResource::handler_PUT_internal(const std::shared_ptr<restbed::S
return;
}
defaultSessionClose(session, status_code, result);
}
int UserUsernameResource::handler_DELETE(
@@ -779,6 +791,8 @@ void UserLoginResource::handler_GET_internal(const std::shared_ptr<restbed::Sess
return;
}
defaultSessionClose(session, status_code, result);
}
@@ -886,6 +900,8 @@ void UserLogoutResource::handler_GET_internal(const std::shared_ptr<restbed::Ses
return;
}
defaultSessionClose(session, status_code, result);
}

View File

@@ -40,6 +40,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -50,6 +51,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -99,6 +101,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}
@@ -148,6 +151,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}
@@ -181,6 +185,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}
@@ -191,6 +196,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -201,6 +207,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -222,6 +229,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}

View File

@@ -34,6 +34,7 @@ fun Route.StoreApi() {
delete<Paths.deleteOrder> {
call.respond(HttpStatusCode.NotImplemented)
}
authenticate("api_key") {
@@ -43,6 +44,7 @@ fun Route.StoreApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -62,6 +64,7 @@ fun Route.StoreApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
post<Paths.placeOrder> {
@@ -80,6 +83,7 @@ fun Route.StoreApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}

View File

@@ -34,18 +34,22 @@ fun Route.UserApi() {
post<Paths.createUser> {
call.respond(HttpStatusCode.NotImplemented)
}
post<Paths.createUsersWithArrayInput> {
call.respond(HttpStatusCode.NotImplemented)
}
post<Paths.createUsersWithListInput> {
call.respond(HttpStatusCode.NotImplemented)
}
delete<Paths.deleteUser> {
call.respond(HttpStatusCode.NotImplemented)
}
get<Paths.getUserByName> {
@@ -66,18 +70,22 @@ fun Route.UserApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
get<Paths.loginUser> {
call.respond(HttpStatusCode.NotImplemented)
}
get<Paths.logoutUser> {
call.respond(HttpStatusCode.NotImplemented)
}
put<Paths.updateUser> {
call.respond(HttpStatusCode.NotImplemented)
}
}

View File

@@ -40,6 +40,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -50,6 +51,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -99,6 +101,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}
@@ -148,6 +151,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}
@@ -181,6 +185,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}
@@ -191,6 +196,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -201,6 +207,7 @@ fun Route.PetApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -222,6 +229,7 @@ fun Route.PetApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}

View File

@@ -34,6 +34,7 @@ fun Route.StoreApi() {
delete<Paths.deleteOrder> {
call.respond(HttpStatusCode.NotImplemented)
}
authenticate("api_key") {
@@ -43,6 +44,7 @@ fun Route.StoreApi() {
call.respond(HttpStatusCode.NotImplemented)
}
}
@@ -62,6 +64,7 @@ fun Route.StoreApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
post<Paths.placeOrder> {
@@ -80,6 +83,7 @@ fun Route.StoreApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
}

View File

@@ -34,18 +34,22 @@ fun Route.UserApi() {
post<Paths.createUser> {
call.respond(HttpStatusCode.NotImplemented)
}
post<Paths.createUsersWithArrayInput> {
call.respond(HttpStatusCode.NotImplemented)
}
post<Paths.createUsersWithListInput> {
call.respond(HttpStatusCode.NotImplemented)
}
delete<Paths.deleteUser> {
call.respond(HttpStatusCode.NotImplemented)
}
get<Paths.getUserByName> {
@@ -66,18 +70,22 @@ fun Route.UserApi() {
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
else -> call.respondText(exampleContentString)
}
}
get<Paths.loginUser> {
call.respond(HttpStatusCode.NotImplemented)
}
get<Paths.logoutUser> {
call.respond(HttpStatusCode.NotImplemented)
}
put<Paths.updateUser> {
call.respond(HttpStatusCode.NotImplemented)
}
}