/
SwaggerApiDocsRoute.scala
60 lines (50 loc) · 2.25 KB
/
SwaggerApiDocsRoute.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/
package org.knora.webapi.routing
import akka.http.scaladsl.server.Route
import com.github.swagger.akka.SwaggerHttpService
import com.github.swagger.akka.model.Info
import io.swagger.models.ExternalDocs
import io.swagger.models.Scheme
import io.swagger.models.auth.BasicAuthDefinition
import org.knora.webapi.routing.admin._
import org.knora.webapi.routing.admin.lists._
/**
* Provides the '/api-docs' endpoint serving the 'swagger.json' OpenAPI specification
*/
class SwaggerApiDocsRoute(routeData: KnoraRouteData) extends KnoraRoute(routeData) with SwaggerHttpService {
// List all routes here
override val apiClasses: Set[Class[_]] = Set(
classOf[GroupsRouteADM],
classOf[DeleteListItemsRouteADM],
classOf[CreateListItemsRouteADM],
classOf[GetListItemsRouteADM],
classOf[UpdateListItemsRouteADM],
classOf[PermissionsRouteADM],
classOf[ProjectsRouteADM],
classOf[StoreRouteADM],
classOf[UsersRouteADM],
classOf[HealthRoute]
)
override val schemes: List[Scheme] = if (settings.externalKnoraApiProtocol == "http") {
List(Scheme.HTTP)
} else if (settings.externalKnoraApiProtocol == "https") {
List(Scheme.HTTPS)
} else {
List(Scheme.HTTP)
}
// swagger will publish at: http://locahost:3333/api-docs/swagger.json
override val host: String = settings.externalKnoraApiHostPort // the url of your api, not swagger's json endpoint
override val basePath = "/" // the basePath for the API you are exposing
override val apiDocsPath = "api-docs" // where you want the swagger-json endpoint exposed
override val info: Info = Info(version = "1.8.0") // provides license and other description details
override val externalDocs: Option[ExternalDocs] = Some(new ExternalDocs("Knora Docs", "http://docs.knora.org"))
override val securitySchemeDefinitions = Map("basicAuth" -> new BasicAuthDefinition())
/**
* Returns the route.
*/
override def makeRoute: Route =
routes
}