Skip to content

Commit ae01e32

Browse files
FlorianNAdamMikilio
authored andcommitted
fix swagger-ui for scraper and schedule-manager docker images (#101)
1 parent b8610b6 commit ae01e32

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

schedule-manager/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>(
125125
))
126126
}
127127

128+
tasks.processResources { from("$projectDir/openapi.yaml") { into(".") } }
129+
128130
tasks.test { useJUnitPlatform() }
129131

130132
tasks.named("compileKotlin") {
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.nixops.schedulemanager.controller
22

3-
import java.io.File
4-
import org.springframework.core.io.FileSystemResource
3+
import org.springframework.core.io.ClassPathResource
54
import org.springframework.core.io.Resource
5+
import org.springframework.http.ResponseEntity
66
import org.springframework.web.bind.annotation.RequestMapping
77
import org.springframework.web.bind.annotation.RestController
88

99
@RestController
1010
class OpenApiSpecController {
1111

1212
@RequestMapping("/api-docs.yaml", produces = ["application/yaml"])
13-
fun getOpenApiYaml(): Resource {
14-
val file = File("openapi.yaml")
15-
println("Trying to serve: ${file.absolutePath} exists: ${file.exists()}")
16-
return FileSystemResource(file)
13+
fun getOpenApiYaml(): ResponseEntity<Resource> {
14+
val resource = ClassPathResource("openapi.yaml")
15+
return if (resource.exists()) {
16+
ResponseEntity.ok(resource)
17+
} else {
18+
ResponseEntity.notFound().build()
19+
}
1720
}
1821
}

scraper/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ tasks.openApiGenerate {
9494
skipValidateSpec.set(true)
9595
}
9696

97+
tasks.processResources { from("$projectDir/openapi.yaml") { into(".") } }
98+
9799
tasks.named("compileKotlin") { dependsOn("openApiGenerate") }
98100

99101
tasks.test { useJUnitPlatform { excludeTags("remoteApi") } }
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.nixops.scraper.controller
22

3-
import java.io.File
4-
import org.springframework.core.io.FileSystemResource
3+
import org.springframework.core.io.ClassPathResource
54
import org.springframework.core.io.Resource
5+
import org.springframework.http.ResponseEntity
66
import org.springframework.web.bind.annotation.RequestMapping
77
import org.springframework.web.bind.annotation.RestController
88

99
@RestController
1010
class OpenApiSpecController {
1111

1212
@RequestMapping("/api-docs.yaml", produces = ["application/yaml"])
13-
fun getOpenApiYaml(): Resource {
14-
val file = File("openapi.yaml")
15-
println("Trying to serve: ${file.absolutePath} exists: ${file.exists()}")
16-
return FileSystemResource(file)
13+
fun getOpenApiYaml(): ResponseEntity<Resource> {
14+
val resource = ClassPathResource("openapi.yaml")
15+
return if (resource.exists()) {
16+
ResponseEntity.ok(resource)
17+
} else {
18+
ResponseEntity.notFound().build()
19+
}
1720
}
1821
}

0 commit comments

Comments
 (0)