Skip to content

Commit

Permalink
Upgrade to OpenAPI 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rojekp committed May 10, 2021
1 parent 6d532fd commit dbe8567
Show file tree
Hide file tree
Showing 98 changed files with 222 additions and 94 deletions.
31 changes: 31 additions & 0 deletions apispec/openapi-circe/src/test/resources/expected_webhooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"openapi": "3.1.0",
"info": {
"title": "Fruits",
"version": "1.0"
},
"paths": {
"/": {
"get": {
"operationId": "getRoot",
"responses": {
"200": {
"description": "Default description"
}
}
}
}
},
"webhooks": {
"newPet": {
"get": {
"operationId": "getRoot",
"responses": {
"200": {
"description": "Default description"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"openapi": "3.1.0",
"info": {
"title": "Fruits",
"version": "1.0"
},
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
"paths": {
"/": {
"get": {
"operationId": "getRoot",
"responses": {
"200": {
"description": "Default description"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package sttp.tapir.openapi.circe

import io.circe.Printer
import io.circe.syntax.EncoderOps
import sttp.tapir.apispec.ReferenceOr
import sttp.tapir.openapi._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

import scala.collection.immutable.ListMap
import scala.io.Source

class TapirOpenAPICirceTest extends AnyFunSuite with Matchers {

test("should match the expected yaml with schema dialect") {
val expectedJson = load("expected_with_schema_dialect.json")
val responsesList = ListMap[ResponsesKey, ReferenceOr[Response]](ResponsesCodeKey(200) -> Right(Response(description = "Default description")))
val responses = Responses(responsesList)
val operation = Operation(operationId = "getRoot", responses = responses)
val pathItem = PathItem(get = Some(operation))

val actualJson = OpenAPI(
info = Info("Fruits", "1.0"),
jsonSchemaDialect = Some("https://json-schema.org/draft/2020-12/schema"),
tags = List.empty,
servers = List.empty,
paths = Paths(ListMap[String, PathItem]("/" -> pathItem)),
webhooks = None,
components = None,
security = List.empty)
.asJson
val actualJsonNoIndent = noIndentation(Printer.spaces2.print(actualJson))

actualJsonNoIndent shouldBe expectedJson
}

test("should match the expected yaml with webhooks") {
val expectedJson = load("expected_webhooks.json")
val responsesList = ListMap[ResponsesKey, ReferenceOr[Response]](ResponsesCodeKey(200) -> Right(Response(description = "Default description")))
val responses = Responses(responsesList)
val operation = Operation(operationId = "getRoot", responses = responses)
val eitherPathItem = Right(PathItem(get = Some(operation)))
val pathItem = PathItem(get = Some(operation))

val actualJson= OpenAPI(
info = Info("Fruits", "1.0"),
jsonSchemaDialect = None,
tags = List.empty,
servers = List.empty,
paths = Paths(ListMap[String, PathItem]("/" -> pathItem)),
webhooks = Some(Map("newPet" -> eitherPathItem)),
components = None,
security = List.empty)
.asJson
val actualJsonNoIndent = noIndentation(Printer.spaces2.print(actualJson))

actualJsonNoIndent shouldBe expectedJson
}

private def load(fileName: String): String = {
noIndentation(Source.fromInputStream(getClass.getResourceAsStream(s"/$fileName")).getLines().mkString("\n"))
}
private def noIndentation(s: String): String = s.replaceAll("[ \t]", "").trim

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import sttp.tapir.apispec.{ExampleValue, ExtensionValue, ReferenceOr, Schema, Se
import scala.collection.immutable.ListMap

case class OpenAPI(
openapi: String = "3.0.3",
openapi: String = "3.1.0",
info: Info,
jsonSchemaDialect: Option[String],
tags: List[Tag],
servers: List[Server],
paths: Paths,
webhooks: Option[Map[String, ReferenceOr[PathItem]]],
components: Option[Components],
security: List[SecurityRequirement],
extensions: ListMap[String, ExtensionValue] = ListMap.empty
Expand All @@ -27,6 +29,10 @@ case class OpenAPI(
def servers(s: List[Server]): OpenAPI = copy(servers = s)

def tags(t: List[Tag]): OpenAPI = copy(tags = t)

def jsonSchemaDialect(d: Option[String]): OpenAPI = copy(jsonSchemaDialect = d)

def webhooks(wh: Option[Map[String, ReferenceOr[PathItem]]]): OpenAPI = copy(webhooks = wh)
}

case class Info(
Expand Down Expand Up @@ -74,7 +80,8 @@ case class ServerVariable(
case class Components(
schemas: ListMap[String, ReferenceOr[Schema]],
securitySchemes: ListMap[String, ReferenceOr[SecurityScheme]],
extensions: ListMap[String, ExtensionValue] = ListMap.empty
extensions: ListMap[String, ExtensionValue] = ListMap.empty,
pathItems: ListMap[String, ReferenceOr[PathItem]] = ListMap.empty
)

case class Paths(
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ lazy val openapiCirce: ProjectMatrix = (projectMatrix in file("apispec/openapi-c
libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % Versions.circe,
"io.circe" %% "circe-parser" % Versions.circe,
"io.circe" %% "circe-generic" % Versions.circe
"io.circe" %% "circe-generic" % Versions.circe,
scalaTest.value % Test
),
name := "tapir-openapi-circe"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ private[openapi] object EndpointToOpenAPIDocs {
paths = Paths(ListMap.empty),
components = componentsCreator.components,
security = List.empty,
extensions = DocsExtensions.fromIterable(docsExtensions)
extensions = DocsExtensions.fromIterable(docsExtensions),
jsonSchemaDialect = Option.empty,
webhooks = Option.empty
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: My Bookshop
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Countries
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Errors
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Games
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Examples
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Examples
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-docs/src/test/resources/expected.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openapi" : "3.0.3",
"openapi" : "3.1.0",
"info" : {
"title" : "Fruits",
"version" : "1.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-docs/src/test/resources/expected.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Examples
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Entities
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: "3.0.3"
openapi: "3.1.0"
info:
title: "String style"
version: "1.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-docs/src/test/resources/expected_empty.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: 3.0.3
openapi: 3.1.0
info:
title: Fruits
version: '1.0'
Expand Down
Loading

0 comments on commit dbe8567

Please sign in to comment.