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

Commit 28acbac

Browse files
committed
check valid api path, resolves #1
1 parent 35ce1f4 commit 28acbac

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2021 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.parser
7+
8+
class NoOpenApiException : RuntimeException() {
9+
10+
override val message: String
11+
get() = "can't find OpenAPI description. Is the option 'apiPath' set?"
12+
13+
}

src/main/kotlin/io/openapiprocessor/core/parser/Parser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Parser {
3030
private val log: Logger = LoggerFactory.getLogger(this.javaClass.name)
3131

3232
fun parse(processorOptions: Map<String, *>): OpenApi {
33-
val apiPath: String = processorOptions["apiPath"].toString()
33+
val apiPath: String = processorOptions["apiPath"]?.toString() ?: throw NoOpenApiException()
3434

3535
when(val parser= processorOptions["parser"]?.toString()) {
3636
ParserType.SWAGGER.name -> {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2021 https://github.com/openapi-processor/openapi-processor-core
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.core.parser
7+
8+
import io.kotest.assertions.throwables.shouldThrow
9+
import io.kotest.core.spec.style.StringSpec
10+
11+
class ParserSpec: StringSpec({
12+
13+
"throws if apiPath is not set" {
14+
val parser = Parser()
15+
16+
shouldThrow<NoOpenApiException> {
17+
parser.parse(emptyMap<String, Any>())
18+
}
19+
}
20+
21+
})

0 commit comments

Comments
 (0)