Skip to content

Commit

Permalink
Merge pull request #403 from NDLANO/tapir-learningpath-api
Browse files Browse the repository at this point in the history
learningpath-api: Rewrite to tapir
  • Loading branch information
jnatten authored Feb 26, 2024
2 parents 80a048c + 598d952 commit 1203338
Show file tree
Hide file tree
Showing 179 changed files with 2,440 additions and 3,651 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import no.ndla.network.tapir.{
TapirHealthController
}
import no.ndla.network.clients.{FeideApiClient, RedisClient}
import no.ndla.network.scalatra.{NdlaControllerBase, NdlaSwaggerSupport}
import no.ndla.search.{BaseIndexService, Elastic4sClient}

class ComponentRegistry(properties: ArticleApiProperties)
Expand All @@ -40,8 +39,6 @@ class ComponentRegistry(properties: ArticleApiProperties)
with DataSource
with InternController
with ArticleControllerV2
with NdlaControllerBase
with NdlaSwaggerSupport
with ArticleRepository
with Elastic4sClient
with SearchApiClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import scala.util.Try
* that require login
*
* One would use the class by using `Cachable.yes(value)` (Or `Cachable.no(value)`) for values that can be cached and
* then use `returnValue.Ok()` in the controller to get the scalatra type with headers.
* then use `returnValue.Ok()` in the controller to get the resutling type with headers in a tuple.
*/
case class Cachable[T](
value: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import no.ndla.articleapi.model.domain.DBArticle
import no.ndla.common.Clock
import no.ndla.network.NdlaClient
import no.ndla.network.clients.{FeideApiClient, RedisClient}
import no.ndla.network.scalatra.{NdlaControllerBase, NdlaSwaggerSupport}
import no.ndla.network.tapir.{NdlaMiddleware, Routes, Service, TapirHealthController}
import no.ndla.search.{BaseIndexService, Elastic4sClient}
import org.mockito.scalatest.MockitoSugar
Expand All @@ -34,8 +33,6 @@ trait TestEnvironment
with IndexService
with BaseIndexService
with SearchService
with NdlaControllerBase
with NdlaSwaggerSupport
with ArticleControllerV2
with InternController
with NdlaMiddleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

package no.ndla.common.errors

import org.scalatra.swagger.annotations._
import org.scalatra.swagger.runtime.annotations.ApiModelProperty
import sttp.tapir.Schema.annotations.description

@description("A message describing a validation error on a specific field")
@ApiModel(description = "A message describing a validation error on a specific field")
@description("A message describing a validation error on a specific field")
case class ValidationMessage(
@description("The field the error occured in")
@ApiModelProperty(description = "The field the error occured in")
field: String,
@description("The validation message")
@ApiModelProperty(description = "The validation message")
message: String
)

Expand Down
24 changes: 11 additions & 13 deletions common/src/main/scala/no/ndla/common/model/api/DraftCopyright.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@

package no.ndla.common.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.model.NDLADate
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}

import scala.annotation.meta.field
import sttp.tapir.Schema.annotations.description

@ApiModel(description = "Description of copyright information")
@description("Description of copyright information")
case class DraftCopyright(
@(ApiModelProperty @field)(description = "Describes the license of the article") license: Option[License],
@(ApiModelProperty @field)(description = "Reference to where the article is procured") origin: Option[String],
@(ApiModelProperty @field)(description = "List of creators") creators: Seq[Author],
@(ApiModelProperty @field)(description = "List of processors") processors: Seq[Author],
@(ApiModelProperty @field)(description = "List of rightsholders") rightsholders: Seq[Author],
@(ApiModelProperty @field)(description = "Date from which the copyright is valid") validFrom: Option[NDLADate],
@(ApiModelProperty @field)(description = "Date to which the copyright is valid") validTo: Option[NDLADate],
@(ApiModelProperty @field)(description = "Whether or not the content has been processed") processed: Boolean
@description("Describes the license of the article") license: Option[License],
@description("Reference to where the article is procured") origin: Option[String],
@description("List of creators") creators: Seq[Author],
@description("List of processors") processors: Seq[Author],
@description("List of rightsholders") rightsholders: Seq[Author],
@description("Date from which the copyright is valid") validFrom: Option[NDLADate],
@description("Date to which the copyright is valid") validTo: Option[NDLADate],
@description("Whether or not the content has been processed") processed: Boolean
)

object DraftCopyright {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

package no.ndla.common.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}

import scala.annotation.meta.field
import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@ApiModel(description = "External link related to the article")
@description("External link related to the article")
case class RelatedContentLink(
@(ApiModelProperty @field)(description = "Title of the article") title: String,
@(ApiModelProperty @field)(description = "The url to where the article can be viewed") url: String
@description("Title of the article") title: String,
@description("The url to where the article can be viewed") url: String
)

object RelatedContentLink {
Expand Down
18 changes: 8 additions & 10 deletions common/src/main/scala/no/ndla/common/model/api/draft/Comment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ package no.ndla.common.model.api.draft
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.model.NDLADate
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}
import sttp.tapir.Schema.annotations.description

import scala.annotation.meta.field

@ApiModel(description = "Information about a comment attached to an article")
@description("Information about a comment attached to an article")
case class Comment(
@(ApiModelProperty @field)(description = "Id of the comment") id: String,
@(ApiModelProperty @field)(description = "Content of the comment") content: String,
@(ApiModelProperty @field)(description = "When the comment was created") created: NDLADate,
@(ApiModelProperty @field)(description = "When the comment was last updated") updated: NDLADate,
@(ApiModelProperty @field)(description = "If the comment is open or closed") isOpen: Boolean,
@(ApiModelProperty @field)(description = "If the comment is solved or not") solved: Boolean
@description("Id of the comment") id: String,
@description("Content of the comment") content: String,
@description("When the comment was created") created: NDLADate,
@description("When the comment was last updated") updated: NDLADate,
@description("If the comment is open or closed") isOpen: Boolean,
@description("If the comment is solved or not") solved: Boolean
)

object Comment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import no.ndla.network.NdlaClient
import no.ndla.search.{BaseIndexService, Elastic4sClient}
import no.ndla.common.Clock
import no.ndla.common.configuration.BaseComponentRegistry
import no.ndla.network.scalatra.{NdlaControllerBase, NdlaSwaggerSupport}
import no.ndla.network.tapir.{
NdlaMiddleware,
Routes,
Expand Down Expand Up @@ -61,8 +60,6 @@ class ComponentRegistry(properties: ConceptApiProperties)
with Props
with DBMigrator
with ErrorHelpers
with NdlaControllerBase
with NdlaSwaggerSupport
with SearchSettingsHelper
with DraftSearchSettingsHelper
with TaxonomyApiClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import no.ndla.conceptapi.service.search.{DraftConceptSearchService, SearchConve
import no.ndla.conceptapi.service.{ConverterService, ReadService, WriteService}
import no.ndla.conceptapi.{Eff, Props}
import no.ndla.language.Language.AllLanguages
import no.ndla.network.scalatra.NdlaSwaggerSupport
import no.ndla.network.tapir.NoNullJsonPrinter.jsonBody
import no.ndla.network.tapir.TapirErrors.errorOutputsFor
import no.ndla.network.tapir.auth.Permission.CONCEPT_API_WRITE
Expand All @@ -37,7 +36,6 @@ trait DraftConceptController {
with SearchConverterService
with ConverterService
with Props
with NdlaSwaggerSupport
with ConceptControllerHelpers
with ErrorHelpers =>
val draftConceptController: DraftConceptController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import no.ndla.conceptapi.service.search.{PublishedConceptSearchService, SearchC
import no.ndla.conceptapi.service.{ReadService, WriteService}
import no.ndla.conceptapi.{Eff, Props}
import no.ndla.language.Language
import no.ndla.network.scalatra.NdlaSwaggerSupport
import no.ndla.network.tapir.NoNullJsonPrinter.jsonBody
import no.ndla.network.tapir.TapirErrors.errorOutputsFor
import no.ndla.network.tapir.{DynamicHeaders, Service}
Expand All @@ -33,7 +32,6 @@ trait PublishedConceptController {
with PublishedConceptSearchService
with SearchConverterService
with Props
with NdlaSwaggerSupport
with ConceptControllerHelpers
with ErrorHelpers =>
val publishedConceptController: PublishedConceptController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ package no.ndla.conceptapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}
import sttp.tapir.Schema.annotations.description

import scala.annotation.meta.field

@ApiModel(description = "Information about the concept")
@description("Information about the concept")
case class ConceptContent(
@(ApiModelProperty @field)(description = "The content of this concept") content: String,
@(ApiModelProperty @field)(description = "The html content of this concept") htmlContent: String,
@(ApiModelProperty @field)(description = "The language of this concept") language: String
@description("The content of this concept") content: String,
@description("The html content of this concept") htmlContent: String,
@description("The language of this concept") language: String
)

object ConceptContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@

package no.ndla.conceptapi.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}

import scala.annotation.meta.field
import io.circe.{Decoder, Encoder}
import no.ndla.conceptapi.model.domain
import sttp.tapir.Schema.annotations.description

@ApiModel(description = "Information about articles")
@description("Information about articles")
case class ConceptDomainDump(
@(ApiModelProperty @field)(description = "The total number of concepts in the database") totalCount: Long,
@(ApiModelProperty @field)(description = "For which page results are shown from") page: Int,
@(ApiModelProperty @field)(description = "The number of results per page") pageSize: Int,
@(ApiModelProperty @field)(description = "The search results") results: Seq[domain.Concept]
@description("The total number of concepts in the database") totalCount: Long,
@description("For which page results are shown from") page: Int,
@description("The number of results per page") pageSize: Int,
@description("The search results") results: Seq[domain.Concept]
)

object ConceptDomainDump {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
package no.ndla.conceptapi.model.api
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}
import sttp.tapir.Schema.annotations.description

import scala.annotation.meta.field

@ApiModel(description = "Meta image for the concept")
@description("Meta image for the concept")
case class ConceptMetaImage(
@(ApiModelProperty @field)(description = "The meta image url") url: String,
@(ApiModelProperty @field)(description = "The alt text for the meta image") alt: String,
@(ApiModelProperty @field)(
description = "The ISO 639-1 language code describing which concept translation this meta image belongs to"
@description("The meta image url") url: String,
@description("The alt text for the meta image") alt: String,
@description(
"The ISO 639-1 language code describing which concept translation this meta image belongs to"
) language: String
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
package no.ndla.conceptapi.model.api
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}

import scala.annotation.meta.field
import no.ndla.common.model.NDLADate
import sttp.tapir.Schema.annotations.description

@ApiModel(description = "Information about the responsible")
@description("Information about the responsible")
case class ConceptResponsible(
// format: off
@(ApiModelProperty @field)(description = "NDLA ID of responsible editor") responsibleId: String,
@(ApiModelProperty @field)(description = "Date of when the responsible editor was last updated") lastUpdated: NDLADate,
// format: on
@description("NDLA ID of responsible editor") responsibleId: String,
@description("Date of when the responsible editor was last updated") lastUpdated: NDLADate
)

object ConceptResponsible {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ package no.ndla.conceptapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}
import sttp.tapir.Schema.annotations.description

import scala.annotation.meta.field

@ApiModel(description = "Meta image for the concept")
@description("Meta image for the concept")
case class ConceptTags(
@(ApiModelProperty @field)(description = "Searchable tags") tags: Seq[String],
@(ApiModelProperty @field)(
description = "The ISO 639-1 language code describing which concept translation these tags belongs to"
@description("Searchable tags") tags: Seq[String],
@description(
"The ISO 639-1 language code describing which concept translation these tags belongs to"
) language: String
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ package no.ndla.conceptapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}
import sttp.tapir.Schema.annotations.description

import scala.annotation.meta.field

@ApiModel(description = "Information about the concept")
@description("Information about the concept")
case class ConceptTitle(
@(ApiModelProperty @field)(description = "The title of this concept") title: String,
@(ApiModelProperty @field)(description = "The language of this concept") language: String
@description("The title of this concept") title: String,
@description("The language of this concept") language: String
)

object ConceptTitle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ package no.ndla.conceptapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import org.scalatra.swagger.annotations.{ApiModel, ApiModelProperty}

import scala.annotation.meta.field
import sttp.tapir.Schema.annotations.description

// format: off
@ApiModel(description = "The search parameters")
@description("The search parameters")
case class DraftConceptSearchParams(
@(ApiModelProperty @field)(description = "The search query.") query: Option[String],
@(ApiModelProperty @field)(description = "The ISO 639-1 language code describing language used in query-params.") language: Option[String],
@(ApiModelProperty @field)(description = "The page number of the search hits to display.") page: Option[Int],
@(ApiModelProperty @field)(description = "The number of search hits to display for each page.") pageSize: Option[Int],
@(ApiModelProperty @field)(description = "Return only articles that have one of the provided ids.") idList: List[Long],
@(ApiModelProperty @field)(description = "The sorting used on results. Default is by -relevance.") sort: Option[String],
@(ApiModelProperty @field)(description = "Whether to fallback to existing language if not found in selected language.") fallback: Option[Boolean],
@(ApiModelProperty @field)(description = "A search context retrieved from the response header of a previous search.") scrollId: Option[String],
@(ApiModelProperty @field)(description = "A comma-separated list of subjects that should appear in the search.") subjects: Set[String],
@(ApiModelProperty @field)(description = "A comma-separated list of tags to filter the search by.") tags: Set[String],
@(ApiModelProperty @field)(description = "A comma-separated list of statuses that should appear in the search.") status: Set[String],
@(ApiModelProperty @field)(description = "A comma-separated list of users to filter the search by.") users: Seq[String],
@(ApiModelProperty @field)(description = "Embed resource type that should exist in the concepts.") embedResource: Option[String],
@(ApiModelProperty @field)(description = "Embed id attribute that should exist in the concepts.") embedId: Option[String],
@(ApiModelProperty @field)(description = "A comma-separated list of NDLA IDs to filter the search by.") responsibleIds: List[String],
@(ApiModelProperty @field)(description = "The type of concepts to return.") conceptType: Option[String],
@(ApiModelProperty @field)(description = "A list of index paths to aggregate over") aggregatePaths: List[String],
@description("The search query.") query: Option[String],
@description("The ISO 639-1 language code describing language used in query-params.") language: Option[String],
@description("The page number of the search hits to display.") page: Option[Int],
@description("The number of search hits to display for each page.") pageSize: Option[Int],
@description("Return only articles that have one of the provided ids.") idList: List[Long],
@description("The sorting used on results. Default is by -relevance.") sort: Option[String],
@description("Whether to fallback to existing language if not found in selected language.") fallback: Option[Boolean],
@description("A search context retrieved from the response header of a previous search.") scrollId: Option[String],
@description("A comma-separated list of subjects that should appear in the search.") subjects: Set[String],
@description("A comma-separated list of tags to filter the search by.") tags: Set[String],
@description("A comma-separated list of statuses that should appear in the search.") status: Set[String],
@description("A comma-separated list of users to filter the search by.") users: Seq[String],
@description("Embed resource type that should exist in the concepts.") embedResource: Option[String],
@description("Embed id attribute that should exist in the concepts.") embedId: Option[String],
@description("A comma-separated list of NDLA IDs to filter the search by.") responsibleIds: List[String],
@description("The type of concepts to return.") conceptType: Option[String],
@description("A list of index paths to aggregate over") aggregatePaths: List[String],
)

object DraftConceptSearchParams{
Expand Down
Loading

0 comments on commit 1203338

Please sign in to comment.