Skip to content

Commit

Permalink
Allow to create schemas on the resource endpoint for legacy purposes (#…
Browse files Browse the repository at this point in the history
…4851)

Co-authored-by: Simon Dumas <[email protected]>
  • Loading branch information
imsdu and Simon Dumas authored Apr 9, 2024
1 parent 53a0d09 commit ea14433
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectOn[InvalidSchemaRejection]
)
}
},
Expand All @@ -113,6 +114,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectOn[InvalidSchemaRejection]
)
case (Some(rev), source, tag) =>
// Update a resource
Expand All @@ -122,7 +124,7 @@ final class ResourcesRoutes(
.flatTap(index(project, _, mode))
.map(_.void)
.attemptNarrow[ResourceRejection]
.rejectOn[ResourceNotFound]
.rejectWhen { case _: ResourceNotFound | _: InvalidSchemaRejection => true }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.epfl.bluebrain.nexus.tests.kg

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.{HttpResponse, StatusCodes}
import cats.syntax.all._
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils
import ch.epfl.bluebrain.nexus.tests.BaseIntegrationSpec
import ch.epfl.bluebrain.nexus.tests.Identity.resources.Rick
Expand Down Expand Up @@ -195,6 +196,24 @@ class SchemasSpec extends BaseIntegrationSpec {
}
} yield succeed
}

"create a schema against the resource endpoint" in {
val id = genId()
val schemaSegment = UrlUtils.encode("https://bluebrain.github.io/nexus/schemas/shacl-20170720.ttl")

for {
payload <- SchemaPayloads.simple(id)
_ <- deltaClient.put[Json](s"/resources/$project/$schemaSegment/$id", payload, Rick) { expectCreated }
// Attempting to create it again and to get a 409 as a response
_ <- deltaClient.put[Json](s"/resources/$project/$schemaSegment/$id", payload, Rick) { (json, response) =>
json should have(`@type`("ResourceAlreadyExists"))
response.status shouldEqual StatusCodes.Conflict
}
// Should be fetched as a schema
_ <- deltaClient.get[Json](s"/schemas/$project/$id", Rick) { expectOk }
} yield succeed

}
}

}

0 comments on commit ea14433

Please sign in to comment.