Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed indent lambda to not strip line breaks #16930

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void execute(Template.Fragment fragment, Writer writer) throws IOExceptio
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).
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -30,5 +34,13 @@ public void indentedCountTest() {
"{{#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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Capitalization {
sCAETHFlowPoints?: string;
/**
* Name of the pet
*
* @type {string}
* @memberof Capitalization
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Capitalization {
sCAETHFlowPoints?: string;
/**
* Name of the pet
*
* @type {string}
* @memberof Capitalization
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void Another_fakeDummyResource::handler_PATCH_internal(const std::shared_ptr<res
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ void FooResource::handler_GET_internal(const std::shared_ptr<restbed::Session> s
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down
40 changes: 40 additions & 0 deletions samples/server/petstore/cpp-restbed/generated/3_0/api/FakeApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ void FakeBigDecimalMapResource::handler_GET_internal(const std::shared_ptr<restb
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -304,6 +306,8 @@ void FakeHealthResource::handler_GET_internal(const std::shared_ptr<restbed::Ses
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -421,6 +425,8 @@ void FakeHttp_signature_testResource::handler_GET_internal(const std::shared_ptr
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -535,6 +541,8 @@ void FakeOuterBooleanResource::handler_POST_internal(const std::shared_ptr<restb
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -650,6 +658,8 @@ void FakeOuterCompositeResource::handler_POST_internal(const std::shared_ptr<res
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -764,6 +774,8 @@ void FakeOuterNumberResource::handler_POST_internal(const std::shared_ptr<restbe
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -879,6 +891,8 @@ void FakeOuterStringResource::handler_POST_internal(const std::shared_ptr<restbe
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -994,6 +1008,8 @@ void FakePropertyEnum_intResource::handler_POST_internal(const std::shared_ptr<r
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -1107,6 +1123,8 @@ void FakeBody_with_binaryResource::handler_PUT_internal(const std::shared_ptr<re
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -1220,6 +1238,8 @@ void FakeBody_with_file_schemaResource::handler_PUT_internal(const std::shared_p
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -1335,6 +1355,8 @@ void FakeBody_with_query_paramsResource::handler_PUT_internal(const std::shared_
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -1459,6 +1481,8 @@ void FakeResource::handler_PATCH_internal(const std::shared_ptr<restbed::Session
return;
}
defaultSessionClose(session, status_code, result);


}

// x-extension
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1759,6 +1789,8 @@ void FakeInline_additionalPropertiesResource::handler_POST_internal(const std::s
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -1872,6 +1904,8 @@ void FakeInline_freeform_additionalPropertiesResource::handler_POST_internal(con
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -1984,6 +2018,8 @@ void FakeJsonFormDataResource::handler_GET_internal(const std::shared_ptr<restbe
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -2097,6 +2133,8 @@ void FakeNullableResource::handler_POST_internal(const std::shared_ptr<restbed::
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -2240,6 +2278,8 @@ void FakeTest_query_parametersResource::handler_PUT_internal(const std::shared_p
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ void Fake_classname_testResource::handler_PATCH_internal(const std::shared_ptr<r
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down
18 changes: 18 additions & 0 deletions samples/server/petstore/cpp-restbed/generated/3_0/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ void PetResource::handler_POST_internal(const std::shared_ptr<restbed::Session>
return;
}
defaultSessionClose(session, status_code, result);


}

// x-extension
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -400,6 +404,8 @@ void PetPetIdResource::handler_DELETE_internal(const std::shared_ptr<restbed::Se
return;
}
defaultSessionClose(session, status_code, result);


}

// x-extension
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -641,6 +651,8 @@ void PetFindByStatusResource::handler_GET_internal(const std::shared_ptr<restbed
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -764,6 +776,8 @@ void PetFindByTagsResource::handler_GET_internal(const std::shared_ptr<restbed::
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -880,6 +894,8 @@ void PetPetIdUploadImageResource::handler_POST_internal(const std::shared_ptr<re
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -996,6 +1012,8 @@ void FakePetIdUploadImageWithRequiredFileResource::handler_POST_internal(const s
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ void StoreOrderOrder_idResource::handler_DELETE_internal(const std::shared_ptr<r
return;
}
defaultSessionClose(session, status_code, result);


}

// x-extension
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -374,6 +378,8 @@ void StoreInventoryResource::handler_GET_internal(const std::shared_ptr<restbed:
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down Expand Up @@ -496,6 +502,8 @@ void StoreOrderResource::handler_POST_internal(const std::shared_ptr<restbed::Se
return;
}
defaultSessionClose(session, status_code, result);


}


Expand Down
Loading
Loading