Compare commits
2 Commits
master
...
feature/sw
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85c5b7aa97 | ||
|
|
662cc3f40f |
@@ -35,12 +35,12 @@ repositories {
|
||||
}
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
//mavenLocal()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'io.github.swagger2markup:markup-document-builder:1.0.0'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.18'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.21-SNAPSHOT'
|
||||
compile 'org.apache.commons:commons-configuration2:2.0'
|
||||
compile 'commons-beanutils:commons-beanutils:1.9.2'
|
||||
compile 'org.apache.commons:commons-collections4:4.1'
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package io.github.swagger2markup.internal.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import io.swagger.models.*;
|
||||
@@ -27,6 +31,7 @@ import io.swagger.models.properties.RefProperty;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -36,11 +41,11 @@ public class ExamplesUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(ExamplesUtil.class);
|
||||
|
||||
/**
|
||||
* Generates a Map of response examples
|
||||
* Generates a map of response examples from the given {@code operation}
|
||||
*
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param operation the Swagger Operation
|
||||
* @param definitions the map of definitions
|
||||
* @param definitions the map of all available definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return map containing response examples.
|
||||
*/
|
||||
@@ -75,13 +80,13 @@ public class ExamplesUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates examples for request
|
||||
* Generates a map of request examples from the given {@code operation}
|
||||
*
|
||||
* @param generateMissingExamples specifies the missing examples should be generated
|
||||
* @param pathOperation the Swagger Operation
|
||||
* @param definitions the map of definitions
|
||||
* @param definitions the map of all available definitions
|
||||
* @param markupDocBuilder the markup builder
|
||||
* @return an Optional with the example content
|
||||
* @return map containing request examples
|
||||
*/
|
||||
public static Map<String, Object> generateRequestExampleMap(boolean generateMissingExamples, PathOperation pathOperation, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Operation operation = pathOperation.getOperation();
|
||||
@@ -174,6 +179,15 @@ public class ExamplesUtil {
|
||||
Object example = null;
|
||||
if (model != null) {
|
||||
example = model.getExample();
|
||||
// Workaround for https://github.com/swagger-api/swagger-parser/issues/255 returning a string
|
||||
if (model instanceof ArrayModel && example instanceof String) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
example = mapper.readTree((String) example);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
if (example == null && generateMissingExamples) {
|
||||
if (model instanceof ComposedModel) {
|
||||
example = exampleMapForProperties(getPropertiesForComposedModel((ComposedModel) model, definitions), definitions, markupDocBuilder);
|
||||
|
||||
@@ -20,6 +20,7 @@ import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -174,7 +175,6 @@ public class AsciidocConverterTest {
|
||||
|
||||
//When
|
||||
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
|
||||
.withoutInlineSchema()
|
||||
.withGeneratedExamples()
|
||||
.build();
|
||||
|
||||
@@ -190,6 +190,7 @@ public class AsciidocConverterTest {
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocConversionWithGeneratedExamples.html");
|
||||
}
|
||||
|
||||
@Ignore("swagger-parser-1.0.21 ignore Location def because it's referenced from an external ref (ExternalLocation)")
|
||||
@Test
|
||||
public void testSwagger2AsciiDocWithInlineSchema() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
@@ -212,6 +213,7 @@ public class AsciidocConverterTest {
|
||||
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testSwagger2AsciiDocWithInlineSchema.html");
|
||||
}
|
||||
|
||||
@Ignore("swagger-parser-1.0.21 ignore Location def because it's referenced from an external ref (ExternalLocation)")
|
||||
@Test
|
||||
public void testSwagger2AsciiDocWithInlineSchemaAndFlatBody() throws IOException, URISyntaxException {
|
||||
//Given
|
||||
|
||||
@@ -37,6 +37,11 @@ _optional_||integer(int64)
|
||||
|===
|
||||
|
||||
|
||||
[[_objectarray]]
|
||||
=== ObjectArray
|
||||
_Type_ : < object > array
|
||||
|
||||
|
||||
[[_order]]
|
||||
=== Order
|
||||
|
||||
|
||||
@@ -2,6 +2,32 @@
|
||||
[[_paths]]
|
||||
== Paths
|
||||
|
||||
[[_objectarray_patch]]
|
||||
=== PATCH /objectArray
|
||||
|
||||
==== Parameters
|
||||
|
||||
[options="header", cols=".^1,.^3,.^10,.^4,.^2"]
|
||||
|===
|
||||
|Type|Name|Description|Schema|Default
|
||||
|*Body*|*body* +
|
||||
_required_||<<_objectarray,ObjectArray>>|
|
||||
|===
|
||||
|
||||
|
||||
==== Example HTTP request
|
||||
|
||||
===== Request body
|
||||
[source,json]
|
||||
----
|
||||
[ {
|
||||
"op" : "replace",
|
||||
"path" : "/s",
|
||||
"v" : "w"
|
||||
} ]
|
||||
----
|
||||
|
||||
|
||||
[[_addpet]]
|
||||
=== Add a new pet to the store
|
||||
....
|
||||
|
||||
@@ -22,7 +22,19 @@ _optional_|*Example* : `"Canines"`|string
|
||||
|===
|
||||
|Name|Description|Schema
|
||||
|*subObject* +
|
||||
_optional_|*Example* : `"object"`|object
|
||||
_optional_|*Example* : `"object"`|<<_complexobject_subobject,subObject>>
|
||||
|===
|
||||
|
||||
[[_complexobject_subobject]]
|
||||
*subObject*
|
||||
|
||||
[options="header", cols=".^3,.^11,.^4"]
|
||||
|===
|
||||
|Name|Description|Schema
|
||||
|*id* +
|
||||
_optional_|*Example* : `88`|integer(int64)
|
||||
|*value* +
|
||||
_optional_|*Example* : `"a value !"`|string
|
||||
|===
|
||||
|
||||
|
||||
@@ -37,6 +49,11 @@ _optional_|*Example* : `0`|integer(int64)
|
||||
|===
|
||||
|
||||
|
||||
[[_objectarray]]
|
||||
=== ObjectArray
|
||||
_Type_ : < object > array
|
||||
|
||||
|
||||
[[_order]]
|
||||
=== Order
|
||||
|
||||
|
||||
@@ -2,6 +2,39 @@
|
||||
[[_paths]]
|
||||
== Paths
|
||||
|
||||
[[_objectarray_patch]]
|
||||
=== PATCH /objectArray
|
||||
|
||||
==== Parameters
|
||||
|
||||
[options="header", cols=".^1,.^3,.^10,.^4,.^2"]
|
||||
|===
|
||||
|Type|Name|Description|Schema|Default
|
||||
|*Body*|*body* +
|
||||
_required_||<<_objectarray,ObjectArray>>|
|
||||
|===
|
||||
|
||||
|
||||
==== Example HTTP request
|
||||
|
||||
===== Request path
|
||||
[source,json]
|
||||
----
|
||||
"/objectArray"
|
||||
----
|
||||
|
||||
|
||||
===== Request body
|
||||
[source,json]
|
||||
----
|
||||
[ {
|
||||
"op" : "replace",
|
||||
"path" : "/s",
|
||||
"v" : "w"
|
||||
} ]
|
||||
----
|
||||
|
||||
|
||||
[[_addpet]]
|
||||
=== Add a new pet to the store
|
||||
....
|
||||
|
||||
@@ -717,6 +717,20 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/objectArray": {
|
||||
"patch": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ObjectArray"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
@@ -757,6 +771,19 @@
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"ObjectArray": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
},
|
||||
"example": [
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/s",
|
||||
"v": "w"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Identified": {
|
||||
"properties": {
|
||||
"id": {
|
||||
|
||||
Reference in New Issue
Block a user