Skip to content

Commit d607fa5

Browse files
committed
update sttp-apispec to pr version and add/update tests
1 parent bec6472 commit d607fa5

File tree

5 files changed

+120
-2
lines changed

5 files changed

+120
-2
lines changed

docs/openapi-docs/src/test/resources/expected_nullable_option_class_field.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ components:
4141
type: object
4242
properties:
4343
optionalObjField:
44-
$ref: '#/components/schemas/Bar'
44+
oneOf:
45+
- $ref: '#/components/schemas/Bar'
46+
- type: 'null'
4547
requiredStringField:
4648
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
openapi: 3.0.3
2+
info:
3+
title: ClassWithOptionClassField
4+
version: '1.0'
5+
paths:
6+
/:
7+
post:
8+
operationId: postRoot
9+
requestBody:
10+
content:
11+
application/json:
12+
schema:
13+
$ref: '#/components/schemas/ClassWithOptionClassField'
14+
required: true
15+
responses:
16+
'200':
17+
description: ''
18+
content:
19+
text/plain:
20+
schema:
21+
type: string
22+
'400':
23+
description: 'Invalid value for: body'
24+
content:
25+
text/plain:
26+
schema:
27+
type: string
28+
components:
29+
schemas:
30+
Bar:
31+
required:
32+
- bar
33+
type: object
34+
properties:
35+
bar:
36+
type: integer
37+
format: int32
38+
ClassWithOptionClassField:
39+
required:
40+
- requiredStringField
41+
type: object
42+
properties:
43+
optionalObjField:
44+
allOf:
45+
- $ref: '#/components/schemas/Bar'
46+
nullable: true
47+
requiredStringField:
48+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
openapi: 3.0.3
2+
info:
3+
title: ClassWithOptionField
4+
version: '1.0'
5+
paths:
6+
/:
7+
get:
8+
operationId: getRoot
9+
requestBody:
10+
content:
11+
application/json:
12+
schema:
13+
$ref: '#/components/schemas/ClassWithOptionField'
14+
required: true
15+
responses:
16+
'200':
17+
description: ''
18+
content:
19+
text/plain:
20+
schema:
21+
type: string
22+
'400':
23+
description: 'Invalid value for: body'
24+
content:
25+
text/plain:
26+
schema:
27+
type: string
28+
components:
29+
schemas:
30+
ClassWithOptionField:
31+
required:
32+
- requiredStringField
33+
type: object
34+
properties:
35+
optionalIntField:
36+
type: integer
37+
format: int32
38+
nullable: true
39+
requiredStringField:
40+
type: string

docs/openapi-docs/src/test/scalajvm/sttp/tapir/docs/openapi/VerifyYamlTest.scala

+28
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,19 @@ class VerifyYamlTest extends AnyFunSuite with Matchers {
676676
actualYamlNoIndent shouldBe expectedYaml
677677
}
678678

679+
test("should mark optional fields as nullable when configured to do so using OpenAPI 3.0") {
680+
case class ClassWithOptionField(optionalIntField: Option[Int], requiredStringField: String)
681+
682+
val e = endpoint.in(jsonBody[ClassWithOptionField]).out(stringBody)
683+
val expectedYaml = load("expected_nullable_option_field_303.yml")
684+
685+
val options = OpenAPIDocsOptions.default.copy(markOptionsAsNullable = true)
686+
687+
val actualYaml = OpenAPIDocsInterpreter(options).toOpenAPI(e, Info("ClassWithOptionField", "1.0")).copy(openapi = "3.0.3").toYaml3_0_3
688+
val actualYamlNoIndent = noIndentation(actualYaml)
689+
actualYamlNoIndent shouldBe expectedYaml
690+
}
691+
679692
test("should mark optional class fields as nullable when configured to do so") {
680693
case class Bar(bar: Int)
681694
case class ClassWithOptionClassField(optionalObjField: Option[Bar], requiredStringField: String)
@@ -690,6 +703,21 @@ class VerifyYamlTest extends AnyFunSuite with Matchers {
690703
actualYamlNoIndent shouldBe expectedYaml
691704
}
692705

706+
test("should mark optional class fields as nullable when configured to do so using OpenAPI 3.0") {
707+
case class Bar(bar: Int)
708+
case class ClassWithOptionClassField(optionalObjField: Option[Bar], requiredStringField: String)
709+
710+
val e = endpoint.in(jsonBody[ClassWithOptionClassField]).out(stringBody).post
711+
val expectedYaml = load("expected_nullable_option_class_field_303.yml")
712+
713+
val options = OpenAPIDocsOptions.default.copy(markOptionsAsNullable = true)
714+
715+
val actualYaml =
716+
OpenAPIDocsInterpreter(options).toOpenAPI(e, Info("ClassWithOptionClassField", "1.0")).copy(openapi = "3.0.3").toYaml3_0_3
717+
val actualYamlNoIndent = noIndentation(actualYaml)
718+
actualYamlNoIndent shouldBe expectedYaml
719+
}
720+
693721
test("should generate default and example values for nested optional fields") {
694722
case class Nested(nestedValue: String)
695723
case class ClassWithNestedOptionalField(

project/Versions.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Versions {
1111
val sttp = "3.9.1"
1212
val sttpModel = "1.7.6"
1313
val sttpShared = "1.3.16"
14-
val sttpApispec = "0.7.1"
14+
val sttpApispec = "0.7.1+16-f56e2f94-SNAPSHOT"
1515
val akkaHttp = "10.2.10"
1616
val akkaStreams = "2.6.20"
1717
val pekkoHttp = "1.0.0"

0 commit comments

Comments
 (0)