Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add http metrics for gravsearch endpoints (DEV-2936) #2946

Merged
merged 79 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
d758755
refactor: Replace GravsearchRequestV2 with direct SearchResponderV2 i…
seakayone Nov 16, 2023
87bf976
Remonve GravsearchCountRequestV2 and replace with direct SearchRespon…
seakayone Nov 16, 2023
f8c85e5
Remove FullTextSearchCountRequestV2 and replace by SearchRespo;nderV2…
seakayone Nov 16, 2023
df0d92f
remove FulltextSearchRequestV2
seakayone Nov 16, 2023
34c48a6
Remove SearchResourceByLabelCountRequestV2
seakayone Nov 16, 2023
bed5cba
Remove SearchResourceByLabelRequestV2
seakayone Nov 16, 2023
2893593
Remove SearchResourcesByProjectAndClassRequestV2
seakayone Nov 16, 2023
d83eec8
Move Response into SearchResponderV2
seakayone Nov 16, 2023
cb23acc
Merge branch 'main' into refactor/replace-GravsearchRequestV2-with-di…
seakayone Nov 16, 2023
3422f0b
rm ImplicitSender dep
seakayone Nov 16, 2023
9cfeee1
chore: Move ProjectIri to KnoraProject
seakayone Nov 17, 2023
1e85487
chore: Use ProjectIri
seakayone Nov 17, 2023
a8ba1c7
Merge branch 'refactor/move-ProjectIri-toKnoraProject' into feat/add-…
seakayone Nov 17, 2023
71b881a
cleanup
seakayone Nov 17, 2023
851f9f4
add SearchEndpoints
seakayone Nov 17, 2023
ad81a7f
add codec for api schema for header and query param
seakayone Nov 17, 2023
d8336aa
add apiV2Schema
seakayone Nov 17, 2023
37f3655
Remove RouteUtilV2.PROJECT_HEADER
seakayone Nov 17, 2023
bb89962
fmt
seakayone Nov 17, 2023
1edcb2a
Add JsonLdRendering codec for header, list and plain
seakayone Nov 18, 2023
f5aa091
fmt
seakayone Nov 18, 2023
4ad35d9
add markupRendering
seakayone Nov 18, 2023
5cd0b2f
fmt
seakayone Nov 18, 2023
4944ea3
header fmt
seakayone Nov 18, 2023
4593e50
Rename SchemaRendering
seakayone Nov 19, 2023
23068dd
merge main
seakayone Nov 20, 2023
086d998
fixup header
seakayone Nov 20, 2023
20d87c6
rm index.html
seakayone Nov 20, 2023
f1323bc
Merge branch 'main' into feat/add-http-metrics-for-search-endpoints
seakayone Nov 20, 2023
0652929
use unsafeFrom
seakayone Nov 20, 2023
2701a40
fixup
seakayone Nov 20, 2023
416f2ed
rm generics from schema rendering
seakayone Nov 20, 2023
71c2084
address codacy issues with unnamed result or parameter
seakayone Nov 21, 2023
21b74c7
fmt
seakayone Nov 21, 2023
3fc0fe4
Add RdfFormat codec
seakayone Nov 21, 2023
05cc948
Merge branch 'main' into feat/add-http-metrics-for-search-endpoints
seakayone Nov 30, 2023
eabb20b
fmt
seakayone Nov 30, 2023
c31b3eb
add description to in
seakayone Nov 30, 2023
6222dc7
Introduce FormatOptionsm
seakayone Nov 30, 2023
bb35a85
Add SearchApiRoutes
seakayone Nov 30, 2023
9e62679
move post /v2/searchextended over to tapir
seakayone Nov 30, 2023
867808c
move /v2/searchextended over to tapir
seakayone Nov 30, 2023
05472b6
clean up packages move files
seakayone Nov 30, 2023
61b7e24
refactor: Use SchemaHeader.simple and MarkupHeader.standoff
seakayone Nov 30, 2023
9cd40b4
hide endpoints and handler layers
seakayone Nov 30, 2023
8c21cde
add get searchextended endpoint
seakayone Nov 30, 2023
b4ae9f6
add copyright headers
seakayone Nov 30, 2023
1cd6911
fix header
seakayone Nov 30, 2023
200089b
fmt
seakayone Nov 30, 2023
ef2de53
fixup
seakayone Nov 30, 2023
a2c5ece
fixup
seakayone Nov 30, 2023
f915320
add SearchApiRoutes to test dependencies
seakayone Nov 30, 2023
1203423
simplify
seakayone Nov 30, 2023
64f4040
simplify
seakayone Nov 30, 2023
9b7baf8
fix test
seakayone Nov 30, 2023
0785e3a
fix zios to fail and not to die on expected exceptions
seakayone Nov 30, 2023
f6f25f5
fixup
seakayone Nov 30, 2023
98597d7
fixup
seakayone Nov 30, 2023
216930c
fix mapError
seakayone Nov 30, 2023
4fb2bd3
migrate count endpoint to tapir
seakayone Nov 30, 2023
f9ebacd
migrate get count endpoint to tapir
seakayone Nov 30, 2023
3329592
cleanup
seakayone Dec 1, 2023
5ef637c
cleanup
seakayone Dec 1, 2023
2de524f
add renderJsonLD
seakayone Dec 1, 2023
89a5fdc
cleanup
seakayone Dec 1, 2023
6f23b6b
cleanup
seakayone Dec 1, 2023
e65fd91
fmt
seakayone Dec 1, 2023
87b0560
simplify
seakayone Dec 1, 2023
08d23cf
simplify
seakayone Dec 1, 2023
2787b3e
fmt scaladoc
seakayone Dec 1, 2023
1603418
Make RdfFormat configurable with the Accept header
seakayone Dec 1, 2023
0dd33c6
Make Accept header optional
seakayone Dec 1, 2023
1a902e4
Remove unused code
seakayone Dec 1, 2023
607c6cc
Update webapi/src/main/scala/org/knora/webapi/routing/v2/SearchRouteV…
seakayone Dec 4, 2023
a65a92b
Update webapi/src/main/scala/org/knora/webapi/slice/common/api/ApiV2.…
seakayone Dec 4, 2023
ff34d56
Update webapi/src/main/scala/org/knora/webapi/slice/common/api/ApiV2.…
seakayone Dec 4, 2023
5f91d01
Move defaultApiV2Schema constant to ApiV2Schema.default
seakayone Dec 4, 2023
359788b
run on github
seakayone Dec 4, 2023
1829f09
Merge branch 'main' into feat/add-http-metrics-for-search-endpoints
seakayone Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 12 additions & 35 deletions integration/src/test/scala/org/knora/webapi/R2RSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
package org.knora.webapi

import com.typesafe.scalalogging.Logger
import org.apache.pekko
import org.apache.pekko.actor.ActorRef
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.model.HttpResponse
import org.apache.pekko.http.scaladsl.testkit.RouteTestTimeout
import org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand All @@ -22,22 +26,15 @@ import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration.NANOSECONDS

import org.knora.webapi.config.AppConfig
import org.knora.webapi.core.AppRouter
import org.knora.webapi.core.AppServer
import org.knora.webapi.core.LayersTest.DefaultTestEnvironmentWithoutSipi
import org.knora.webapi.core.TestStartupUtils
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
import org.knora.webapi.messages.util.rdf._
import org.knora.webapi.routing.KnoraRouteData
import org.knora.webapi.routing.UnsafeZioRun
import org.knora.webapi.util.FileUtil
import org.knora.webapi.util.LogAspect

import pekko.actor.ActorRef
import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.HttpResponse
import pekko.http.scaladsl.testkit.RouteTestTimeout
import pekko.http.scaladsl.testkit.ScalatestRouteTest

/**
* R(oute)2R(esponder) Spec base class. Please, for any new E2E tests, use E2ESpec.
*/
Expand All @@ -50,16 +47,15 @@ abstract class R2RSpec

/**
* The `Environment` that we require to exist at startup.
* Can be overriden in specs that need other implementations.
* Can be overridden in specs that need other implementations.
*/
type Environment = core.LayersTest.DefaultTestEnvironmentWithoutSipi

/**
* The effect layers from which the App is built.
* Can be overriden in specs that need other implementations.
* Can be overridden in specs that need other implementations.
*/
lazy val effectLayers: ULayer[DefaultTestEnvironmentWithoutSipi] =
core.LayersTest.integrationTestsWithFusekiTestcontainers(Some(system))
lazy val effectLayers: ULayer[Environment] = core.LayersTest.integrationTestsWithFusekiTestcontainers(Some(system))

/**
* `Bootstrap` will ensure that everything is instantiated when the Runtime is created
Expand All @@ -75,33 +71,14 @@ abstract class R2RSpec
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

// An effect for getting stuff out, so that we can pass them
// to some legacy code
private val routerAndConfig = for {
router <- ZIO.service[core.AppRouter]
config <- ZIO.service[AppConfig]
} yield (router, config)

/**
* Create router and config by unsafe running them.
*/
private val (router: AppRouter, config: AppConfig) =
Unsafe.unsafe { implicit u =>
runtime.unsafe
.run(
routerAndConfig
)
.getOrThrowFiberFailure()
}

// main difference to other specs (no own systen and executionContext defined)
lazy val rdfDataObjects = List.empty[RdfDataObject]
val log: Logger = Logger(this.getClass())
val appActor: ActorRef = router.ref
val appActor: ActorRef = UnsafeZioRun.runOrThrow(ZIO.serviceWith[core.AppRouter](_.ref))

// needed by some tests
val routeData: KnoraRouteData = KnoraRouteData(system, appActor, config)
val appConfig: AppConfig = config
val appConfig: AppConfig = UnsafeZioRun.runOrThrow(ZIO.service[AppConfig])
val routeData: KnoraRouteData = KnoraRouteData(system, appActor, appConfig)

final override def beforeAll(): Unit =
/* Here we start our app and initialize the repository before each suit runs */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.knora.webapi.slice.ontology.repo.service.PredicateRepositoryLive
import org.knora.webapi.slice.resourceinfo.ResourceInfoLayers
import org.knora.webapi.slice.resourceinfo.api.service.RestResourceInfoService
import org.knora.webapi.slice.resourceinfo.domain.IriConverter
import org.knora.webapi.slice.search.api.SearchApiRoutes
import org.knora.webapi.store.cache.CacheServiceRequestMessageHandler
import org.knora.webapi.store.cache.CacheServiceRequestMessageHandlerLive
import org.knora.webapi.store.cache.api.CacheService
Expand Down Expand Up @@ -113,6 +114,7 @@ object LayersTest {
with RestCardinalityService
with RestPermissionService
with RestResourceInfoService
with SearchApiRoutes
with SearchResponderV2
with SipiResponderADM
with OntologyInferencer
Expand Down Expand Up @@ -148,6 +150,7 @@ object LayersTest {
IriConverter.layer,
IriService.layer,
KnoraProjectRepoLive.layer,
KnoraResponseRenderer.layer,
ListsResponderADMLive.layer,
ListsResponderV2Live.layer,
MaintenanceEndpoints.layer,
Expand Down Expand Up @@ -179,6 +182,7 @@ object LayersTest {
ResourcesResponderV2Live.layer,
RestCardinalityServiceLive.layer,
RestPermissionServiceLive.layer,
SearchApiRoutes.layer,
SearchResponderV2Live.layer,
SipiResponderADMLive.layer,
StandoffResponderV2Live.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ import org.apache.pekko

import scala.util.Try

import org.knora.webapi.routing.RouteUtilV2

import pekko.http.scaladsl.model.headers.ModeledCustomHeader
import pekko.http.scaladsl.model.headers.ModeledCustomHeaderCompanion

/**
* A custom Pekko HTTP header representing [[RouteUtilV2.MARKUP_HEADER]], which a client can send to specify
* A custom Pekko HTTP header representing "x-knora-accept-markup", which a client can send to specify
* how text markup should be returned in an API response.
*
* The definition follows [[https://doc.pekko.io/docs/pekko-http/current/common/http-model.html#custom-headers]].
*/
final class MarkupHeader(token: String) extends ModeledCustomHeader[MarkupHeader] {
final class MarkupHeader private (token: String) extends ModeledCustomHeader[MarkupHeader] {
override def renderInRequests = true
override def renderInResponses = true
override val companion: MarkupHeader.type = MarkupHeader
override def value: String = token
}

object MarkupHeader extends ModeledCustomHeaderCompanion[MarkupHeader] {
override val name: String = RouteUtilV2.MARKUP_HEADER
override val name: String = "x-knora-accept-markup"
seakayone marked this conversation as resolved.
Show resolved Hide resolved
override def parse(value: String) = Try(new MarkupHeader(value))

val standoff: MarkupHeader = new MarkupHeader("standoff")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@

package org.knora.webapi.e2e.v2

import org.apache.pekko
import org.apache.pekko.http.scaladsl.model.headers.ModeledCustomHeader
import org.apache.pekko.http.scaladsl.model.headers.ModeledCustomHeaderCompanion

import scala.util.Try

import org.knora.webapi.routing.RouteUtilV2

import pekko.http.scaladsl.model.headers.ModeledCustomHeader
import pekko.http.scaladsl.model.headers.ModeledCustomHeaderCompanion

/**
* A custom Pekko HTTP header representing [[RouteUtilV2.PROJECT_HEADER]], which a client can send to specify
* A custom Pekko HTTP header "x-knora-accept-schema", which a client can send to specify
* a project from which results should be returned.
*
* The definition follows [[https://doc.pekko.io/docs/pekko-http/current/common/http-model.html#custom-headers]].
Expand All @@ -28,6 +24,6 @@ class ProjectHeader(token: String) extends ModeledCustomHeader[ProjectHeader] {
}

object ProjectHeader extends ModeledCustomHeaderCompanion[ProjectHeader] {
override val name: String = RouteUtilV2.PROJECT_HEADER
override def parse(value: String) = Try(new ProjectHeader(value))
override val name: String = "x-knora-accept-project"
override def parse(value: String): Try[ProjectHeader] = Try(new ProjectHeader(value))
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ package org.knora.webapi.e2e.v2

import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import org.apache.pekko
import org.apache.pekko.http.scaladsl.model.HttpEntity
import org.apache.pekko.http.scaladsl.model.HttpResponse
import org.apache.pekko.http.scaladsl.model.MediaRange
import org.apache.pekko.http.scaladsl.model.StatusCodes
import org.apache.pekko.http.scaladsl.model.headers.Accept
import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import org.xmlunit.diff.Diff
Expand Down Expand Up @@ -41,20 +47,11 @@ import org.knora.webapi.messages.ValuesValidator
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
import org.knora.webapi.messages.util._
import org.knora.webapi.messages.util.rdf._
import org.knora.webapi.routing.RouteUtilV2
import org.knora.webapi.routing.v2.OntologiesRouteV2
import org.knora.webapi.sharedtestdata.SharedOntologyTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.util._

import pekko.http.scaladsl.model.HttpEntity
import pekko.http.scaladsl.model.HttpResponse
import pekko.http.scaladsl.model.MediaRange
import pekko.http.scaladsl.model.StatusCodes
import pekko.http.scaladsl.model.headers.Accept
import pekko.http.scaladsl.model.headers.BasicHttpCredentials
import pekko.http.scaladsl.unmarshalling.Unmarshal

/**
* Tests the API v2 resources route.
*/
Expand Down Expand Up @@ -221,7 +218,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

"perform a resource request for the book 'Reise ins Heilige Land' using the simple schema (specified by an HTTP header) in JSON-LD" in {
val request = Get(s"$baseApiUrl/v2/resources/$reiseInsHeiligeLandIriEncoded")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
assert(response.status == StatusCodes.OK, responseAsString)
Expand All @@ -238,7 +235,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

"perform a resource request for the book 'Reise ins Heilige Land' using the simple schema in Turtle" in {
val request = Get(s"$baseApiUrl/v2/resources/$reiseInsHeiligeLandIriEncoded")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
.addHeader(Accept(RdfMediaTypes.`text/turtle`))
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
Expand All @@ -249,7 +246,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

"perform a resource request for the book 'Reise ins Heilige Land' using the simple schema in RDF/XML" in {
val request = Get(s"$baseApiUrl/v2/resources/$reiseInsHeiligeLandIriEncoded")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
.addHeader(Accept(RdfMediaTypes.`application/rdf+xml`))
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
Expand All @@ -260,7 +257,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

"perform a resource preview request for the book 'Reise ins Heilige Land' using the simple schema (specified by an HTTP header)" in {
val request = Get(s"$baseApiUrl/v2/resourcespreview/$reiseInsHeiligeLandIriEncoded")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
assert(response.status == StatusCodes.OK, responseAsString)
Expand All @@ -270,7 +267,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

"perform a resource request for the book 'Reise ins Heilige Land' using the simple schema (specified by a URL parameter)" in {
val request = Get(
s"$baseApiUrl/v2/resources/$reiseInsHeiligeLandIriEncoded?${RouteUtilV2.SCHEMA_PARAM}=${RouteUtilV2.SIMPLE_SCHEMA_NAME}"
s"$baseApiUrl/v2/resources/$reiseInsHeiligeLandIriEncoded?schema=simple"
)
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
Expand Down Expand Up @@ -343,7 +340,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
"perform a full resource request for a resource with a list value (in the simple schema)" in {
val iri = URLEncoder.encode("http://rdfh.ch/0001/thing_with_list_value", "UTF-8")
val request = Get(s"$baseApiUrl/v2/resources/$iri")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
assert(response.status == StatusCodes.OK, responseAsString)
Expand Down Expand Up @@ -378,7 +375,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
"perform a full resource request for a resource with a link (in the simple schema)" in {
val iri = URLEncoder.encode("http://rdfh.ch/0001/0C-0L1kORryKzJAJxxRyRQ", "UTF-8")
val request = Get(s"$baseApiUrl/v2/resources/$iri")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
assert(response.status == StatusCodes.OK, responseAsString)
Expand Down Expand Up @@ -413,7 +410,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
"perform a full resource request for a resource with a Text language (in the simple schema)" in {
val iri = URLEncoder.encode("http://rdfh.ch/0001/a-thing-with-text-valuesLanguage", "UTF-8")
val request = Get(s"$baseApiUrl/v2/resources/$iri")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME))
.addHeader(SchemaHeader.simple)
val response: HttpResponse = singleAwaitingRequest(request)
val responseAsString = responseToString(response)
assert(response.status == StatusCodes.OK, responseAsString)
Expand Down Expand Up @@ -833,7 +830,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

// Request the newly created resource in the simple schema, and check that it matches the ontology.
val resourceSimpleGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(resourceIri, "UTF-8")}")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME)) ~> addCredentials(
.addHeader(SchemaHeader.simple) ~> addCredentials(
BasicHttpCredentials(anythingUserEmail, password)
)
val resourceSimpleGetResponse: HttpResponse = singleAwaitingRequest(resourceSimpleGetRequest)
Expand Down Expand Up @@ -901,7 +898,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {

// Request the newly created resource in the simple schema, and check that it matches the ontology.
val resourceSimpleGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(resourceIri, "UTF-8")}")
.addHeader(new SchemaHeader(RouteUtilV2.SIMPLE_SCHEMA_NAME)) ~> addCredentials(
.addHeader(SchemaHeader.simple) ~> addCredentials(
BasicHttpCredentials(anythingUserEmail, password)
)
val resourceSimpleGetResponse: HttpResponse = singleAwaitingRequest(resourceSimpleGetRequest)
Expand Down Expand Up @@ -1748,7 +1745,7 @@ class ResourcesRouteV2E2ESpec extends E2ESpec {
"read the large text without its markup, and get the markup separately as pages of standoff" ignore { // depends on previous test
// Get the resource without markup.
val resourceGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(hamletResourceIri.get, "UTF-8")}")
.addHeader(new MarkupHeader(RouteUtilV2.MARKUP_STANDOFF)) ~> addCredentials(
.addHeader(MarkupHeader.standoff) ~> addCredentials(
BasicHttpCredentials(anythingUserEmail, password)
)
val resourceGetResponse: HttpResponse = singleAwaitingRequest(resourceGetRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@

package org.knora.webapi.e2e.v2

import org.apache.pekko
import org.apache.pekko.http.scaladsl.model.headers.ModeledCustomHeader
import org.apache.pekko.http.scaladsl.model.headers.ModeledCustomHeaderCompanion

import scala.util.Try

import org.knora.webapi.routing.RouteUtilV2

import pekko.http.scaladsl.model.headers.ModeledCustomHeader
import pekko.http.scaladsl.model.headers.ModeledCustomHeaderCompanion

/**
* A custom Pekko HTTP header representing [[RouteUtilV2.SCHEMA_HEADER]], which a client can send to specify
* which ontology schema should be used in an API response.
* A custom Pekko HTTP header "x-knora-accept-schema", which a client can send to specify which ontology schema
* should be used in an API response.
*
* The definition follows [[https://doc.pekko.io/docs/pekko-http/current/common/http-model.html#custom-headers]].
*/
final class SchemaHeader(token: String) extends ModeledCustomHeader[SchemaHeader] {
final class SchemaHeader private (token: String) extends ModeledCustomHeader[SchemaHeader] {
override def renderInRequests = true
override def renderInResponses = true
override val companion: SchemaHeader.type = SchemaHeader
override def value: String = token
}

object SchemaHeader extends ModeledCustomHeaderCompanion[SchemaHeader] {
override val name: String = RouteUtilV2.SCHEMA_HEADER
override val name: String = "x-knora-accept-schema"
override def parse(value: String) = Try(new SchemaHeader(value))

val simple: SchemaHeader = SchemaHeader("simple")
val complex: SchemaHeader = SchemaHeader("complex")
}
Loading
Loading