Introduced tableRow() to escape table contents

This commit is contained in:
Hugo de Paix de Coeur
2016-02-02 18:35:16 +01:00
parent 8da5d3a770
commit 60c687f3f8
2 changed files with 16 additions and 6 deletions

View File

@@ -18,6 +18,8 @@
*/
package io.github.robwin.swagger2markup.builder.document;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import io.github.robwin.markup.builder.MarkupDocBuilder;
import io.github.robwin.markup.builder.MarkupDocBuilders;
import io.github.robwin.markup.builder.MarkupLanguage;
@@ -25,7 +27,6 @@ import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig;
import io.github.robwin.swagger2markup.type.ObjectType;
import io.github.robwin.swagger2markup.type.RefType;
import io.github.robwin.swagger2markup.type.Type;
import io.github.robwin.swagger2markup.utils.MarkupDocBuilderUtils;
import io.github.robwin.swagger2markup.utils.PropertyUtils;
import io.swagger.models.Swagger;
import io.swagger.models.properties.Property;
@@ -114,6 +115,15 @@ public abstract class MarkupDocument {
return name + "-" + typeIdCount.getAndIncrement();
}
public static String tableRow(List<String> cells) {
return join(Collections2.transform(cells, new Function<String, String>() {
@Override
public String apply(final String cell) {
return cell.replace(DELIMITER, "{vbar}");
}
}), DELIMITER);
}
public List<Type> typeProperties(Type type, int depth, PropertyDescriptor propertyDescriptor, MarkupDocBuilder docBuilder) {
List<Type> localDefinitions = new ArrayList<>();
if (type instanceof ObjectType) {
@@ -140,7 +150,7 @@ public abstract class MarkupDocument {
Boolean.toString(property.getRequired()),
propertyType.displaySchema(markupLanguage),
PropertyUtils.getDefaultValue(property));
headerAndContent.add(join(content, DELIMITER));
headerAndContent.add(tableRow(content));
}
docBuilder.tableWithHeaderRow(headerAndContent);
}

View File

@@ -307,7 +307,7 @@ public class PathsDocument extends MarkupDocument {
Boolean.toString(parameter.getRequired()),
type.displaySchema(markupLanguage),
ParameterUtils.getDefaultValue(parameter));
headerAndContent.add(join(content, DELIMITER));
headerAndContent.add(tableRow(content));
}
addPathSectionTitle(PARAMETERS);
this.markupDocBuilder.tableWithHeaderRow(headerAndContent);
@@ -500,9 +500,9 @@ public class PathsDocument extends MarkupDocument {
localDefinitions.add(type);
type = new RefType(type);
}
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + type.displaySchema(markupLanguage));
csvContent.add(tableRow(Arrays.asList(entry.getKey(), response.getDescription(), type.displaySchema(markupLanguage))));
}else{
csvContent.add(entry.getKey() + DELIMITER + response.getDescription() + DELIMITER + NO_CONTENT);
csvContent.add(tableRow(Arrays.asList(entry.getKey(), response.getDescription(), NO_CONTENT)));
}
}
addPathSectionTitle(RESPONSES);
@@ -521,7 +521,7 @@ public class PathsDocument extends MarkupDocument {
}
List<Type> localDefinitions = typeProperties(definition, depth, new PropertyDescriptor(definition), this.markupDocBuilder);
for (Type localDefinition : localDefinitions)
inlineDefinitions(Arrays.asList(localDefinition), depth - 1);
inlineDefinitions(Collections.singletonList(localDefinition), depth - 1);
}
}