Skip to content

Commit 1dc3365

Browse files
committed
update/validate json schema of mapping.yaml
1 parent bdb082d commit 1dc3365

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

openapi-processor-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ dependencies {
142142
testImplementation("io.mockk:mockk:1.10.4")
143143
testImplementation("io.kotest:kotest-runner-junit5:4.3.2")
144144
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
145+
testImplementation "com.networknt:json-schema-validator:1.0.49"
145146
}
146147

147148
tasks.withType(Test) {

openapi-processor-core/src/main/resources/mapping/v2/mapping.example.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ options: # general processor options (optional)
1313
# validation annotation (optional): true or false (default)
1414
bean-validation: false
1515

16+
javadoc: true
17+
1618
map: # the type mappings
1719

1820
# global mappings, apply to all paths/endpoints
@@ -72,3 +74,7 @@ map: # the type mappings
7274
responses:
7375
- content: application/vnd.any => java.util.Set
7476
- content: application/json => java.util.Map
77+
78+
/third:
79+
patch:
80+
null: org.openapitools.jackson.nullable.JsonNullable = JsonNullable.undefined()

openapi-processor-core/src/main/resources/mapping/v2/mapping.yaml.json

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"Options": {
2727
"description": "general processor configuration options.",
2828
"type": "object",
29+
"additionalProperties": false,
2930
"properties": {
3031
"package-name": {
3132
"description": "java root package name to use in the generated source files.",
@@ -36,6 +37,11 @@
3637
"description": "enable bean validation annotations for OpenAPI constraints.",
3738
"type": "boolean",
3839
"default": false
40+
},
41+
"javadoc": {
42+
"description": "generate javadoc from OpenAPI 'description' properties (since core 2021.1).",
43+
"type": "boolean",
44+
"default": false
3945
}
4046
}
4147
},
@@ -63,8 +69,9 @@
6369
"$ref": "#/definitions/Exclude"
6470
}, {
6571
"$ref": "#/definitions/Mappings"
66-
}
67-
]
72+
}, {
73+
"$ref": "#/definitions/Methods"
74+
}]
6875
}
6976
}
7077
},
@@ -81,6 +88,9 @@
8188
"multi": {
8289
"$ref": "#/definitions/MultiMapping"
8390
},
91+
"null": {
92+
"$ref": "#/definitions/NullMapping"
93+
},
8494
"types": {
8595
"$ref": "#/definitions/TypeMappings"
8696
},
@@ -92,6 +102,31 @@
92102
}
93103
}
94104
},
105+
"Methods": {
106+
"description": "http method mapping rules (since core 2021.2).",
107+
"type": "object",
108+
"get": {
109+
"$ref": "#/definitions/Mappings"
110+
},
111+
"put": {
112+
"$ref": "#/definitions/Mappings"
113+
},
114+
"post": {
115+
"$ref": "#/definitions/Mappings"
116+
},
117+
"delete": {
118+
"$ref": "#/definitions/Mappings"
119+
},
120+
"options": {
121+
"$ref": "#/definitions/Mappings"
122+
},
123+
"head": {
124+
"$ref": "#/definitions/Mappings"
125+
},
126+
"patch": {
127+
"$ref": "#/definitions/Mappings"
128+
}
129+
},
95130
"ResultMapping": {
96131
"description": "wrapper object of a http response.",
97132
"type": "string",
@@ -113,6 +148,14 @@
113148
"reactor.core.publisher.Flux"
114149
]
115150
},
151+
"NullMapping": {
152+
"description": "null wrapper of 'nullable' object properties (since core 2021.2).",
153+
"type": "string",
154+
"examples": [
155+
"org.openapitools.jackson.nullable.JsonNullable",
156+
"org.openapitools.jackson.nullable.JsonNullable = JsonNullable.undefined()"
157+
]
158+
},
116159
"TypeMappings": {
117160
"description": "basic type mappings.",
118161
"type": "array",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.openapiprocessor.core.processor.mapping.v2
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper
4+
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
5+
import com.networknt.schema.JsonSchemaFactory
6+
import com.networknt.schema.SpecVersion
7+
import io.kotest.core.spec.style.StringSpec
8+
import java.io.InputStream
9+
import io.kotest.matchers.collections.shouldBeEmpty
10+
11+
12+
class ValidateSpec: StringSpec({
13+
14+
fun getResource(path: String): InputStream {
15+
return this.javaClass.getResourceAsStream(path)
16+
}
17+
18+
"validate" {
19+
val yaml = ObjectMapper(YAMLFactory ())
20+
val yamlData = getResource("/mapping/v2/mapping.example.yaml")
21+
val node = yaml.readTree(yamlData)
22+
23+
val factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)
24+
val schemaData = getResource("/mapping/v2/mapping.yaml.json")
25+
val schema = factory.getSchema(schemaData)
26+
27+
val errors = schema.validate(node)
28+
29+
errors.shouldBeEmpty()
30+
}
31+
32+
})

0 commit comments

Comments
 (0)