Skip to content
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 @@ -40,6 +40,7 @@
import java.util.*;

import static io.github.swagger2markup.internal.utils.MapUtils.toKeySet;
import static org.apache.commons.lang3.BooleanUtils.isTrue;
import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

Expand All @@ -58,8 +59,10 @@ public abstract class MarkupDocumentBuilder {

protected final String PATTERN_COLUMN;
protected final String MINVALUE_COLUMN;
protected final String MINVALUE_EXCLUSIVE_COLUMN;
protected final String MAXVALUE_COLUMN;

protected final String MAXVALUE_EXCLUSIVE_COLUMN;


protected final String EXAMPLE_COLUMN;
protected final String SCHEMA_COLUMN;
Expand Down Expand Up @@ -103,7 +106,9 @@ public abstract class MarkupDocumentBuilder {
PATTERN_COLUMN = labels.getString("pattern_column");
MINVALUE_COLUMN = labels.getString("minvalue_column");
MAXVALUE_COLUMN = labels.getString("maxvalue_column");

MINVALUE_EXCLUSIVE_COLUMN = labels.getString("minvalue_exclusive_column");
MAXVALUE_EXCLUSIVE_COLUMN = labels.getString("maxvalue_exclusive_column");

EXAMPLE_COLUMN = labels.getString("example_column");
FLAGS_COLUMN = labels.getString("flags.column");
FLAGS_REQUIRED = labels.getString("flags.required");
Expand Down Expand Up @@ -211,15 +216,17 @@ protected List<ObjectType> buildPropertiesTable(Map<String, Property> properties
Integer minlength = PropertyUtils.getMinlength(property);
String pattern = PropertyUtils.getPattern(property);
Number minValue = PropertyUtils.getMin(property);
Boolean exclusiveMin = PropertyUtils.getExclusiveMin(property);
Number maxValue = PropertyUtils.getMax(property);
Boolean exclusiveMax = PropertyUtils.getExclusiveMax(property);

MarkupDocBuilder propertyNameContent = copyMarkupDocBuilder();
propertyNameContent.boldTextLine(propertyName, true);
if (BooleanUtils.isTrue(property.getRequired()))
if (isTrue(property.getRequired()))
propertyNameContent.italicText(FLAGS_REQUIRED.toLowerCase());
else
propertyNameContent.italicText(FLAGS_OPTIONAL.toLowerCase());
if (BooleanUtils.isTrue(property.getReadOnly())) {
if (isTrue(property.getReadOnly())) {
propertyNameContent.newLine(true);
propertyNameContent.italicText(FLAGS_READ_ONLY.toLowerCase());
}
Expand Down Expand Up @@ -270,17 +277,21 @@ protected List<ObjectType> buildPropertiesTable(Map<String, Property> properties

descriptionContent.boldText(PATTERN_COLUMN).text(COLON).literalText(Json.pretty(pattern));
}

if(minValue != null){
if (isNotBlank(descriptionContent.toString()))
descriptionContent.newLine(true);
descriptionContent.boldText(MINVALUE_COLUMN).text(COLON).literalText(minValue.toString());

String minValueColumn = isTrue(exclusiveMin) ? MINVALUE_EXCLUSIVE_COLUMN : MINVALUE_COLUMN;
descriptionContent.boldText(minValueColumn).text(COLON).literalText(minValue.toString());
}

if(maxValue != null){
if (isNotBlank(descriptionContent.toString()))
descriptionContent.newLine(true);
descriptionContent.boldText(MAXVALUE_COLUMN).text(COLON).literalText(maxValue.toString());

String maxValueColumn = isTrue(exclusiveMax) ? MAXVALUE_EXCLUSIVE_COLUMN : MAXVALUE_COLUMN;
descriptionContent.boldText(maxValueColumn).text(COLON).literalText(maxValue.toString());
}

if (example != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ public static Number getMin(Property property) {
}
return min;
}

/**
* Retrieves the exclusiveMinimum value of a property, or otherwise returns null.
*
* @param property the property
* @return the exclusiveMinimum value of the property, or otherwise null
*/
public static Boolean getExclusiveMin(Property property) {
Validate.notNull(property, "property must not be null");
Boolean exclusiveMin = null;

if (property instanceof AbstractNumericProperty){
AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
exclusiveMin = numericProperty.getExclusiveMinimum();
}
return exclusiveMin;
}

/**
* Retrieves the minimum value of a property, or otherwise returns null.
Expand All @@ -218,6 +235,23 @@ public static Number getMax(Property property) {
}
return max;
}

/**
* Retrieves the exclusiveMaximum value of a property, or otherwise returns null.
*
* @param property the property
* @return the exclusiveMaximum value of the property, or otherwise null
*/
public static Boolean getExclusiveMax(Property property) {
Validate.notNull(property, "property must not be null");
Boolean exclusiveMax = null;

if (property instanceof AbstractNumericProperty){
AbstractNumericProperty numericProperty = (AbstractNumericProperty) property;
exclusiveMax = numericProperty.getExclusiveMaximum();
}
return exclusiveMax;
}

/**
* Return example display string for the given {@code property}.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
definitions=Definitionen

default_column=Standard

# validators
Expand All @@ -7,7 +8,9 @@ maxlength_column=Maximale L
length_column=L�nge
pattern_column=Pattern
minvalue_column=Mindestwert
minvalue_exclusive_column=Mindestwert (exklusiv)
maxvalue_column=Maximalwert
maxvalue_exclusive_column=Maximalwert (exklusiv)

example_column=Beispiel
flags.column=Flags
Expand Down Expand Up @@ -37,7 +40,7 @@ uri_scheme=URI Schema
host=Host
base_path=Basis-Pfad
schemes=Schemata
security_name=
security_name=Name
security_type=Typ
security_in=In
security_flow=Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ maxlength_column=Maximal length
length_column=Length
pattern_column=Pattern
minvalue_column=Minimum value
minvalue_exclusive_column=Minimum value (exclusive)
maxvalue_column=Maximum value
maxvalue_exclusive_column=Maximum value (exclusive)

example_column=Example
flags.column=Flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ maxlength_column=Longitud m
length_column=Longitud
pattern_column=Patr�n
minvalue_column=Valor m�nimo
minvalue_exclusive_column=Valor m�nimo (exclusivo)
maxvalue_column=Valor m�ximo
maxvalue_exclusive_column=Valor m�ximo (exclusivo)

example_column=Ejemplo
flags.column=Flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ maxlength_column=Longueur maximale
length_column=Longueur
pattern_column=Mod\u00E8le
minvalue_column=Valeur minimale
minvalue_exclusive_column=Valeur minimale (exclusif)
maxvalue_column=Valeur maximale
maxvalue_exclusive_column=Valeur maximale (exclusif)

example_column=Exemple
flags.column=Modificateurs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ maxlength_column=Maximal length
length_column=Length
pattern_column=Pattern
minvalue_column=Minimum value
minvalue_exclusive_column=Minimum value (exclusive)
maxvalue_column=Maximum value
maxvalue_exclusive_column=Maximum value (exclusive)

flags.column=Flags
flags.required=\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ maxlength_column=Maximal length
length_column=Length
pattern_column=Pattern
minvalue_column=Minimum value
minvalue_exclusive_column=Minimum value (exclusive)
maxvalue_column=Maximum value
maxvalue_exclusive_column=Maximum value (exclusive)

example_column=\u00D6rnek
flags.column=Bayraklar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ maxlength_column=最大长度
length_column=长度
pattern_column=模式
minvalue_column=最小值
minvalue_exclusive_column=最小值(不包括)
maxvalue_column=最大值
maxvalue_exclusive_column=最大值(不包括)

example_column=例子
flags.column=标志
Expand Down
49 changes: 13 additions & 36 deletions src/test/java/io/github/swagger2markup/AsciidocConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,65 +389,42 @@ public void testSwagger2AsciiDocConversionWithSeparatedOperations() throws IOExc

@Test
public void testSwagger2AsciiDocConversionWithRussianOutputLanguage() throws IOException, URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory.toFile());

//When
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withOutputLanguage(Language.RU)
.build();
Swagger2MarkupConverter.from(file)
.withConfig(config)
.build()
.toFolder(outputDirectory);

//Then
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")), Charset.forName("UTF-8")))
.contains("== Определения");
testSwagger2AsciiDocConversionWithOutputLanguage(Language.RU, "definitions.adoc", "== Определения");
}

@Test
public void testSwagger2AsciiDocConversionWithFrenchOutputLanguage() throws IOException, URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory.toFile());

//When
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withOutputLanguage(Language.FR)
.build();
Swagger2MarkupConverter.from(file)
.withConfig(config)
.build()
.toFolder(outputDirectory);
testSwagger2AsciiDocConversionWithOutputLanguage(Language.FR, "overview.adoc", "== Sch\u00E9ma d'URI");
}

//Then
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")), Charset.forName("UTF-8")))
.contains("== Sch\u00E9ma d'URI");
@Test
public void testSwagger2AsciiDocConversionWithGermanOutputLanguage() throws IOException, URISyntaxException {
testSwagger2AsciiDocConversionWithOutputLanguage(Language.DE, "definitions.adoc", "Beschreibung");
}

@Test
public void testSwagger2AsciiDocConversionWithSpanishOutputLanguage() throws IOException, URISyntaxException {
testSwagger2AsciiDocConversionWithOutputLanguage(Language.ES, "definitions.adoc", "Descripción");
}

private void testSwagger2AsciiDocConversionWithOutputLanguage(Language language, String outputFilename, String expected) throws IOException, URISyntaxException {
//Given
Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
Path outputDirectory = Paths.get("build/test/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory.toFile());

//When
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withOutputLanguage(Language.ES)
.withOutputLanguage(language)
.build();
Swagger2MarkupConverter.from(file)
.withConfig(config)
.build()
.toFolder(outputDirectory);

//Then
assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")), Charset.forName("UTF-8")))
.contains("Descripción");
assertThat(new String(Files.readAllBytes(outputDirectory.resolve(outputFilename)), Charset.forName("UTF-8")))
.contains(expected);
}

@Test
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/expected/asciidoc/validators/definitions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
_optional_|sample double with range 0.0-10.0 +
*Minimum value* : `0.0` +
*Maximum value* : `10.0`|number(double)
|*sampleDoubleExclusiveBoth* +
_optional_|sample double with range 0.0-10.0 (both exclusive) +
*Minimum value (exclusive)* : `0.0` +
*Maximum value (exclusive)* : `10.0`|number(double)
|*sampleDoubleExclusiveMaximum* +
_optional_|sample double with range to 10.0 (exclusive) +
*Maximum value (exclusive)* : `10.0`|number(double)
|*sampleDoubleExclusiveMinimum* +
_optional_|sample double with range from 0.0 (exclusive) +
*Minimum value (exclusive)* : `0.0`|number(double)
|*sampleDoubleNoDescription* +
_optional_|*Minimum value* : `0.0` +
*Maximum value* : `10.0`|number(double)
Expand Down
23 changes: 23 additions & 0 deletions src/test/resources/json/swagger_validators.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@
"format":"double",
"description": "sample double with range to 10.0",
"maximum": 10.0
},
"sampleDoubleExclusiveMinimum": {
"type":"number",
"format":"double",
"description": "sample double with range from 0.0 (exclusive)",
"minimum": 0.0,
"exclusiveMinimum": true
},
"sampleDoubleExclusiveMaximum": {
"type":"number",
"format":"double",
"description": "sample double with range to 10.0 (exclusive)",
"maximum": 10.0,
"exclusiveMaximum": true
},
"sampleDoubleExclusiveBoth": {
"type":"number",
"format":"double",
"description": "sample double with range 0.0-10.0 (both exclusive)",
"minimum": 0.0,
"maximum": 10.0,
"exclusiveMinimum": true,
"exclusiveMaximum": true
}
}
}
Expand Down