Skip to content

Commit

Permalink
Merge pull request #389 from franklauterwald/master
Browse files Browse the repository at this point in the history
#386: Unset format for array types
  • Loading branch information
adamw committed Jan 23, 2020
2 parents 6e8ca65 + 988fddd commit 8e9f95b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/scala/sttp/tapir/Schema.scala
Expand Up @@ -34,8 +34,9 @@ case class Schema[T](
/**
* Returns a collection version of this schema, with the schema type wrapped in [[SArray]].
* Also, sets `isOptional` to true as the collection might be empty.
* Also, sets 'format' to None. Formats are only applicable to the array elements, not to the array as a whole.
*/
def asArrayElement[U]: Schema[U] = copy(isOptional = true, schemaType = SArray(this))
def asArrayElement[U]: Schema[U] = copy(isOptional = true, schemaType = SArray(this), format=None)

def description(d: String): Schema[T] = copy(description = Some(d))

Expand Down
27 changes: 27 additions & 0 deletions docs/openapi-docs/src/test/resources/expected_array_no_format.yml
@@ -0,0 +1,27 @@
openapi: 3.0.1
info:
title: Entities
version: '1.0'
paths:
/:
get:
operationId: getRoot
parameters:
- name: foo
in: query
required: false
schema:
type: array
items:
type: string
- name: bar
in: query
required: false
schema:
type: array
items:
type: integer
format: int64
responses:
'200':
description: ''
Expand Up @@ -645,6 +645,18 @@ class VerifyYamlTest extends FunSuite with Matchers {
actualYamlNoIndent shouldBe expectedYaml
}

test("should not set format for array types ") {
val expectedYaml = loadYaml("expected_array_no_format.yml")
val actualYaml = endpoint
.in(query[List[String]]("foo"))
.in(query[List[Long]]("bar"))
.toOpenAPI(Info("Entities", "1.0"))
.toYaml

val actualYamlNoIndent = noIndentation(actualYaml)
actualYamlNoIndent shouldBe expectedYaml
}

private def loadYaml(fileName: String): String = {
noIndentation(Source.fromInputStream(getClass.getResourceAsStream(s"/$fileName")).getLines().mkString("\n"))
}
Expand Down

0 comments on commit 8e9f95b

Please sign in to comment.