Skip to content

Commit

Permalink
Merge pull request #989 from softwaremill/bug/761
Browse files Browse the repository at this point in the history
use SString schema for LocalDateTime codec
  • Loading branch information
adamw authored Feb 8, 2021
2 parents b4df49f + 44f59b7 commit da00a0e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
23 changes: 10 additions & 13 deletions core/src/main/scala/sttp/tapir/Schema.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package sttp.tapir

import java.io.InputStream
import java.math.{BigDecimal => JBigDecimal}
import java.nio.ByteBuffer
import java.time._
import java.util.{Date, UUID}

import magnolia.Magnolia
import sttp.model.Part
import sttp.tapir.SchemaType._
import sttp.tapir.generic.Derived
import sttp.tapir.generic.internal.OneOfMacro.oneOfMacro
import sttp.tapir.generic.internal.SchemaMapMacro
import sttp.tapir.generic.internal.{SchemaMagnoliaDerivation, SchemaMapMacro}
import sttp.tapir.internal.ModifySchemaMacro

import scala.annotation.StaticAnnotation
import scala.annotation.implicitNotFound
import sttp.tapir.generic.Derived
import sttp.tapir.generic.internal.SchemaMagnoliaDerivation
import magnolia.Magnolia
import java.io.InputStream
import java.math.{BigDecimal => JBigDecimal}
import java.nio.ByteBuffer
import java.time._
import java.util.{Date, UUID}
import scala.annotation.{StaticAnnotation, implicitNotFound}

/** Describes the type `T`: its low-level representation, meta-data and validation rules.
* @param format The name of the format of the low-level representation of `T`.
Expand Down Expand Up @@ -142,7 +139,7 @@ object Schema extends SchemaExtensions with SchemaMagnoliaDerivation with LowPri
implicit val schemaForZonedDateTime: Schema[ZonedDateTime] = Schema(SDateTime)
implicit val schemaForOffsetDateTime: Schema[OffsetDateTime] = Schema(SDateTime)
implicit val schemaForDate: Schema[Date] = Schema(SDateTime)
implicit val schemaForLocalDateTime: Schema[LocalDateTime] = Schema(SDateTime)
implicit val schemaForLocalDateTime: Schema[LocalDateTime] = Schema(SString)
implicit val schemaForLocalDate: Schema[LocalDate] = Schema(SDate)
implicit val schemaForZoneOffset: Schema[ZoneOffset] = Schema(SString)
implicit val schemaForJavaDuration: Schema[Duration] = Schema(SString)
Expand Down
17 changes: 17 additions & 0 deletions docs/openapi-docs/src/test/resources/expected_localDateTime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.3
info:
title: Examples
version: '1.0'
paths:
/:
get:
operationId: getRoot
parameters:
- name: localDateTime
in: query
required: true
schema:
type: string
responses:
'200':
description: ''
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sttp.tapir.docs.openapi

import java.time.Instant
import java.time.{Instant, LocalDateTime}
import io.circe.Json
import io.circe.generic.auto._
import sttp.model.{Method, StatusCode}
Expand Down Expand Up @@ -896,6 +896,18 @@ class VerifyYamlTest extends AnyFunSuite with Matchers {
actualYamlNoIndent shouldBe expectedYaml
}

test("should use string format for LocalDateTime fields") {

val expectedYaml = loadYaml("expected_localDateTime.yml")

val e = endpoint.in(query[LocalDateTime]("localDateTime"))

val actualYaml = OpenAPIDocsInterpreter.toOpenAPI(e, Info("Examples", "1.0")).toYaml
val actualYamlNoIndent = noIndentation(actualYaml)

actualYamlNoIndent shouldBe expectedYaml
}

test("exclusive bounds") {
val expectedYaml = loadYaml("expected_exclusive_bounds.yml")

Expand Down

0 comments on commit da00a0e

Please sign in to comment.