Skip to content

Commit 4606502

Browse files
committed
fix OpenAPI 3.1 exclusiveMinimum/exclusiveMaximum result type (#114)
1 parent 4df4079 commit 4606502

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

openapi-parser/src/main/java/io/openapiparser/model/v31/Schema.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ public Collection<String> getType () {
234234
/**
235235
* JSON Schema Validation: validation Keywords for numeric instances (number and integer)
236236
*
237-
* @return exclusive maximum or false if missing
237+
* @return exclusive maximum or null if missing
238238
*/
239-
public Boolean getExclusiveMaximum () {
240-
return getBooleanOrDefault (EXCLUSIVE_MAXIMUM, false);
239+
public @Nullable Number getExclusiveMaximum () {
240+
return getNumberOrNull (EXCLUSIVE_MAXIMUM);
241241
}
242242

243243
/**
@@ -252,10 +252,10 @@ public Boolean getExclusiveMaximum () {
252252
/**
253253
* JSON Schema Validation: validation Keywords for numeric instances (number and integer)
254254
*
255-
* @return exclusive minimum or false if missing
255+
* @return exclusive minimum or null if missing
256256
*/
257-
public Boolean getExclusiveMinimum () {
258-
return getBooleanOrDefault (EXCLUSIVE_MINIMUM, false);
257+
public Number getExclusiveMinimum () {
258+
return getNumberOrNull (EXCLUSIVE_MINIMUM);
259259
}
260260

261261
/**

openapi-parser/src/test/kotlin/io/openapiparser/model/v30/SchemaSpec.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ class SchemaSpec: StringSpec({
3737
schema().nullable.shouldBeFalse()
3838
}
3939

40+
"gets schema exclusiveMaximum is false if missing" {
41+
schema().exclusiveMaximum.shouldBeFalse()
42+
}
43+
44+
"gets schema exclusiveMinimum is false if missing" {
45+
schema().exclusiveMinimum.shouldBeFalse()
46+
}
47+
4048
"gets schema additionalProperties" {
4149
schema("additionalProperties: false").additionalProperties.shouldBeInstanceOf<Boolean>()
4250
schema("additionalProperties: {}").additionalProperties.shouldBeInstanceOf<Schema>()

openapi-parser/src/test/kotlin/io/openapiparser/model/v31/SchemaSpec.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ class SchemaSpec: StringSpec({
7070
schema().minContains shouldBe 1
7171
}
7272

73+
"gets schema exclusiveMaximum is null if missing" {
74+
schema().exclusiveMaximum.shouldBeNull()
75+
}
76+
77+
"gets schema exclusiveMinimum is null if missing" {
78+
schema().exclusiveMinimum.shouldBeNull()
79+
}
80+
7381
"gets schema dependentRequired" {
7482
val required = schema("dependentRequired: {bar: [foo]}").dependentRequired
7583
required shouldContainKey "bar"

openapi-parser/src/test/kotlin/io/openapiparser/model/v3x/SchemaSpec.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ class SchemaSpec: StringSpec({
4242

4343
"gets schema exclusiveMaximum" {
4444
schema30("exclusiveMaximum: true").exclusiveMaximum.shouldBeTrue()
45-
schema31("exclusiveMaximum: true").exclusiveMaximum.shouldBeTrue()
46-
}
47-
48-
"gets schema exclusiveMaximum is false if missing" {
49-
schema30().exclusiveMaximum.shouldBeFalse()
50-
schema31().exclusiveMaximum.shouldBeFalse()
45+
schema31("exclusiveMaximum: 9.9").exclusiveMaximum shouldBe 9.9
5146
}
5247

5348
"gets schema minimum" {
@@ -62,12 +57,7 @@ class SchemaSpec: StringSpec({
6257

6358
"gets schema exclusiveMinimum" {
6459
schema30("exclusiveMinimum: true").exclusiveMinimum.shouldBeTrue()
65-
schema31("exclusiveMinimum: true").exclusiveMinimum.shouldBeTrue()
66-
}
67-
68-
"gets schema exclusiveMinimum is false if missing" {
69-
schema30().exclusiveMinimum.shouldBeFalse()
70-
schema31().exclusiveMinimum.shouldBeFalse()
60+
schema31("exclusiveMinimum: 9.9").exclusiveMinimum shouldBe 9.9
7161
}
7262

7363
"gets schema maxLength" {

0 commit comments

Comments
 (0)