Fix for issue #5460 (#5778)

* Fix issue 5460

* Handling only first and last double quote to support example with double quote in the middle

* Fix proposed by @ePaul

* Add comments to explain de fixStringModel function. Add an enum model called PetStatus that test this scenario. Update sample only for JavaPlayFramework generator
This commit is contained in:
Jean-François Côté
2017-07-24 13:20:36 -04:00
committed by wing328
parent 64658f0bea
commit 79e10c427a
4 changed files with 75 additions and 7 deletions

View File

@@ -161,7 +161,7 @@ public class InlineModelResolver {
Map<String, Property> properties = m.getProperties();
flattenProperties(properties, modelName);
fixStringModel(m);
} else if (model instanceof ArrayModel) {
ArrayModel m = (ArrayModel) model;
Property inner = m.getItems();
@@ -191,6 +191,21 @@ public class InlineModelResolver {
}
}
/**
* This function fix models that are string (mostly enum). Before this fix, the example
* would look something like that in the doc: "\"example from def\""
* @param m Model implementation
*/
private void fixStringModel(ModelImpl m) {
if (m.getType() != null && m.getType().equals("string") && m.getExample() != null) {
String example = m.getExample().toString();
if (example.substring(0, 1).equals("\"") &&
example.substring(example.length() - 1).equals("\"")) {
m.setExample(example.substring(1, example.length() - 1));
}
}
}
private String resolveModelName(String title, String key) {
if (title == null) {
return uniqueName(key);