Skip to content

Commit a503697

Browse files
committed
v32: new properties
1 parent efa3dc5 commit a503697

7 files changed

Lines changed: 141 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public interface Keywords {
5353
String ITEM_ENCODING = "itemEncoding";
5454
String ITEMS = "items";
5555
String JSON_SCHEMA_DIALECT = "jsonSchemaDialect";
56+
String KIND = "kind";
5657
String LICENSE = "license";
5758
String LINKS = "links";
5859
String MAPPING = "mapping";
@@ -76,6 +77,7 @@ public interface Keywords {
7677
String OPERATION_ID = "operationId";
7778
String OPTIONS = "options";
7879
String PARAMETERS = "parameters";
80+
String PARENT = "parent";
7981
String PATCH = "patch";
8082
String PATHS = "paths";
8183
String PATH_ITEMS = "pathItems";

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
package io.openapiparser.model.v31;
77

88
import io.openapiparser.*;
9+
import io.openapiparser.support.Required;
910
import io.openapiprocessor.jsonschema.schema.Bucket;
1011
import org.checkerframework.checker.nullness.qual.Nullable;
1112

1213
import java.util.Map;
1314

15+
import static io.openapiparser.Keywords.*;
16+
1417
/**
1518
* the <em>Tag</em> object.
1619
*
@@ -23,6 +26,19 @@ public Tag (Context context, Bucket bucket) {
2326
super (context, bucket);
2427
}
2528

29+
@Required
30+
public String getName() {
31+
return getStringOrThrow(NAME);
32+
}
33+
34+
public @Nullable String getDescription () {
35+
return getStringOrNull (DESCRIPTION);
36+
}
37+
38+
public @Nullable ExternalDocumentation getExternalDocs () {
39+
return getObjectOrNull (EXTERNAL_DOCS, ExternalDocumentation.class);
40+
}
41+
2642
@Override
2743
public Map<String, @Nullable Object> getExtensions () {
2844
return super.getExtensions ();

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77

88
import io.openapiparser.Context;
99
import io.openapiparser.Properties;
10+
import io.openapiparser.model.v31.ExternalDocumentation;
11+
import io.openapiparser.support.Required;
1012
import io.openapiprocessor.jsonschema.schema.Bucket;
1113
import org.checkerframework.checker.nullness.qual.Nullable;
1214

1315
import java.util.Map;
1416

17+
import static io.openapiparser.Keywords.*;
18+
1519
/**
1620
* the <em>Tag</em> object.
1721
*
@@ -24,6 +28,31 @@ public Tag (Context context, Bucket bucket) {
2428
super (context, bucket);
2529
}
2630

31+
@Required
32+
public String getName() {
33+
return getStringOrThrow(NAME);
34+
}
35+
36+
public @Nullable String getSummary () {
37+
return getStringOrNull (SUMMARY);
38+
}
39+
40+
public @Nullable String getDescription () {
41+
return getStringOrNull (DESCRIPTION);
42+
}
43+
44+
public @Nullable ExternalDocumentation getExternalDocs () {
45+
return getObjectOrNull (EXTERNAL_DOCS, ExternalDocumentation.class);
46+
}
47+
48+
public @Nullable String getParent () {
49+
return getStringOrNull (PARENT);
50+
}
51+
52+
public @Nullable String getKind () {
53+
return getStringOrNull (KIND);
54+
}
55+
2756
@Override
2857
public Map<String, @Nullable Object> getExtensions () {
2958
return super.getExtensions ();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ fun serverVariable(content: String = "{}"): ServerVariable {
9595
return buildObject(ServerVariable::class.java, content)
9696
}
9797

98+
fun tag(content: String = "{}"): Tag {
99+
return buildObject(Tag::class.java, content)
100+
}
101+
98102
fun xml(content: String = "{}"): Xml {
99103
return buildObject(Xml::class.java, content)
100104
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.v31
7+
8+
import io.kotest.assertions.throwables.shouldThrow
9+
import io.kotest.core.spec.style.StringSpec
10+
import io.kotest.matchers.nulls.shouldBeNull
11+
import io.kotest.matchers.nulls.shouldNotBeNull
12+
import io.kotest.matchers.shouldBe
13+
import io.openapiprocessor.jsonschema.converter.NoValueException
14+
import io.openapiparser.model.v31.tag as tag31
15+
import io.openapiparser.model.v32.tag as tag32
16+
17+
class TagSpec: StringSpec({
18+
19+
"gets tag name" {
20+
tag31("name: the name").name shouldBe "the name"
21+
tag32("name: the name").name shouldBe "the name"
22+
}
23+
24+
"gets tag name is null if missing" {
25+
shouldThrow<NoValueException> { tag31().name }
26+
shouldThrow<NoValueException> { tag32().name }
27+
}
28+
29+
"gets tag description" {
30+
tag31("description: a description").description shouldBe "a description"
31+
tag32("description: a description").description shouldBe "a description"
32+
}
33+
34+
"gets tag description is null if missing" {
35+
tag31().description.shouldBeNull()
36+
tag32().description.shouldBeNull()
37+
}
38+
39+
"gets external docs object" {
40+
tag31("externalDocs: {}").externalDocs.shouldNotBeNull()
41+
tag32("externalDocs: {}").externalDocs.shouldNotBeNull()
42+
}
43+
44+
"gets external docs object is null if it missing" {
45+
tag31().externalDocs.shouldBeNull()
46+
tag32().externalDocs.shouldBeNull()
47+
}
48+
})

‎openapi-parser/src/test/kotlin/io/openapiparser/model/v32/Builder.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ fun serverVariable(content: String = "{}"): ServerVariable {
9595
return buildObject(ServerVariable::class.java, content)
9696
}
9797

98+
fun tag(content: String = "{}"): Tag {
99+
return buildObject(Tag::class.java, content)
100+
}
101+
98102
fun xml(content: String = "{}"): Xml {
99103
return buildObject(Xml::class.java, content)
100104
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.nulls.shouldBeNull
10+
import io.kotest.matchers.shouldBe
11+
import io.openapiparser.model.v32.tag as tag32
12+
13+
class TagSpec: StringSpec({
14+
15+
"gets tag summary" {
16+
tag32("summary: a summary").summary shouldBe "a summary"
17+
}
18+
19+
"gets tag summary is null if missing" {
20+
tag32().summary.shouldBeNull()
21+
}
22+
23+
"gets tag parent" {
24+
tag32("parent: the parent").parent shouldBe "the parent"
25+
}
26+
27+
"gets tag name is null if missing" {
28+
tag32().parent.shouldBeNull()
29+
}
30+
31+
"gets tag kind" {
32+
tag32("kind: the kind").kind shouldBe "the kind"
33+
}
34+
35+
"gets tag kind is null if missing" {
36+
tag32().kind.shouldBeNull()
37+
}
38+
})

0 commit comments

Comments
 (0)