Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit cd89f40

Browse files
committed
extract ref resolver
1 parent a44e837 commit cd89f40

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/main/kotlin/io/openapiprocessor/core/parser/openapi4j/OpenApi.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ import org.openapi4j.parser.model.v3.Path as O4jPath
2828
*
2929
* @author Martin Hauner
3030
*/
31-
class OpenApi(private val api: O4jOpenApi, private val validations: ValidationResults): ParserOpenApi {
31+
class OpenApi(
32+
private val api: O4jOpenApi,
33+
private val validations: ValidationResults,
34+
): ParserOpenApi {
35+
private val refResolver: RefResolverNative = RefResolverNative(api)
3236

3337
override fun getPaths(): Map<String, ParserPath> {
3438
val paths = linkedMapOf<String, ParserPath>()
3539

3640
api.paths.forEach { (name: String, value: O4jPath) ->
3741
var path = value
38-
if (isRef(value)) {
39-
path = resolve (path)
42+
if (path.isRef) {
43+
path = refResolver.resolve(path)
4044
}
4145

4246
paths[name] = Path(name, path)
@@ -50,12 +54,4 @@ class OpenApi(private val api: O4jOpenApi, private val validations: ValidationRe
5054
override fun printWarnings() {
5155
}
5256

53-
private fun resolve(path: O4jPath): O4jPath {
54-
return path.getReference (api.context).getMappedContent (O4jPath::class.java)
55-
}
56-
57-
private fun isRef(path: O4jPath): Boolean {
58-
return path.ref != null
59-
}
60-
6157
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright © 2020 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.parser.openapi4j
7+
8+
import org.openapi4j.parser.model.v3.OpenApi3
9+
import org.openapi4j.parser.model.v3.Path as O4jPath
10+
11+
/**
12+
* openapi4j $ref resolver on o4j types.
13+
*/
14+
class RefResolverNative(private val api: OpenApi3) {
15+
16+
fun resolve(path: O4jPath): O4jPath {
17+
return path.getReference(api.context).getMappedContent(O4jPath::class.java)
18+
}
19+
20+
}

0 commit comments

Comments
 (0)