Skip to content

Commit 22ddb2a

Browse files
committed
openapi: asciidoc output #3820
- attempt to control new lines
1 parent 2fb853d commit 22ddb2a

File tree

4 files changed

+37
-38
lines changed

4 files changed

+37
-38
lines changed

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/asciidoc/SnippetResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public SnippetResolver(Path baseDir) {
2626

2727
public String apply(String snippet, Map<String, Object> context) throws IOException {
2828
var writer = new StringWriter();
29-
var snippetContent = resolve(baseDir, snippet);
30-
engine.getLiteralTemplate(snippetContent).evaluate(writer, context);
29+
var snippetContent = resolve(baseDir, snippet).trim().replaceAll("\r\n", "\n");
30+
var template = engine.getLiteralTemplate(snippetContent);
31+
template.evaluate(writer, context);
3132
return writer.toString();
3233
}
3334

modules/jooby-openapi/src/test/java/io/jooby/internal/openapi/asciidoc/FilterTest.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void requestParams() {
8989
|`+string+`
9090
|
9191
92-
|===
92+
|===\
9393
""",
9494
queryParameters.apply(
9595
operation("GET", "/api/library/{isbn}").query("foo", "bar").build(),
@@ -107,7 +107,7 @@ public void requestParams() {
107107
|`+string+`
108108
|
109109
110-
|===
110+
|===\
111111
""",
112112
pathParameters.apply(
113113
operation("GET", "/api/library/{isbn}").path("isbn").build(),
@@ -125,7 +125,7 @@ public void requestParams() {
125125
|`+single-sign-on+`
126126
|
127127
128-
|===
128+
|===\
129129
""",
130130
cookieParameters.apply(
131131
operation("GET", "/api/library/{isbn}").cookie("single-sign-on").build(),
@@ -148,7 +148,7 @@ public void requestParams() {
148148
|`+string+`
149149
|
150150
151-
|===
151+
|===\
152152
""",
153153
formParameters.apply(
154154
operation("POST", "/api/library")
@@ -182,7 +182,7 @@ public void requestParams() {
182182
|`+string+`
183183
|
184184
185-
|===
185+
|===\
186186
""",
187187
requestParameters.apply(
188188
operation("POST", "/api/library")
@@ -209,7 +209,7 @@ public void curl() {
209209
[source,bash]
210210
----
211211
curl -X GET 'https://api.libray.com/api/library/{isbn}'
212-
----
212+
----\
213213
""",
214214
curl.apply(
215215
operation("GET", "/api/library/{isbn}").build(),
@@ -224,7 +224,7 @@ public void curl() {
224224
[source,bash]
225225
----
226226
curl -X GET 'https://api.libray.com/api/library/{isbn}?foo=string&bar=string'
227-
----
227+
----\
228228
""",
229229
curl.apply(
230230
operation("GET", "/api/library/{isbn}").query("foo", "bar").build(),
@@ -241,7 +241,7 @@ public void curl() {
241241
curl --data-urlencode 'foo=string'\\
242242
--data-urlencode 'bar=string'\\
243243
-X POST 'https://api.libray.com/api/library/{isbn}'
244-
----
244+
----\
245245
""",
246246
curl.apply(
247247
operation("POST", "/api/library/{isbn}").form("foo", "bar").build(),
@@ -258,7 +258,7 @@ public void curl() {
258258
curl --data-urlencode 'foo=string'\\
259259
--data-urlencode 'bar=string'\\
260260
-X POST 'https://api.libray.com/api/library/{isbn}?active=boolean'
261-
----
261+
----\
262262
""",
263263
curl.apply(
264264
operation("POST", "/api/library/{isbn}")
@@ -281,7 +281,7 @@ public void curl() {
281281
----
282282
curl -i\\
283283
-X GET 'https://api.libray.com/api/library/{isbn}'
284-
----
284+
----\
285285
""",
286286
curl.apply(
287287
operation("GET", "/api/library/{isbn}").build(),
@@ -297,7 +297,7 @@ public void curl() {
297297
----
298298
curl -i\\
299299
-X POST 'https://api.libray.com/api/library/{isbn}'
300-
----
300+
----\
301301
""",
302302
curl.apply(
303303
operation("GET", "/api/library/{isbn}").build(),
@@ -313,7 +313,7 @@ public void curl() {
313313
----
314314
curl -H 'Accept: application/json'\\
315315
-X GET 'https://api.libray.com/api/library/{isbn}'
316-
----
316+
----\
317317
""",
318318
curl.apply(
319319
operation("GET", "/api/library/{isbn}").produces("application/json").build(),
@@ -329,7 +329,7 @@ public void curl() {
329329
----
330330
curl -H 'Accept: application/xml'\\
331331
-X GET 'https://api.libray.com/api/library/{isbn}'
332-
----
332+
----\
333333
""",
334334
curl.apply(
335335
operation("GET", "/api/library/{isbn}").produces("application/json").build(),
@@ -345,7 +345,7 @@ public void curl() {
345345
curl -H 'Content-Type: application/json'\\
346346
-d '{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}'\\
347347
-X POST 'https://api.libray.com/api/library'
348-
----
348+
----\
349349
""",
350350
curl.apply(
351351
operation("POST", "/api/library").body(new Book(), "application/json").build(),
@@ -362,7 +362,7 @@ public void curl() {
362362
--data-urlencode 'name=string'\\
363363
-F "file=@/file.extension"\\
364364
-X POST 'https://api.libray.com/api/library'
365-
----
365+
----\
366366
""",
367367
curl.apply(
368368
operation("POST", "/api/library")
@@ -382,7 +382,7 @@ public void httpRequest() {
382382
[source,http,options="nowrap"]
383383
----
384384
GET /api/library/{isbn} HTTP/1.1
385-
----
385+
----\
386386
""",
387387
httpRequest.apply(
388388
operation("GET", "/api/library/{isbn}").build(),
@@ -397,7 +397,7 @@ public void httpRequest() {
397397
----
398398
GET /api/library/{isbn} HTTP/1.1
399399
Accept: application/json
400-
----
400+
----\
401401
""",
402402
httpRequest.apply(
403403
operation("GET", "/api/library/{isbn}").produces("application/json").build(),
@@ -413,7 +413,7 @@ public void httpRequest() {
413413
POST /api/library HTTP/1.1
414414
Content-Type: application/json
415415
{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}
416-
----
416+
----\
417417
""",
418418
httpRequest.apply(
419419
operation("POST", "/api/library").body(new Book(), "application/json").build(),
@@ -430,7 +430,7 @@ public void httpResponse() {
430430
[source,http,options="nowrap"]
431431
----
432432
HTTP/1.1 200 Success
433-
----
433+
----\
434434
""",
435435
httpResponse.apply(
436436
operation("GET", "/api/library/{isbn}").defaultResponse().build(),
@@ -445,7 +445,7 @@ public void httpResponse() {
445445
----
446446
HTTP/1.1 200 Success
447447
Content-Type: application/json
448-
----
448+
----\
449449
""",
450450
httpResponse.apply(
451451
operation("GET", "/api/library/{isbn}")
@@ -464,7 +464,7 @@ public void httpResponse() {
464464
HTTP/1.1 201 Created
465465
Content-Type: application/json
466466
{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}
467-
----
467+
----\
468468
""",
469469
httpResponse.apply(
470470
operation("POST", "/api/library")
@@ -483,7 +483,7 @@ public void httpResponse() {
483483
HTTP/1.1 201 Created
484484
Content-Type: application/json
485485
{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}
486-
----
486+
----\
487487
""",
488488
httpResponse.apply(
489489
operation("POST", "/api/library")
@@ -502,7 +502,7 @@ public void httpResponse() {
502502
HTTP/1.1 400 Bad Request
503503
Content-Type: application/json
504504
{"path":"string","message":"string","code":"int32"}
505-
----
505+
----\
506506
""",
507507
httpResponse.apply(
508508
operation("POST", "/api/library")
@@ -551,7 +551,7 @@ public void responseFields() {
551551
|`+binary+`
552552
|
553553
554-
|===
554+
|===\
555555
""",
556556
responseFields.apply(
557557
operation("POST", "/api/library")
@@ -596,7 +596,7 @@ public void responseFields() {
596596
|`+binary+`
597597
|
598598
599-
|===
599+
|===\
600600
""",
601601
responseFields.apply(
602602
operation("POST", "/api/library")
@@ -625,7 +625,7 @@ public void responseFields() {
625625
|`+int32+`
626626
|
627627
628-
|===
628+
|===\
629629
""",
630630
responseFields.apply(
631631
operation("POST", "/api/library")
@@ -655,7 +655,7 @@ public void statusCode() {
655655
"authors" : [ ],
656656
"image" : "binary"
657657
}
658-
----
658+
----\
659659
""",
660660
statusCode.apply(
661661
operation("POST", "/api/library")
@@ -678,7 +678,7 @@ public void statusCode() {
678678
"message" : "string",
679679
"code" : "int32"
680680
}
681-
----
681+
----\
682682
""",
683683
statusCode.apply(
684684
operation("POST", "/api/library")
@@ -700,7 +700,7 @@ public void schema() {
700700
[source,json]
701701
----
702702
{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}
703-
----
703+
----\
704704
""",
705705
schema.apply(
706706
operation("POST", "/api/library")
@@ -718,7 +718,7 @@ public void schema() {
718718
[source,json]
719719
----
720720
{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}
721-
----
721+
----\
722722
""",
723723
schema.apply(
724724
operation("POST", "/api/library")
@@ -736,7 +736,7 @@ public void schema() {
736736
[source,json]
737737
----
738738
{"isbn":"string","title":"string","publicationDate":"date","text":"string","type":"string","authors":[],"image":"binary"}
739-
----
739+
----\
740740
""",
741741
schema.apply(
742742
operation("POST", "/api/library")

modules/jooby-openapi/src/test/java/issues/i3729/api/ApiDocTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public void shouldGenerateAdoc(OpenAPIResult result) {
5252
-X GET 'https://api.fake-museum-example.com/v1/api/library?title=string&author=string&isbn=string1&isbn=string2&isbn=string3'
5353
----
5454
55-
5655
==== Request Fields
5756
5857
|===
@@ -72,10 +71,8 @@ public void shouldGenerateAdoc(OpenAPIResult result) {
7271
7372
|===
7473
75-
7674
=== Find a book by ISBN
7775
78-
7976
[source,bash]
8077
----
8178
curl -i\\
@@ -117,7 +114,6 @@ public void shouldGenerateAdoc(OpenAPIResult result) {
117114
}
118115
----
119116
120-
121117
==== Response Fields
122118
123119
|===

modules/jooby-openapi/src/test/resources/adoc/library.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ ${ listBooks | curl }
2929
${ listBooks | queryParameters }
3030

3131
=== Find a book by ISBN
32-
3332
{% set bookByISBN = operation("GET", "/api/library/{isbn}") %}
3433
${ bookByISBN | curl("-i") }
34+
3535
${ bookByISBN | statusCode(200) }
36+
3637
${ bookByISBN | statusCode(400) }
38+
3739
${ bookByISBN | statusCode(404) }
3840

3941
==== Response Fields

0 commit comments

Comments
 (0)