Skip to content

Commit 333d94f

Browse files
committed
v32: new property
1 parent dfacebf commit 333d94f

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

openapi-parser/src/main/java/io/openapiparser/Keywords.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public interface Keywords {
5656
String MAX_LENGTH = "maxLength";
5757
String MAX_PROPERTIES = "maxProperties";
5858
String MAXIMUM = "maximum";
59+
String MEDIA_TYPES = "mediaTypes";
5960
String MIN_CONTAINS = "minContains";
6061
String MIN_ITEMS = "minItems";
6162
String MIN_LENGTH = "minLength";

openapi-parser/src/main/java/io/openapiparser/model/v32/Components.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public Map<String, PathItem> getPathItems () {
6666
return getMapObjectsOrEmpty (PATH_ITEMS, PathItem.class);
6767
}
6868

69+
public Map<String, MediaType> getMediaTypes () {
70+
return getMapObjectsOrEmpty (MEDIA_TYPES, MediaType.class);
71+
}
72+
6973
@Override
7074
public Map<String, @Nullable Object> getExtensions () {
7175
return super.getExtensions ();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 https://github.com/openapi-processor/openapi-parser
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiparser.model.v32
7+
8+
import io.kotest.core.spec.style.StringSpec
9+
import io.kotest.matchers.maps.shouldBeEmpty
10+
import io.kotest.matchers.nulls.shouldNotBeNull
11+
import io.kotest.matchers.shouldBe
12+
13+
/**
14+
* @see [io.openapiparser.model.v3x.ComponentsSpec]
15+
*/
16+
class ComponentsSpec: StringSpec ({
17+
18+
fun assertMap (items: Map<String, MediaType>) {
19+
items.size shouldBe 2
20+
items["foo"].shouldNotBeNull()
21+
items["bar"].shouldNotBeNull()
22+
}
23+
24+
"gets components mediaTypes" {
25+
val source = """
26+
mediaTypes:
27+
foo: {}
28+
bar: {}
29+
"""
30+
31+
assertMap(components(source).mediaTypes)
32+
}
33+
34+
"gets components mediaTypes is empty if missing" {
35+
components().mediaTypes.shouldBeEmpty()
36+
}
37+
})

0 commit comments

Comments
 (0)