Skip to content

Commit 4b69d6a

Browse files
authored
Added support for MIME types with structured syntax suffixes (#410)
1 parent 4a3ee6c commit 4b69d6a

File tree

7 files changed

+2058
-2
lines changed

7 files changed

+2058
-2
lines changed

swagger2markup/src/main/java/io/github/swagger2markup/internal/component/PathOperationComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ private void exampleMap(MarkupDocBuilder markupDocBuilder, Map<String, Object> e
384384
while (fieldsIterator.hasNext()) {
385385
Map.Entry<String, JsonNode> field = fieldsIterator.next();
386386

387-
if (field.getKey().equals("application/json")) {
387+
if (field.getKey().equals("application/json") || field.getKey().contains("+json")) {
388388
String example = Json.pretty(field.getValue());
389389
example = stripExampleQuotes(StringEscapeUtils.unescapeJson(example));
390390

391391
markupDocBuilder.listingBlock(example, "json");
392392

393-
} else if (field.getKey().equals("application/xml")) {
393+
} else if (field.getKey().equals("application/xml") || field.getKey().contains("+xml")) {
394394

395395
String example = stripExampleQuotes(field.getValue().toString());
396396
example = StringEscapeUtils.unescapeJava(example);

swagger2markup/src/test/java/io/github/swagger2markup/AsciidocConverterTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,29 @@ public void testWithGeneratedInlineResponseExamples() throws IOException, URISyn
400400
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedInlineResponseExamples.html");
401401
}
402402

403+
@Test
404+
public void testWithExamplesAndMimeTypesSuffix() throws IOException, URISyntaxException {
405+
//Given
406+
String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples_suffix.json"), StandardCharsets.UTF_8);
407+
Path outputDirectory = Paths.get("build/test/asciidoc/examples_suffix");
408+
FileUtils.deleteQuietly(outputDirectory.toFile());
409+
410+
//When
411+
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
412+
.build();
413+
414+
Swagger2MarkupConverter.from(swaggerJsonString)
415+
.withConfig(config)
416+
.build()
417+
.toFolder(outputDirectory);
418+
419+
//Then
420+
String[] files = outputDirectory.toFile().list();
421+
assertThat(files).hasSize(4).containsAll(expectedFiles);
422+
Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/examples_suffix").toURI());
423+
DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithExamples.html");
424+
}
425+
403426
@Test
404427
public void testWithInlineSchema() throws URISyntaxException {
405428
//Given
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
[[_definitions]]
3+
== Definitions
4+
5+
[[_category]]
6+
=== Category
7+
8+
[options="header", cols=".^3a,.^11a,.^4a"]
9+
|===
10+
|Name|Description|Schema
11+
|**id** +
12+
__optional__|**Example** : `123`|integer (int64)
13+
|**name** +
14+
__optional__|**Example** : `"Canines"`|string
15+
|===
16+
17+
18+
[[_complexobject]]
19+
=== ComplexObject
20+
21+
[options="header", cols=".^3a,.^11a,.^4a"]
22+
|===
23+
|Name|Description|Schema
24+
|**subObject** +
25+
__optional__|**Example** : `{
26+
"id" : 99,
27+
"value" : "an example value !"
28+
}`|<<_subobject,SubObject>>
29+
|===
30+
31+
[[_subobject]]
32+
**SubObject**
33+
34+
[options="header", cols=".^3a,.^11a,.^4a"]
35+
|===
36+
|Name|Description|Schema
37+
|**id** +
38+
__optional__|**Example** : `88`|integer (int64)
39+
|**value** +
40+
__optional__|**Example** : `"a value !"`|string
41+
|===
42+
43+
44+
[[_identified]]
45+
=== Identified
46+
47+
[options="header", cols=".^3a,.^4a"]
48+
|===
49+
|Name|Schema
50+
|**id** +
51+
__optional__|integer (int64)
52+
|===
53+
54+
55+
[[_order]]
56+
=== Order
57+
58+
[options="header", cols=".^3a,.^11a,.^4a"]
59+
|===
60+
|Name|Description|Schema
61+
|**complete** +
62+
__optional__||boolean
63+
|**id** +
64+
__optional__|**Example** : `77`|integer (int64)
65+
|**petId** +
66+
__optional__||integer (int64)
67+
|**quantity** +
68+
__optional__||integer (int32)
69+
|**shipDate** +
70+
__optional__||string (date-time)
71+
|**status** +
72+
__optional__|Order Status|enum (placed, approved, delivered)
73+
|===
74+
75+
76+
[[_pet]]
77+
=== Pet
78+
Test description
79+
80+
81+
[options="header", cols=".^3a,.^11a,.^4a"]
82+
|===
83+
|Name|Description|Schema
84+
|**category** +
85+
__optional__||<<_category,Category>>
86+
|**id** +
87+
__optional__||integer (int64)
88+
|**name** +
89+
__required__|**Example** : `"doggie"`|string
90+
|**nicknames** +
91+
__optional__||< string, string > map
92+
|**photoUrls** +
93+
__required__||< string > array
94+
|**status** +
95+
__optional__|pet status in the store|string
96+
|**tags** +
97+
__optional__||< <<_tag,Tag>> > array
98+
|**weight** +
99+
__optional__|the weight of the pet|number
100+
|===
101+
102+
103+
[[_tag]]
104+
=== Tag
105+
106+
[options="header", cols=".^3a,.^4a"]
107+
|===
108+
|Name|Schema
109+
|**id** +
110+
__optional__|integer (int64)
111+
|**name** +
112+
__optional__|string
113+
|===
114+
115+
116+
[[_user]]
117+
=== User
118+
[%hardbreaks]
119+
__Polymorphism__ : Composition
120+
121+
122+
[options="header", cols=".^3a,.^11a,.^4a"]
123+
|===
124+
|Name|Description|Schema
125+
|**email** +
126+
__optional__||string (email)
127+
|**firstName** +
128+
__optional__||string
129+
|**id** +
130+
__optional__||integer (int64)
131+
|**lastName** +
132+
__optional__||string
133+
|**password** +
134+
__optional__||string (password)
135+
|**phone** +
136+
__optional__||string
137+
|**pictures** +
138+
__optional__||< string (byte) > array
139+
|**userStatus** +
140+
__optional__|User Status|integer (int32)
141+
|**username** +
142+
__optional__||string
143+
|===
144+
145+
146+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
= Swagger Petstore API
2+
3+
4+
[[_overview]]
5+
== Overview
6+
This is a sample server Petstore server.
7+
8+
http://swagger.wordnik.com[Learn about Swagger] or join the IRC channel `#swagger` on irc.freenode.net.
9+
10+
For this sample, you can use the api key `special-key` to test the authorization filters
11+
12+
13+
=== Version information
14+
[%hardbreaks]
15+
__Version__ : 1.0.0
16+
17+
18+
=== Contact information
19+
[%hardbreaks]
20+
__Contact__ : [email protected]
21+
22+
23+
=== License information
24+
[%hardbreaks]
25+
__License__ : Apache 2.0
26+
__License URL__ : http://www.apache.org/licenses/LICENSE-2.0.html
27+
__Terms of service__ : http://helloreverb.com/terms/
28+
29+
30+
=== URI scheme
31+
[%hardbreaks]
32+
__Host__ : petstore.swagger.wordnik.com
33+
__BasePath__ : /v2
34+
__Schemes__ : HTTP
35+
36+
37+
=== Tags
38+
39+
* pet : Pet resource
40+
* store : Store resource
41+
* user : User resource
42+
43+
44+

0 commit comments

Comments
 (0)