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

Commit 635ee9d

Browse files
committed
resolve parameter $ref
1 parent cd89f40 commit 635ee9d

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class OpenApi(
4343
path = refResolver.resolve(path)
4444
}
4545

46-
paths[name] = Path(name, path)
46+
paths[name] = Path(name, path, refResolver)
4747
}
4848

4949
return paths

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import org.openapi4j.parser.model.v3.Response as O4jResponse
3030
*
3131
* @author Martin Hauner
3232
*/
33-
class Operation(private val method: HttpMethod, private val operation: O4jOperation): ParserOperation {
33+
class Operation(
34+
private val method: HttpMethod,
35+
private val operation: O4jOperation,
36+
private val refResolver: RefResolverNative
37+
): ParserOperation {
3438

3539
override fun getMethod(): HttpMethod = method
3640

@@ -42,7 +46,12 @@ class Operation(private val method: HttpMethod, private val operation: O4jOperat
4246
val parameters = mutableListOf<ParserParameter>()
4347

4448
operation.parameters?.map { p: O4jParameter ->
45-
parameters.add(Parameter(p))
49+
var param = p
50+
if(p.isRef) {
51+
param = refResolver.resolve(p)
52+
}
53+
54+
parameters.add(Parameter(param))
4655
}
4756

4857
return parameters

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import org.openapi4j.parser.model.v3.Path as Oa4jPath
2626
*
2727
* @author Martin Hauner
2828
*/
29-
class Path(private val path: String, private val info: Oa4jPath): ParserPath {
29+
class Path(
30+
private val path: String,
31+
private val info: Oa4jPath,
32+
private val refResolver: RefResolverNative
33+
): ParserPath {
3034

3135
override fun getPath(): String = path
3236

@@ -36,7 +40,7 @@ class Path(private val path: String, private val info: Oa4jPath): ParserPath {
3640
HttpMethod.values().map {
3741
val op = info.getOperation(it.method)
3842
if (op != null) {
39-
ops.add (Operation(it, op))
43+
ops.add (Operation(it, op, refResolver))
4044
}
4145
}
4246

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ package io.openapiprocessor.core.parser.openapi4j
77

88
import org.openapi4j.parser.model.v3.OpenApi3
99
import org.openapi4j.parser.model.v3.Path as O4jPath
10+
import org.openapi4j.parser.model.v3.Parameter as O4jParameter
1011

1112
/**
12-
* openapi4j $ref resolver on o4j types.
13+
* openapi4j $ref resolver on o4j types. Resolves non-schema $ref's.
1314
*/
1415
class RefResolverNative(private val api: OpenApi3) {
1516

1617
fun resolve(path: O4jPath): O4jPath {
1718
return path.getReference(api.context).getMappedContent(O4jPath::class.java)
1819
}
1920

21+
fun resolve(param: O4jParameter): O4jParameter {
22+
return param.getReference(api.context).getMappedContent(O4jParameter::class.java)
23+
}
24+
2025
}

src/testInt/groovy/com/github/hauner/openapi/processor/core/ProcessorEndToEndTest.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class ProcessorEndToEndTest extends ProcessorTestBase {
3232

3333
static def testSets = TestSet.ALL + [
3434
'deprecated',
35-
'ref-into-another-file-path'
35+
'ref-into-another-file-path',
36+
'ref-parameter'
3637
]
3738

3839
@Parameterized.Parameters(name = "{0}")

src/testInt/groovy/com/github/hauner/openapi/processor/core/ProcessorPendingTest.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ import com.github.hauner.openapi.test.TestSet
2323
import org.junit.Test
2424
import org.junit.runner.RunWith
2525
import org.junit.runners.Parameterized
26+
import spock.lang.Ignore
2627

27-
//@Ignore
28+
@Ignore
2829
@RunWith(Parameterized)
2930
class ProcessorPendingTest extends ProcessorTestBase {
3031

3132
@Parameterized.Parameters(name = "{0}")
3233
static Collection<TestSet> sources () {
3334
return [
34-
new TestSet(name: 'ref-array-items-nested', processor: new TestProcessor(), parser: ParserType.OPENAPI4J),
35-
new TestSet(name: 'ref-array-items-nested', processor: new TestProcessor(), parser: ParserType.SWAGGER)
35+
new TestSet(name: 'ref-parameter', processor: new TestProcessor(), parser: ParserType.OPENAPI4J),
36+
new TestSet(name: 'ref-parameter', processor: new TestProcessor(), parser: ParserType.SWAGGER)
3637
]
3738
}
3839

0 commit comments

Comments
 (0)