File tree 4 files changed +83
-1
lines changed
openapi-processor-core-parser-openapi4j
main/kotlin/io/openapiprocessor/core/parser/openapi4j
test/kotlin/io/openapiprocessor/core/parser/openapi4j 4 files changed +83
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ repositories {
11
11
dependencies {
12
12
implementation (project(" :openapi-processor-core-parser-api" ))
13
13
implementation (libs.openapi4j)
14
+ implementation (libs.uritemplate)
14
15
implementation (libs.slf4j)
15
16
16
17
testImplementation (project(" :openapi-processor-test" ))
Original file line number Diff line number Diff line change @@ -27,7 +27,13 @@ class OpenApi(
27
27
private val refResolver: RefResolverNative = RefResolverNative (api)
28
28
29
29
override fun getServers (): List <Server > {
30
- return listOf ()
30
+ val servers = mutableListOf<Server >()
31
+
32
+ api.servers.forEach { server ->
33
+ servers.add(Server (server))
34
+ }
35
+
36
+ return servers
31
37
}
32
38
33
39
override fun getPaths (): Map <String , ParserPath > {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2024 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 io.github.stduritemplate.StdUriTemplate
9
+ import java.net.URI
10
+ import io.openapiprocessor.core.parser.Server as ParserServer
11
+ import org.openapi4j.parser.model.v3.Server as O4jServer
12
+
13
+ class Server (private val server : O4jServer ): ParserServer {
14
+
15
+ override fun getUri (): URI {
16
+ val variables = mutableMapOf<String , Any >()
17
+
18
+ server.variables.forEach { variable ->
19
+ variables[variable.key] = variable.value.default
20
+ }
21
+
22
+ return URI .create(StdUriTemplate .expand(server.url, variables))
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2024 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 io.kotest.core.spec.style.StringSpec
9
+ import io.kotest.matchers.collections.shouldHaveSize
10
+ import io.kotest.matchers.shouldBe
11
+ import io.openapiprocessor.test.stream.Memory
12
+ import java.net.URI
13
+
14
+ class ServerSpec : StringSpec ({
15
+
16
+ " get server from openapi" {
17
+ val parser = Parser ()
18
+
19
+ Memory .add("openapi.yaml", """
20
+ openapi: 3.0.5
21
+ info:
22
+ title: OpenAPI
23
+ version: 1.0.0
24
+ servers:
25
+ - url: "{schema}://{host}:{port}/{path1}/{path2}/v{version}"
26
+ variables:
27
+ schema:
28
+ default: https
29
+ enum:
30
+ - https
31
+ - http
32
+ host:
33
+ default: openapiprocessor.io
34
+ port:
35
+ default: "443"
36
+ path1:
37
+ default: foo
38
+ path2:
39
+ default: bar
40
+ version:
41
+ default: "1"
42
+ paths: {}
43
+ """.trimIndent())
44
+
45
+ val api = parser.parse("memory:openapi.yaml")
46
+
47
+ val servers = api.getServers()
48
+ servers shouldHaveSize 1
49
+ servers[0 ].getUri() shouldBe URI .create("https://openapiprocessor.io:443/foo/bar/v1")
50
+ }
51
+ })
You can’t perform that action at this time.
0 commit comments