Merged swagger-parser 1.0.18
This commit is contained in:
@@ -40,7 +40,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile 'io.github.swagger2markup:markup-document-builder:1.0.0-SNAPSHOT'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.17'
|
||||
compile 'io.swagger:swagger-compat-spec-parser:1.0.18'
|
||||
compile 'org.apache.commons:commons-configuration2:2.0'
|
||||
compile 'commons-beanutils:commons-beanutils:1.9.2'
|
||||
compile 'org.apache.commons:commons-collections4:4.1'
|
||||
|
||||
@@ -15,7 +15,10 @@ Swagger2Markup provides an Extension SPI to extend the functionality of Swagger2
|
||||
|
||||
=== Creation of an extension
|
||||
|
||||
To create a custom extension, you have to create a class (e.g. `io.myname.MyExtension`) which extends an extension point, e.g. `io.github.swagger2markup.spi.DefinitionsDocumentExtension`.
|
||||
To create a custom extension, you have to create a class (e.g. `io.myname.MyExtension`) which extends an extension point, e.g. `io.github.swagger2markup.spi.DefinitionsDocumentExtension`. Every extension point provides to methods which must be implemented:
|
||||
|
||||
* `init`: This method is invoked once
|
||||
* `apply`: This method is invoked multiple times depending on the type of the extension point.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@@ -47,7 +50,7 @@ include::../../test/java/io/github/swagger2markup/DocumentationTest.java[tags=sw
|
||||
3. Build an instance of `Swagger2MarkupExtensionRegistry`
|
||||
4. Use the custom Swagger2MarkupExtensionRegistry
|
||||
|
||||
=== Available extensions points
|
||||
=== Extensions points
|
||||
|
||||
==== OverviewDocumentExtension
|
||||
|
||||
@@ -62,8 +65,44 @@ image::images/overview_extension_points.PNG[]
|
||||
|
||||
==== PathsDocumentExtension
|
||||
|
||||
The PathsDocumentExtension allows to extend the paths document at five positions:
|
||||
|
||||
* DOCUMENT_BEFORE: Before the section title
|
||||
* DOCUMENT_START: After the section title and before the description
|
||||
* DOCUMENT_BEFORE: At the end of the document
|
||||
* OPERATION_BEGIN: At the beginning of a path operation section
|
||||
* OPERATION_END: At the end of a path operation section
|
||||
|
||||
==== SecurityDocumentExtension
|
||||
|
||||
The SecurityDocumentExtension allows to extend the security document at five positions:
|
||||
|
||||
* DOCUMENT_BEFORE: Before the section title
|
||||
* DOCUMENT_START: After the section title and before the description
|
||||
* DOCUMENT_BEFORE: At the end of the document
|
||||
* DEFINITION_BEGIN: At the beginning of a security scheme definition section
|
||||
* DEFINITION_END: At the end of a security scheme definition section
|
||||
|
||||
==== DefinitionsDocumentExtension
|
||||
|
||||
==== SwaggerModelExtension
|
||||
The DefinitionsDocumentExtension allows to extend the definitions document at five positions:
|
||||
|
||||
* DOCUMENT_BEFORE: Before the section title
|
||||
* DOCUMENT_START: After the section title and before the description
|
||||
* DOCUMENT_BEFORE: At the end of the document
|
||||
* DEFINITION_BEGIN: At the beginning of a model definition sectiin
|
||||
* DEFINITION_END: At the end of a model definition section
|
||||
|
||||
|
||||
==== SwaggerModelExtension
|
||||
|
||||
The SwaggerModelExtension allows to modify the Swagger model before it is processed by Swagger2Markup.
|
||||
|
||||
=== Provided Extensions
|
||||
|
||||
Swagger2Markup provides some extensions which can be used out-of-the-box.
|
||||
|
||||
1. An extension which allows to dynamically import Markup from files.
|
||||
2. An extension which allows to import example Curl, HTTP request and response snippets from Spring Rest Docs.
|
||||
3. An extension which allows to import JSON or XML Schema files.
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ExamplesUtil {
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
Property item = ((AbstractSerializableParameter) parameter).getItems();
|
||||
if (item != null) {
|
||||
abstractSerializableParameterExample = PropertyUtils.convertExample(item.getExample(), item.getType());
|
||||
abstractSerializableParameterExample = item.getExample();
|
||||
if (abstractSerializableParameterExample == null) {
|
||||
abstractSerializableParameterExample = PropertyUtils.generateExample(item, markupDocBuilder);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class ExamplesUtil {
|
||||
public static Map<String, Object> exampleMapForProperties(Map<String, Property> properties, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Map<String, Object> exampleMap = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, Property> property : properties.entrySet()) {
|
||||
Object exampleObject = PropertyUtils.convertExample(property.getValue().getExample(), property.getValue().getType());
|
||||
Object exampleObject = property.getValue().getExample();
|
||||
if (exampleObject == null) {
|
||||
if (property.getValue() instanceof RefProperty) {
|
||||
exampleObject = generateExampleForRefModel(true, ((RefProperty) property.getValue()).getSimpleRef(), definitions, markupDocBuilder);
|
||||
@@ -262,7 +262,7 @@ public class ExamplesUtil {
|
||||
} else {
|
||||
Property itemProperty = model.getItems();
|
||||
if (itemProperty.getExample() != null) {
|
||||
return new Object[]{PropertyUtils.convertExample(itemProperty.getExample(), itemProperty.getType())};
|
||||
return new Object[]{itemProperty.getExample()};
|
||||
} else if (itemProperty instanceof ArrayProperty) {
|
||||
return new Object[]{generateExampleForArrayProperty((ArrayProperty) itemProperty, definitions, markupDocBuilder)};
|
||||
} else if (itemProperty instanceof RefProperty) {
|
||||
@@ -284,7 +284,7 @@ public class ExamplesUtil {
|
||||
public static Object[] generateExampleForArrayProperty(ArrayProperty value, Map<String, Model> definitions, MarkupDocBuilder markupDocBuilder) {
|
||||
Property property = value.getItems();
|
||||
if (property.getExample() != null) {
|
||||
return new Object[]{PropertyUtils.convertExample(property.getExample(), property.getType())};
|
||||
return new Object[]{property.getExample()};
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
return new Object[]{generateExampleForArrayProperty((ArrayProperty) property, definitions, markupDocBuilder)};
|
||||
} else if (property instanceof RefProperty) {
|
||||
|
||||
@@ -115,7 +115,7 @@ public final class PropertyUtils {
|
||||
Validate.notNull(property, "property must not be null");
|
||||
Object examplesValue = null;
|
||||
if (property.getExample() != null) {
|
||||
examplesValue = convertExample(property.getExample(), property.getType());
|
||||
examplesValue = property.getExample();
|
||||
} else if (property instanceof MapProperty) {
|
||||
Property additionalProperty = ((MapProperty) property).getAdditionalProperties();
|
||||
if (additionalProperty.getExample() != null) {
|
||||
|
||||
@@ -28,6 +28,7 @@ public abstract class DefinitionsDocumentExtension extends AbstractExtension {
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_AFTER,
|
||||
DOCUMENT_BEGIN,
|
||||
DOCUMENT_END,
|
||||
DEFINITION_BEGIN,
|
||||
@@ -98,6 +99,9 @@ public abstract class DefinitionsDocumentExtension extends AbstractExtension {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
levelOffset = 1;
|
||||
|
||||
@@ -25,6 +25,7 @@ public abstract class OverviewDocumentExtension extends AbstractExtension {
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_AFTER,
|
||||
DOCUMENT_BEGIN,
|
||||
DOCUMENT_END
|
||||
}
|
||||
@@ -60,6 +61,9 @@ public abstract class OverviewDocumentExtension extends AbstractExtension {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
levelOffset = 1;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package io.github.swagger2markup.spi;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.GroupBy;
|
||||
import io.github.swagger2markup.markup.builder.MarkupDocBuilder;
|
||||
import io.github.swagger2markup.model.PathOperation;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
@@ -29,6 +29,7 @@ public abstract class PathsDocumentExtension extends AbstractExtension {
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_AFTER,
|
||||
DOCUMENT_BEGIN,
|
||||
DOCUMENT_END,
|
||||
OPERATION_BEGIN,
|
||||
@@ -88,6 +89,9 @@ public abstract class PathsDocumentExtension extends AbstractExtension {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
levelOffset = 1;
|
||||
|
||||
@@ -28,6 +28,7 @@ public abstract class SecurityDocumentExtension extends AbstractExtension {
|
||||
|
||||
public enum Position {
|
||||
DOCUMENT_BEFORE,
|
||||
DOCUMENT_AFTER,
|
||||
DOCUMENT_BEGIN,
|
||||
DOCUMENT_END,
|
||||
DEFINITION_BEGIN,
|
||||
@@ -96,6 +97,9 @@ public abstract class SecurityDocumentExtension extends AbstractExtension {
|
||||
int levelOffset;
|
||||
switch (context.position) {
|
||||
case DOCUMENT_BEFORE:
|
||||
case DOCUMENT_AFTER:
|
||||
levelOffset = 0;
|
||||
break;
|
||||
case DOCUMENT_BEGIN:
|
||||
case DOCUMENT_END:
|
||||
levelOffset = 1;
|
||||
|
||||
Reference in New Issue
Block a user