Skip to content

Commit ebcb5a8

Browse files
committed
add tests for additionalProperties false/true (#370)
1 parent 9930e68 commit ebcb5a8

14 files changed

Lines changed: 149 additions & 14 deletions

File tree

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/parser/openapi/v30/Schema.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ class Schema(val schema: Schema30) : OpenApiSchema {
7676
override fun getAdditionalProperties(): Schema? {
7777
val additional = schema.additionalProperties
7878

79-
// null, boolean, schema
79+
// schema
8080
if(additional is Schema30) {
8181
return Schema(additional)
8282
}
8383

84-
return null;
84+
// null, boolean
85+
return null
8586
}
8687

8788
override fun getItems(): List<OpenApiSchema> {

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/parser/openapi/v31/Schema.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ class Schema(val schema: Schema31) : OpenApiSchema {
7373
return props
7474
}
7575

76-
override fun getAdditionalProperties(): Schema? {
76+
override fun getAdditionalProperties(): OpenApiSchema? {
7777
val additional = schema.additionalProperties
7878

79-
// null, boolean, schema
79+
// schema
8080
if(additional is Schema31) {
8181
return Schema(additional)
8282
}
8383

84-
return null;
84+
// null, boolean
85+
return null
8586
}
8687

8788
override fun getItems(): List<OpenApiSchema> {

openapi-processor-core/src/main/kotlin/io/openapiprocessor/core/parser/openapi/v32/Schema.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ class Schema(val schema: Schema32) : OpenApiSchema {
7373
return props
7474
}
7575

76-
override fun getAdditionalProperties(): Schema? {
76+
override fun getAdditionalProperties(): OpenApiSchema? {
7777
val additional = schema.additionalProperties
7878

79-
// null, boolean, schema
79+
// schema
8080
if(additional is Schema32) {
8181
return Schema(additional)
8282
}
8383

84-
return null;
84+
// null, boolean
85+
return null
8586
}
8687

8788
override fun getItems(): List<OpenApiSchema> {

openapi-processor-core/src/test/kotlin/io/openapiprocessor/core/parser/swagger/AdditionalPropertiesSpec.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class AdditionalPropertiesSpec: StringSpec({
4040
additional.shouldNotBeNull()
4141
}
4242

43-
"additionalProperties of boolean object is null (OpenAPI 3.0)" {
43+
// creates empty object
44+
"additionalProperties of boolean object is null (OpenAPI 3.0)" {
4445
val openApi = parseApi( """
4546
openapi: 3.0.2
4647
info:

openapi-processor-core/src/testInt/kotlin/io/openapiprocessor/core/ProcessorPendingSpec.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ class ProcessorPendingSpec: StringSpec({
4848

4949
private fun sources(): Collection<TestSet> {
5050
return listOf(
51-
testSet("params-request-body-form-urlencoded", "INTERNAL", API_30, model = "model"),
52-
// testSet("endpoint-http-mapping-32", "INTERNAL", API_32, model = "record"),
51+
testSet("object-without-properties", "INTERNAL", API_30, model = "model"),
52+
testSet("object-without-properties", "INTERNAL", API_31, model = "model"),
53+
testSet("object-without-properties", "INTERNAL", API_32, model = "model"),
54+
testSet("object-without-properties", "INTERNAL", API_30, model = "record"),
55+
testSet("object-without-properties", "INTERNAL", API_31, model = "record"),
56+
testSet("object-without-properties", "INTERNAL", API_32, model = "record"),
5357
)
5458
}

openapi-processor-core/src/testInt/resources/tests/object-without-properties/inputs/openapi30.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,43 @@ paths:
99
get:
1010
responses:
1111
'200':
12-
description: the foo result
12+
description: the foo object result
1313
content:
1414
application/json:
1515
schema:
1616
$ref: '#/components/schemas/Foo'
1717

18+
/foo-true:
19+
get:
20+
responses:
21+
'200':
22+
description: the foo true result
23+
content:
24+
application/json:
25+
schema:
26+
$ref: '#/components/schemas/FooTrue'
27+
28+
/foo-false:
29+
get:
30+
responses:
31+
'200':
32+
description: the foo false result
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/FooFalse'
37+
1838
components:
1939
schemas:
2040

2141
Foo:
2242
type: object
2343
additionalProperties: {}
44+
45+
FooTrue:
46+
type: object
47+
additionalProperties: true
48+
49+
FooFalse:
50+
type: object
51+
additionalProperties: false

openapi-processor-core/src/testInt/resources/tests/object-without-properties/inputs/openapi31.yaml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,43 @@ paths:
99
get:
1010
responses:
1111
'200':
12-
description: the foo result
12+
description: the foo object result
1313
content:
1414
application/json:
1515
schema:
1616
$ref: '#/components/schemas/Foo'
1717

18+
/foo-true:
19+
get:
20+
responses:
21+
'200':
22+
description: the foo true result
23+
content:
24+
application/json:
25+
schema:
26+
$ref: '#/components/schemas/FooTrue'
27+
28+
/foo-false:
29+
get:
30+
responses:
31+
'200':
32+
description: the foo false result
33+
content:
34+
application/json:
35+
schema:
36+
$ref: '#/components/schemas/FooFalse'
37+
1838
components:
1939
schemas:
2040

2141
Foo:
2242
type: object
2343
additionalProperties: {}
44+
45+
FooTrue:
46+
type: object
47+
additionalProperties: true
48+
49+
FooFalse:
50+
type: object
51+
additionalProperties: false

openapi-processor-core/src/testInt/resources/tests/object-without-properties/inputs/openapi32.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,42 @@ paths:
77
get:
88
responses:
99
"200":
10-
description: the foo result
10+
description: the foo object result
1111
content:
1212
application/json:
1313
schema:
1414
$ref: "#/components/schemas/Foo"
15+
16+
/foo-true:
17+
get:
18+
responses:
19+
'200':
20+
description: the foo true result
21+
content:
22+
application/json:
23+
schema:
24+
$ref: '#/components/schemas/FooTrue'
25+
26+
/foo-false:
27+
get:
28+
responses:
29+
'200':
30+
description: the foo false result
31+
content:
32+
application/json:
33+
schema:
34+
$ref: '#/components/schemas/FooFalse'
35+
1536
components:
1637
schemas:
1738
Foo:
1839
type: object
1940
additionalProperties: {}
41+
42+
FooTrue:
43+
type: object
44+
additionalProperties: true
45+
46+
FooFalse:
47+
type: object
48+
additionalProperties: false

openapi-processor-core/src/testInt/resources/tests/object-without-properties/outputs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ prefix: generated
22
items:
33
- outputs/api/Api.java
44
- outputs/model/<model>/Foo.java
5+
- outputs/model/<model>/FooFalse.java
6+
- outputs/model/<model>/FooTrue.java

openapi-processor-core/src/testInt/resources/tests/object-without-properties/outputs/api/Api.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import annotation.Mapping;
44
import generated.model.Foo;
5+
import generated.model.FooFalse;
6+
import generated.model.FooTrue;
57
import generated.support.Generated;
68

79
@Generated(value = "openapi-processor-core", version = "test")
@@ -10,4 +12,10 @@ public interface Api {
1012
@Mapping("/foo")
1113
Foo getFoo();
1214

15+
@Mapping("/foo-true")
16+
FooTrue getFooTrue();
17+
18+
@Mapping("/foo-false")
19+
FooFalse getFooFalse();
20+
1321
}

0 commit comments

Comments
 (0)