Workaround: If the type of a BodyParameter is String and not a Model, the schema is null and lost. Therefore the fallback type of a BodyParameter is String now.

This commit is contained in:
Robert Winkler
2015-07-20 08:20:06 +02:00
parent 3ed894688c
commit 3469523225
6 changed files with 82 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
= Swagger2Markup
:author: Robert Winkler
:version: <
:hardbreaks:
image:https://travis-ci.org/RobWin/swagger2markup.svg?branch=master["Build Status", link="https://travis-ci.org/RobWin/swagger2markup"] image:https://coveralls.io/repos/RobWin/swagger2markup/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/swagger2markup"] image:https://api.bintray.com/packages/robwin/maven/swagger2markup/images/download.svg[link="https://bintray.com/robwin/maven/swagger2markup/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://img.shields.io/badge/Twitter-rbrtwnklr-blue.svg["Twitter", link="https://twitter.com/rbrtwnklr"] image:https://badges.gitter.im/Join%20Chat.svg[link="https://gitter.im/RobWin/swagger2markup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]

View File

@@ -56,4 +56,7 @@
* Added possibility to write object definitions to separate files. Issue #19
== Version 0.7.0
* Added support for both reference models and composed models
* Added support for both reference models and composed models
== Version 0.7.1
* Workaround: If the type of a BodyParameter is String and not a Model, the schema is null and lost. Therefore the fallback type of a BodyParameter is String now.

View File

@@ -13,7 +13,7 @@ buildscript {
}
}
description = 'swagger2markup Build'
version = '0.7.0'
version = '0.7.1'
group = 'io.github.robwin'
apply plugin: 'java'

View File

@@ -39,7 +39,12 @@ public final class ParameterUtils {
if(parameter instanceof BodyParameter){
BodyParameter bodyParameter = (BodyParameter)parameter;
Model model = bodyParameter.getSchema();
type = ModelUtils.getType(model, markupLanguage);
if(model != null){
type = ModelUtils.getType(model, markupLanguage);
}else{
type = "string";
}
}
else if(parameter instanceof AbstractSerializableParameter){
AbstractSerializableParameter serializableParameter = (AbstractSerializableParameter)parameter;

View File

@@ -39,9 +39,6 @@ import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.BDDAssertions.assertThat;
/**
* @author Robert Winkler
*/
public class Swagger2MarkupConverterTest {
@Test
@@ -60,6 +57,23 @@ public class Swagger2MarkupConverterTest {
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
}
@Test
public void testOldSwaggerSpec2AsciiDocConversion() throws IOException {
//Given
File file = new File(Swagger2MarkupConverterTest.class.getResource("/json/swagger_12.json").getFile());
File outputDirectory = new File("build/docs/asciidoc/generated");
FileUtils.deleteQuietly(outputDirectory);
//When
Swagger2MarkupConverter.from(file.getAbsolutePath()).build()
.intoFolder(outputDirectory.getAbsolutePath());
//Then
String[] directories = outputDirectory.list();
assertThat(directories).hasSize(3).containsAll(asList("definitions.adoc", "overview.adoc", "paths.adoc"));
}
@Test
public void testSwagger2AsciiDocConversionWithDescriptionsAndExamples() throws IOException {
//Given

View File

@@ -0,0 +1,54 @@
{
"apiVersion" : "0.0.1-SNAPSHOT",
"swaggerVersion" : "1.2",
"basePath" : "",
"resourcePath" : "/resource/x/v2",
"apis" : [ {
"path" : "/resource/x/v2",
"operations" : [ {
"method" : "POST",
"nickname" : "createX",
"type" : "string",
"parameters" : [ {
"type": "string",
"description" : "The x in JSON format",
"paramType" : "body",
"name" : "body",
"required" : true
} ],
"summary" : "Creates a x x.",
"notes" : "If id already exists, the x is updated.",
"responseMessages" : [ {
"code" : 200,
"message" : "ok"
}, {
"code" : 500,
"message" : "error"
} ],
"consumes" : [ "application/json" ]
} ]
}, {
"path" : "/resource/x/v2/{id}",
"operations" : [ {
"method" : "GET",
"nickname" : "getX",
"type" : "string",
"parameters" : [ {
"type" : "integer",
"description" : "A valid x x UUID",
"paramType" : "path",
"name" : "id",
"required" : true
} ],
"summary" : "Gets the x x with the specified id.",
"responseMessages" : [ {
"code" : 200,
"message" : "ok"
}, {
"code" : 404,
"message" : "not found"
} ],
"produces" : [ "application/json" ]
} ]
} ]
}