Compare commits

...

6 Commits

Author SHA1 Message Date
Robert Winkler
d8c3cf725d Release 1.3.1 2017-03-20 12:28:44 +01:00
Robert Winkler
aecc531d84 Added gradle.properties to set file.encoding and sun.jnu.encoding to UTF-8 2017-03-17 09:25:30 +01:00
shardings
f107779542 Fix request path and query params' example support. (#247)
Fix request path and query params' example support.
2017-03-16 09:01:45 +01:00
shardings
70bf17011c Improve the zh_CN translation. (#246)
For human:
default_column: 默认列 -> 默认值
example_column: 例子 -> 样例
schema_column: 架构 -> 类型
overview: 概观 -> 概览
2017-03-14 16:40:01 +01:00
Robert Winkler
86ae19fe2a Update version to 1.3.1-SNAPSHOT 2017-02-20 08:39:59 +01:00
Robert Winkler
e8235c4c35 Updated README 2017-02-20 08:38:20 +01:00
10 changed files with 273 additions and 7 deletions

View File

@@ -27,7 +27,7 @@ image::src/docs/asciidoc/images/Swagger2Markup.PNG[]
image::src/docs/asciidoc/images/Swagger2Markup_definitions.PNG[]
== Reference documentation
- http://swagger2markup.github.io/swagger2markup/1.2.0/[Reference Documentation]
- http://swagger2markup.github.io/swagger2markup/1.3.0/[Reference Documentation]
- https://github.com/Swagger2Markup/swagger2markup/blob/master/RELEASENOTES.adoc[Release notes]
- https://github.com/Swagger2Markup/spring-swagger2markup-demo[Demo using Swagger2Markup, Spring Boot, Springfox and spring-restdocs]

View File

@@ -129,3 +129,6 @@
* Updated paleo-core from 0.10.1 to 0.10.2
* Updated swagger-parser from v1.0.23 to v1.0.25
* Decimal numbers are formatted into locale-specific strings
=== Version 1.3.1
* PR #247: Fix request path and query params example support.

View File

@@ -13,8 +13,8 @@ buildscript {
}
}
description = 'swagger2markup Build'
version = '1.3.0'
ext.releaseVersion = '1.3.0'
version = '1.3.1'
ext.releaseVersion = '1.3.1'
group = 'io.github.swagger2markup'
apply plugin: 'java'

2
gradle.properties Normal file
View File

@@ -0,0 +1,2 @@
systemProp.file.encoding=UTF-8
systemProp.sun.jnu.encoding=UTF-8

View File

@@ -124,6 +124,9 @@ public class ExamplesUtil {
if (generateMissingExamples) {
Object abstractSerializableParameterExample;
abstractSerializableParameterExample = ((AbstractSerializableParameter) parameter).getExample();
if (abstractSerializableParameterExample == null) {
abstractSerializableParameterExample = parameter.getVendorExtensions().get("x-example");
}
if (abstractSerializableParameterExample == null) {
Property item = ((AbstractSerializableParameter) parameter).getItems();
if (item != null) {

View File

@@ -1,5 +1,5 @@
definitions=\u5b9a\u4e49
default_column=\u9ed8\u8ba4\u5217
default_column=\u9ed8\u8ba4\u503c
# validators
minlength_column=\u6700\u5c0f\u957f\u5ea6
maxlength_column=\u6700\u5927\u957f\u5ea6
@@ -9,13 +9,13 @@ minvalue_column=\u6700\u5c0f\u503c
minvalue_exclusive_column=\u6700\u5c0f\u503c(\u4e0d\u5305\u62ec)
maxvalue_column=\u6700\u5927\u503c
maxvalue_exclusive_column=\u6700\u5927\u503c(\u4e0d\u5305\u62ec)
example_column=\u4f8b\u5b50
example_column=\u6837\u4f8b
flags.column=\u6807\u5fd7
flags.required=\u5fc5\u586b
flags.optional=\u53ef\u9009
flags.read_only=\u53ea\u8bfb
flags.read_write=\u8bfb\u5199
schema_column=\u67b6\u6784
schema_column=\u7c7b\u578b
name_column=\u540d\u79f0
description_column=\u8bf4\u660e
headers_column=\u5934
@@ -23,7 +23,7 @@ scopes_column=\u4f5c\u7528\u57df
produces=\u751f\u6210
consumes=\u6d88\u8017
tags=\u6807\u7b7e
overview=\u6982\u89c2
overview=\u6982\u89c8
current_version=\u7248\u672c\u4fe1\u606f
version=\u7248\u672c
contact_information=\u8054\u7cfb\u65b9\u5f0f

View File

@@ -15,8 +15,10 @@
*/
package io.github.swagger2markup.internal.component;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.assertions.DiffUtils;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.internal.resolver.DefinitionDocumentResolverFromOperation;
import io.github.swagger2markup.internal.resolver.SecurityDocumentResolver;
import io.github.swagger2markup.internal.utils.PathUtils;
@@ -30,7 +32,9 @@ import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PathOperationComponentTest extends AbstractComponentTest {
@@ -96,5 +100,72 @@ public class PathOperationComponentTest extends AbstractComponentTest {
}
@Test
public void testWithPathParamExample() throws URISyntaxException {
String COMPONENT_NAME = "path_operation_with_path_param_example";
Path outputDirectory = getOutputFile(COMPONENT_NAME);
FileUtils.deleteQuietly(outputDirectory.toFile());
Map<String, String> configMap = new HashMap<>();
configMap.put("swagger2markup.generatedExamplesEnabled", "true"); // enable example
//Given
Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
Swagger swagger = converter.getContext().getSwagger();
io.swagger.models.Path path = swagger.getPaths().get("/pets/{petId}");
List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets/{petId}", path);
Swagger2MarkupConverter.Context context = converter.getContext();
MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
//When
markupDocBuilder = new PathOperationComponent(context,
new DefinitionDocumentResolverFromOperation(context),
new SecurityDocumentResolver(context)).
apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
//Then
Path expectedFile = getExpectedFile(COMPONENT_NAME);
DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}
@Test
public void testWithQueryParamExample() throws URISyntaxException {
String COMPONENT_NAME = "path_operation_with_query_param_example";
Path outputDirectory = getOutputFile(COMPONENT_NAME);
FileUtils.deleteQuietly(outputDirectory.toFile());
Map<String, String> configMap = new HashMap<>();
configMap.put("swagger2markup.generatedExamplesEnabled", "true"); // enable example
//Given
Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
Swagger swagger = converter.getContext().getSwagger();
io.swagger.models.Path path = swagger.getPaths().get("/pets/findByTags");
List<PathOperation> pathOperations = PathUtils.toPathOperationsList("/pets/findByTags", path);
Swagger2MarkupConverter.Context context = converter.getContext();
MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();
//When
markupDocBuilder = new PathOperationComponent(context,
new DefinitionDocumentResolverFromOperation(context),
new SecurityDocumentResolver(context)).
apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));
markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);
//Then
Path expectedFile = getExpectedFile(COMPONENT_NAME);
DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}
}

View File

@@ -0,0 +1,89 @@
[[_getpetbyid]]
=== Find pet by ID
....
GET /pets/{petId}
....
==== Description
Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
==== Parameters
[options="header", cols=".^2,.^3,.^9,.^4"]
|===
|Type|Name|Description|Schema
|**Path**|**petId** +
__required__|ID of pet that needs to be fetched|integer (int64)
|===
==== Responses
[options="header", cols=".^2,.^14,.^4"]
|===
|HTTP Code|Description|Schema
|**200**|successful operation +
**Headers** : +
`X-Rate-Limit-Limit` (integer) : The number of allowed requests in the current period. +
`X-Rate-Limit-Remaining` (integer) : The number of remaining requests in the current period. +
`X-Rate-Limit-Reset` (integer) : The number of seconds left in the current period.|<<_pet,Pet>>
|**400**|Invalid ID supplied|No Content
|**404**|Pet not found|No Content
|===
==== Produces
* `application/json`
* `application/xml`
==== Tags
* pet
==== Security
[options="header", cols=".^3,.^4,.^13"]
|===
|Type|Name|Scopes
|**apiKey**|**<<_api_key,api_key>>**|
|**oauth2**|**<<_petstore_auth,petstore_auth>>**|write_pets,read_pets
|===
==== Example HTTP request
===== Request path
----
/pets/30
----
==== Example HTTP response
===== Response 200
[source,json]
----
{
"id" : 0,
"category" : {
"id" : 0,
"name" : "FoobarCategory"
},
"name" : "doggie",
"photoUrls" : [ "string" ],
"tags" : [ {
"id" : 0,
"name" : "string"
} ],
"status" : "string"
}
----

View File

@@ -0,0 +1,96 @@
[[_findpetsbytags]]
=== Finds Pets by tags
....
GET /pets/findByTags
....
==== Description
Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
==== Parameters
[options="header", cols=".^2,.^3,.^9,.^4"]
|===
|Type|Name|Description|Schema
|**Query**|**tags** +
__optional__|Tags to filter by|< string > array(multi)
|===
==== Responses
[options="header", cols=".^2,.^14,.^4"]
|===
|HTTP Code|Description|Schema
|**200**|successful operation +
**Headers** : +
`X-Rate-Limit-Limit` (integer) : The number of allowed requests in the current period. +
`X-Rate-Limit-Remaining` (integer) : The number of remaining requests in the current period. +
`X-Rate-Limit-Reset` (integer) : The number of seconds left in the current period.|< <<_pet,Pet>> > array
|**400**|Invalid tag value|No Content
|===
==== Produces
* `application/json`
* `application/xml`
==== Tags
* pet
==== Security
[options="header", cols=".^3,.^4,.^13"]
|===
|Type|Name|Scopes
|**oauth2**|**<<_petstore_auth,petstore_auth>>**|write_pets,read_pets
|===
==== Example HTTP request
===== Request path
----
/pets/findByTags
----
===== Request query
[source,json]
----
{
"tags" : "adorable"
}
----
==== Example HTTP response
===== Response 200
[source,json]
----
[ {
"id" : 0,
"category" : {
"id" : 0,
"name" : "FoobarCategory"
},
"name" : "doggie",
"photoUrls" : [ "string" ],
"tags" : [ {
"id" : 0,
"name" : "string"
} ],
"status" : "string"
} ]
----

View File

@@ -134,6 +134,7 @@ paths:
items:
type: string
collectionFormat: multi
x-example: adorable
responses:
"200":
description: successful operation
@@ -174,6 +175,7 @@ paths:
required: true
type: integer
format: int64
x-example: 30
responses:
"404":
description: Pet not found