Skip to content

Commit

Permalink
Empty response support in openapi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Mar 6, 2019
1 parent 206662f commit b8defe4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ private[openapi] class EndpointToOpenApiPaths(objectSchemas: ObjectSchemas, secu
}

private def operationResponse(e: Endpoint[_, _, _, _]): Map[ResponsesKey, Right[Nothing, Response]] = {
// There always needs to be at least a 200 empty response
val okResponse = outputToResponse(e.output).getOrElse(Response("", Map.empty, Map.empty))

List(
outputToResponse(e.output).map { r =>
ResponsesCodeKey(200) -> Right(r)
},
Some(ResponsesCodeKey(200) -> Right(okResponse)),
outputToResponse(e.errorOutput).map { r =>
ResponsesDefaultKey -> Right(r)
}
Expand Down
11 changes: 11 additions & 0 deletions docs/openapi-docs/src/test/resources/expected_empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
openapi: 3.0.1
info:
title: Fruits
version: '1.0'
paths:
/:
get:
operationId: getRoot
responses:
'200':
description: ''
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ class VerifyYamlTest extends FunSuite with Matchers {
actualYamlNoIndent shouldBe expectedYaml
}

test("should support empty bodies") {
val expectedYaml = loadYaml("expected_empty.yml")

val actualYaml = List(endpoint).toOpenAPI(Info("Fruits", "1.0")).toYaml
println(actualYaml)
val actualYamlNoIndent = noIndentation(actualYaml)

actualYamlNoIndent shouldBe expectedYaml
}

private def loadYaml(fileName: String): String = {
noIndentation(Source.fromResource(fileName).getLines().mkString("\n"))
}
Expand Down

0 comments on commit b8defe4

Please sign in to comment.