diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationController.scala index 0cad1183..f2878d20 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationController.scala @@ -47,9 +47,7 @@ class ApiDocumentationController @Inject() ( loggedInUserService: LoggedInUserService, errorHandler: ErrorHandler, mcc: MessagesControllerComponents, - apiIndexView: ApiIndexView, retiredVersionJumpView: RetiredVersionJumpView, - apisFilteredView: ApisFilteredView, xmlDocumentationView: XmlDocumentationView, parentPage: ParentPageOuter, xmlServicesService: XmlServicesService, @@ -61,47 +59,15 @@ class ApiDocumentationController @Inject() ( ) extends FrontendController(mcc) with HeaderNavigation with PageAttributesHelper with HomeCrumb with DocumentationCrumb with ApplicationLogger { private lazy val cacheControlHeaders = "cache-control" -> "no-cache,no-store,max-age=0" - private lazy val apiDocCrumb = Crumb("API Documentation", routes.ApiDocumentationController.apiIndexPage(None, None, None).url) - private lazy val v2ApiDocCrumb = Crumb( + private lazy val apiDocCrumb = Crumb( "API Documentation", - uk.gov.hmrc.apidocumentation.v2.controllers.routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url + routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url ) - def apiIndexPage(service: Option[ServiceName], version: Option[ApiVersionNbr], filter: Option[String]): Action[AnyContent] = headerNavigation { implicit request => navLinks => - def pageAttributes(title: String = "API Documentation") = - PageAttributes(title, breadcrumbs = Breadcrumbs(documentationCrumb, homeCrumb), headerLinks = navLinks, sidebarLinks = navigationService.sidebarNavigation()) - - val params = for (a <- service; b <- version) yield (a, b) - - params match { - case Some((service, version)) => - val url = routes.ApiDocumentationController.renderApiDocumentation(service, version, None).url - Future.successful(Redirect(url)) - case None => - (for { - userId <- extractDeveloperIdentifier(loggedInUserService.fetchLoggedInUser()) - apis <- apiDefinitionService.fetchAllDefinitions(userId) - xmlApis <- xmlServicesService.fetchAllXmlApis() - } yield { - val apisByCategory = Documentation.groupedByCategory(apis, xmlApis, ServiceGuide.serviceGuides, RoadMap.roadMaps) - - filter match { - case Some(f) => Ok(apisFilteredView(pageAttributes("Filtered API Documentation"), apisByCategory, DocumentationCategory.fromFilter(f))) - case _ => Ok(apiIndexView(pageAttributes(), apisByCategory)) - } - - }) recoverWith { - case e: Throwable => - logger.error("Could not load API Documentation service", e) - errorHandler.internalServerErrorTemplate.map(InternalServerError(_)) - } - } - } - def redirectToApiDocumentation(service: ServiceName, version: Option[ApiVersionNbr]): Action[AnyContent] = version match { case Some(version) => Action.async { - Future.successful(Redirect(routes.ApiDocumentationController.renderApiDocumentation(service, version, None))) + Future.successful(Redirect(routes.ApiDocumentationController.renderApiDocumentation(service, version))) } case _ => redirectToCurrentApiDocumentation(service) } @@ -112,7 +78,7 @@ class ApiDocumentationController @Inject() ( extendedDefn <- apiDefinitionService.fetchExtendedDefinition(service, userId) } yield { extendedDefn.flatMap(_.userAccessibleApiDefinition.defaultVersion).fold(errorHandler.notFoundTemplate.map(NotFound(_))) { version => - successful(Redirect(routes.ApiDocumentationController.renderApiDocumentation(service, version.version, None))) + successful(Redirect(routes.ApiDocumentationController.renderApiDocumentation(service, version.version))) } }).flatten recoverWith { case _: NotFoundException => errorHandler.notFoundTemplate.map(NotFound(_)) @@ -122,12 +88,12 @@ class ApiDocumentationController @Inject() ( } } - def renderApiDocumentation(service: ServiceName, version: ApiVersionNbr, useV2: Option[Boolean]): Action[AnyContent] = + def renderApiDocumentation(service: ServiceName, version: ApiVersionNbr): Action[AnyContent] = headerNavigation { implicit request => navLinks => (for { userId <- extractDeveloperIdentifier(loggedInUserService.fetchLoggedInUser()) api <- apiDefinitionService.fetchExtendedDefinition(service, userId) - apiDocumentation <- doRenderApiDocumentation(service, version, api, navLinks, userId, useV2) + apiDocumentation <- doRenderApiDocumentation(service, version, api, navLinks, userId) } yield apiDocumentation) recoverWith { case e: NotFoundException => logger.info(s"Upstream request not found: ${e.getMessage}") @@ -144,18 +110,13 @@ class ApiDocumentationController @Inject() ( version: ApiVersionNbr, apiOption: Option[ExtendedApiDefinition], navLinks: Seq[NavLink], - developerId: Option[DeveloperIdentifier], - useV2IndexPage: Option[Boolean] + developerId: Option[DeveloperIdentifier] )(implicit request: Request[AnyContent], messagesProvider: MessagesProvider ): Future[Result] = { def makePageAttributes(apiDefinition: ExtendedApiDefinition, sidebarLinks: Seq[SidebarLink]) = { - val breadcrumbs = if (useV2IndexPage.getOrElse(false)) Breadcrumbs( - v2ApiDocCrumb, - homeCrumb - ) - else Breadcrumbs( + val breadcrumbs = Breadcrumbs( apiDocCrumb, homeCrumb ) @@ -166,27 +127,25 @@ class ApiDocumentationController @Inject() ( def renderNotFoundPage = errorHandler.notFoundTemplate.map(NotFound(_)) def redirectToLoginPage = { - logger.info(s"redirectToLogin - access_uri ${routes.ApiDocumentationController.renderApiDocumentation(service, version, None).url}") + logger.info(s"redirectToLogin - access_uri ${routes.ApiDocumentationController.renderApiDocumentation(service, version).url}") Future.successful(Redirect("/developer/login").withSession( - "access_uri" -> routes.ApiDocumentationController.renderApiDocumentation(service, version, None).url, + "access_uri" -> routes.ApiDocumentationController.renderApiDocumentation(service, version).url, "ts" -> Instant.now(Clock.systemUTC).toEpochMilli.toString )) } - def renderRetiredVersionJumpPage(api: ExtendedApiDefinition, useV2: Option[Boolean])(implicit request: Request[AnyContent], messagesProvider: MessagesProvider) = { + def renderRetiredVersionJumpPage(api: ExtendedApiDefinition)(implicit request: Request[AnyContent], messagesProvider: MessagesProvider) = { val apiDefinition = api.userAccessibleApiDefinition Future.successful(Ok(retiredVersionJumpView( makePageAttributes(apiDefinition, navigationService.sidebarNavigation()), - apiDefinition, - useV2 + apiDefinition ))) } def renderDocumentationPage( api: ExtendedApiDefinition, - selectedVersion: ExtendedApiVersion, - useV2: Option[Boolean] + selectedVersion: ExtendedApiVersion )(implicit request: Request[AnyContent], messagesProvider: MessagesProvider ): Future[Result] = { @@ -220,7 +179,7 @@ class ApiDocumentationController @Inject() ( markdownBlocks = List(overview, errors, testing) ++ (if (requiredFraudPrevention) List(fraudPrevention) else List()) ++ List(versioning) attrs = makePageAttributes(api, navigationService.openApiSidebarNavigation(markdownBlocks)) - } yield Ok(parentPage(attrs, markdownBlocks, api.name, api, selectedVersion, developerId.isDefined, useV2 = useV2)).withHeaders(cacheControlHeaders) + } yield Ok(parentPage(attrs, markdownBlocks, api.name, api, selectedVersion, developerId.isDefined)).withHeaders(cacheControlHeaders) } val categories = APICategoryFilters.categoryMap.getOrElse(api.name, Seq.empty) ++ api.categories @@ -235,28 +194,22 @@ class ApiDocumentationController @Inject() ( } yield (api, apiVersion, visibility) findVersion(apiOption) match { - case Some((api, selectedVersion, VersionVisibility(_, _, true, _))) if selectedVersion.status == ApiStatus.RETIRED => renderRetiredVersionJumpPage(api, useV2IndexPage) - case Some((api, selectedVersion, VersionVisibility(_, _, true, _))) => renderDocumentationPage(api, selectedVersion, useV2IndexPage) - case Some((api, selectedVersion, VersionVisibility(ApiAccessType.PRIVATE, _, false, true))) => renderDocumentationPage(api, selectedVersion, useV2IndexPage) + case Some((api, selectedVersion, VersionVisibility(_, _, true, _))) if selectedVersion.status == ApiStatus.RETIRED => renderRetiredVersionJumpPage(api) + case Some((api, selectedVersion, VersionVisibility(_, _, true, _))) => renderDocumentationPage(api, selectedVersion) + case Some((api, selectedVersion, VersionVisibility(ApiAccessType.PRIVATE, _, false, true))) => renderDocumentationPage(api, selectedVersion) case Some((_, _, VersionVisibility(ApiAccessType.PRIVATE, false, _, _))) => redirectToLoginPage case _ => renderNotFoundPage } } // scalastyle:on method.length - def renderXmlApiDocumentation(name: String, useV2: Option[Boolean]): Action[AnyContent] = headerNavigation { implicit request => navLinks => + def renderXmlApiDocumentation(name: String): Action[AnyContent] = headerNavigation { implicit request => navLinks => def makePageAttributes(apiDefinition: Documentation): PageAttributes = { val xmlCrumb = Crumb( apiDefinition.name, - routes.ApiDocumentationController.renderXmlApiDocumentation(apiDefinition.context, useV2).url + routes.ApiDocumentationController.renderXmlApiDocumentation(apiDefinition.context).url ) - val breadcrumbs = if (useV2.getOrElse(false)) { - Breadcrumbs( - xmlCrumb, - v2ApiDocCrumb, - homeCrumb - ) - } else Breadcrumbs( + val breadcrumbs = Breadcrumbs( xmlCrumb, apiDocCrumb, homeCrumb diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/DocumentationController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/DocumentationController.scala index 6bf8d16a..0562cfe1 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/DocumentationController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/DocumentationController.scala @@ -36,11 +36,8 @@ class DocumentationController @Inject() ( partialsService: PartialsService, mcc: MessagesControllerComponents, indexView: IndexView, - retiredVersionJumpView: RetiredVersionJumpView, tutorialsView: TutorialsView, - credentialsView: CredentialsView, developmentPracticesView: DevelopmentPracticesView, - mtdIntroductionView: MtdIntroductionView, namingGuidelinesView: NamingGuidelinesView, referenceView: ReferenceView, termsOfUseView: TermsOfUseView, @@ -131,7 +128,7 @@ class DocumentationController @Inject() ( _ => navLinks => Future.successful( Redirect( - routes.ApiDocumentationController.apiIndexPage(None, None, None).url + routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url ) ) } diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/DownloadController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/DownloadController.scala index 58781454..24e46c48 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/DownloadController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/DownloadController.scala @@ -43,12 +43,12 @@ class DownloadController @Inject() ( )(implicit val ec: ExecutionContext ) extends FrontendController(cc) with ApplicationLogger { - def downloadResource(service: ServiceName, version: ApiVersionNbr, resource: String, useV2: Option[Boolean]) = Action.async { implicit request => + def downloadResource(service: ServiceName, version: ApiVersionNbr, resource: String) = Action.async { implicit request => (for { userId <- extractDeveloperIdentifier(loggedInUserService.fetchLoggedInUser()) api <- apiDefinitionService.fetchExtendedDefinition(service, userId) validResource = validateResource(resource) - result <- fetchResourceForApi(api, version, validResource, useV2) + result <- fetchResourceForApi(api, version, validResource) } yield { result }) recoverWith { @@ -61,8 +61,7 @@ class DownloadController @Inject() ( } } - private def fetchResourceForApi(apiOption: Option[ExtendedApiDefinition], version: ApiVersionNbr, validResource: String, useV2: Option[Boolean])(implicit request: Request[_]) - : Future[Result] = { + private def fetchResourceForApi(apiOption: Option[ExtendedApiDefinition], version: ApiVersionNbr, validResource: String)(implicit request: Request[_]): Future[Result] = { def findVersion(apiOption: Option[ExtendedApiDefinition]) = for { api <- apiOption @@ -75,7 +74,7 @@ class DownloadController @Inject() ( def redirectToLoginPage(service: ServiceName) = Future.successful(Redirect("/developer/login").withSession( - "access_uri" -> routes.ApiDocumentationController.renderApiDocumentation(service, version, useV2).url + "access_uri" -> routes.ApiDocumentationController.renderApiDocumentation(service, version).url )) findVersion(apiOption) match { diff --git a/app/uk/gov/hmrc/apidocumentation/v2/controllers/FilteredDocumentationIndexController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/FilteredDocumentationIndexController.scala similarity index 89% rename from app/uk/gov/hmrc/apidocumentation/v2/controllers/FilteredDocumentationIndexController.scala rename to app/uk/gov/hmrc/apidocumentation/controllers/FilteredDocumentationIndexController.scala index b3cb6a59..693cfe04 100644 --- a/app/uk/gov/hmrc/apidocumentation/v2/controllers/FilteredDocumentationIndexController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/FilteredDocumentationIndexController.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package uk.gov.hmrc.apidocumentation.v2.controllers +package uk.gov.hmrc.apidocumentation.controllers import javax.inject.{Inject, Singleton} import scala.concurrent.{ExecutionContext, Future} @@ -26,12 +26,10 @@ import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController import uk.gov.hmrc.apidocumentation.ErrorHandler import uk.gov.hmrc.apidocumentation.config.ApplicationConfig -import uk.gov.hmrc.apidocumentation.controllers.{DocumentationCrumb, HeaderNavigation, HomeCrumb, routes} import uk.gov.hmrc.apidocumentation.models._ import uk.gov.hmrc.apidocumentation.services.{ApiDefinitionService, LoggedInUserService, NavigationService, XmlServicesService} import uk.gov.hmrc.apidocumentation.util.ApplicationLogger -import uk.gov.hmrc.apidocumentation.v2.models._ -import uk.gov.hmrc.apidocumentation.v2.views.html.FilteredIndexView +import uk.gov.hmrc.apidocumentation.views.html.documentationList.FilteredIndexView @Singleton class FilteredDocumentationIndexController @Inject() ( @@ -47,11 +45,9 @@ class FilteredDocumentationIndexController @Inject() ( ) extends FrontendController(mcc) with HeaderNavigation with ApplicationLogger with DocumentationCrumb with HomeCrumb { - // lazy val v2HomeCrumb = - // Crumb("Home", uk.gov.hmrc.apidocumentation.v2.controllers.routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url) private lazy val apiDocCrumb = Crumb( "API Documentation", - uk.gov.hmrc.apidocumentation.v2.controllers.routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url + uk.gov.hmrc.apidocumentation.controllers.routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url ) private lazy val restApiDescriptionOverrides: Seq[RestApiDescriptionOverride] = RestApiDescriptionOverride.descriptionOverrides @@ -109,7 +105,7 @@ class FilteredDocumentationIndexController @Inject() ( private def xmlApiToXmlDocumentation(api: XmlApiDocumentation) = { val identifier = DocumentIdentifier(api.name) - val url = routes.ApiDocumentationController.renderXmlApiDocumentation(identifier.value, useV2 = Some(true)).url + val url = routes.ApiDocumentationController.renderXmlApiDocumentation(identifier.value).url XmlDocumentation.fromXmlDocumentation(identifier, api, url) } @@ -118,7 +114,7 @@ class FilteredDocumentationIndexController @Inject() ( .versionsAsList .sorted(WrappedApiDefinition.statusVersionOrdering) .head.versionNbr - val url: String = routes.ApiDocumentationController.renderApiDocumentation(api.serviceName, defaultVersionNbr, useV2 = Some(true)).url + val url: String = routes.ApiDocumentationController.renderApiDocumentation(api.serviceName, defaultVersionNbr).url RestDocumentation.fromApiDefinition(api, url, defaultVersionNbr, getRestApiDescriptionOverride(api.serviceName.value)) } diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala index afd5ad83..1c6f99f3 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationController.scala @@ -97,11 +97,11 @@ class OpenApiDocumentationController @Inject() ( } yield (api, apiVersion, visibility) findVersion(apiOption) match { - case Some((api, selectedVersion, VersionVisibility(_, _, true, _))) if selectedVersion.status == ApiStatus.RETIRED => badRequestPage - case Some((api, selectedVersion, VersionVisibility(_, _, true, _))) => renderDocumentationPage(api.name) - case Some((api, selectedVersion, VersionVisibility(ApiAccessType.PRIVATE, _, false, true))) => renderDocumentationPage(api.name) // TODO - makes no sense for oas/page - case Some((_, _, VersionVisibility(ApiAccessType.PRIVATE, false, _, _))) => badRequestPage - case _ => renderNotFoundPage + case Some((_, selectedVersion, VersionVisibility(_, _, true, _))) if selectedVersion.status == ApiStatus.RETIRED => badRequestPage + case Some((api, _, VersionVisibility(_, _, true, _))) => renderDocumentationPage(api.name) + case Some((api, _, VersionVisibility(ApiAccessType.PRIVATE, _, false, true))) => renderDocumentationPage(api.name) // TODO - makes no sense for oas/page + case Some((_, _, VersionVisibility(ApiAccessType.PRIVATE, false, _, _))) => badRequestPage + case _ => renderNotFoundPage } } diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/RedirectController.scala b/app/uk/gov/hmrc/apidocumentation/controllers/RedirectController.scala index 051ae6c5..a1c914fb 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/RedirectController.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/RedirectController.scala @@ -28,20 +28,18 @@ import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController class RedirectController @Inject() (cc: MessagesControllerComponents) extends FrontendController(cc) { - def `redirectToDocumentationIndexPage`(useV2: Option[Boolean]): Action[AnyContent] = { + def `redirectToDocumentationIndexPage`(): Action[AnyContent] = { - val redirectTo = if (useV2.getOrElse(false)) { - uk.gov.hmrc.apidocumentation.v2.controllers.routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url - } else routes.ApiDocumentationController.apiIndexPage(None, None, None).url + val redirectTo = routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url Action.async { _ => Future.successful(MovedPermanently(redirectTo)) } } - def redirectToApiDocumentationPage(service: ServiceName, version: ApiVersionNbr, endpoint: String, useV2: Option[Boolean]): Action[AnyContent] = { + def redirectToApiDocumentationPage(service: ServiceName, version: ApiVersionNbr, endpoint: String): Action[AnyContent] = { val redirectTo = routes.ApiDocumentationController - .renderApiDocumentation(service, version, useV2) + .renderApiDocumentation(service, version) .url Action.async { _ => Future.successful(MovedPermanently(redirectTo)) diff --git a/app/uk/gov/hmrc/apidocumentation/controllers/binders/package.scala b/app/uk/gov/hmrc/apidocumentation/controllers/binders/package.scala index 7ed987c1..13cd0e58 100644 --- a/app/uk/gov/hmrc/apidocumentation/controllers/binders/package.scala +++ b/app/uk/gov/hmrc/apidocumentation/controllers/binders/package.scala @@ -21,7 +21,7 @@ import scala.util.{Failure, Success, Try} import play.api.mvc.{PathBindable, QueryStringBindable} import uk.gov.hmrc.apiplatform.modules.apis.domain.models.{ApiCategory, ServiceName} -import uk.gov.hmrc.apidocumentation.v2.models.DocumentationTypeFilter +import uk.gov.hmrc.apidocumentation.models.DocumentationTypeFilter package object binders { diff --git a/app/uk/gov/hmrc/apidocumentation/v2/models/ApiDocumentation.scala b/app/uk/gov/hmrc/apidocumentation/models/ApiDocumentation.scala similarity index 97% rename from app/uk/gov/hmrc/apidocumentation/v2/models/ApiDocumentation.scala rename to app/uk/gov/hmrc/apidocumentation/models/ApiDocumentation.scala index 5905f125..4f7cb7be 100644 --- a/app/uk/gov/hmrc/apidocumentation/v2/models/ApiDocumentation.scala +++ b/app/uk/gov/hmrc/apidocumentation/models/ApiDocumentation.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package uk.gov.hmrc.apidocumentation.v2.models +package uk.gov.hmrc.apidocumentation.models import scala.io.Source @@ -23,8 +23,6 @@ import uk.gov.hmrc.apiplatform.modules.apis.domain.models.{ApiCategory, ApiDefin import uk.gov.hmrc.apiplatform.modules.common.domain.models.ApiVersionNbr import uk.gov.hmrc.play.json.Union -import uk.gov.hmrc.apidocumentation.models.{DocumentationLabel, XmlApiDocumentation} - case class DocumentIdentifier(value: String) extends AnyVal object DocumentIdentifier { diff --git a/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala b/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala index c09acf0d..f03a8738 100644 --- a/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala +++ b/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala @@ -19,7 +19,6 @@ package uk.gov.hmrc.apidocumentation.models import scala.collection.immutable.ListMap import scala.io.Source -import play.api.Configuration import play.api.libs.json._ import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ @@ -69,7 +68,7 @@ case class XmlApiDocumentation(name: String, context: String, description: Strin val label: DocumentationLabel = DocumentationLabel.XML_API - def documentationUrl: String = routes.ApiDocumentationController.renderXmlApiDocumentation(name, None).url + def documentationUrl: String = routes.ApiDocumentationController.renderXmlApiDocumentation(name).url } object XmlApiDocumentation { @@ -107,21 +106,6 @@ object RoadMap { Json.parse(Source.fromInputStream(getClass.getResourceAsStream("/roadmap.json")).mkString).as[Seq[RoadMap]] } -case class APIAccess(`type`: ApiAccessType, whitelistedApplicationIds: Option[Seq[String]], isTrial: Option[Boolean] = None) - -object APIAccess { - - def apply(accessType: ApiAccessType): APIAccess = { - APIAccess(accessType, Some(Seq.empty), Some(false)) - } - - def build(config: Option[Configuration]): APIAccess = APIAccess( - `type` = ApiAccessType.PRIVATE, - whitelistedApplicationIds = config.flatMap(_.getOptional[Seq[String]]("whitelistedApplicationIds")).orElse(Some(Seq.empty)), - isTrial = None - ) -} - case class WrappedApiDefinition(definition: ApiDefinition) extends Documentation { override val name: String = definition.name override val context: String = definition.context.value @@ -133,24 +117,13 @@ case class WrappedApiDefinition(definition: ApiDefinition) extends Documentation .sorted(WrappedApiDefinition.statusVersionOrdering) .head - override def documentationUrl: String = routes.ApiDocumentationController.renderApiDocumentation(definition.serviceName, defaultVersion.versionNbr, None).url + override def documentationUrl: String = routes.ApiDocumentationController.renderApiDocumentation(definition.serviceName, defaultVersion.versionNbr).url } object WrappedApiDefinition { val statusVersionOrdering: Ordering[ApiVersion] = Ordering.by[ApiVersion, ApiStatus](_.status)(ApiStatus.orderingByPriority).reverse.orElseBy(_.versionNbr).reverse } -case class DocumentationCategory(apiCategory: ApiCategory) { - val filter = apiCategory.toString.toLowerCase.replaceAll("_", "-").replaceAll("vat-mtd", "vat") -} - -object DocumentationCategory { - - def fromFilter(filter: String): Option[ApiCategory] = { - ApiCategory.values.map(cat => DocumentationCategory(cat)).find(cat => cat.filter == filter).map(_.apiCategory) - } -} - case class VersionVisibility(privacy: ApiAccessType, loggedIn: Boolean, authorised: Boolean, isTrial: Boolean = false) object VersionVisibility { diff --git a/app/uk/gov/hmrc/apidocumentation/v2/models/DocumentationTypeFilter.scala b/app/uk/gov/hmrc/apidocumentation/models/DocumentationTypeFilter.scala similarity index 96% rename from app/uk/gov/hmrc/apidocumentation/v2/models/DocumentationTypeFilter.scala rename to app/uk/gov/hmrc/apidocumentation/models/DocumentationTypeFilter.scala index c250cf25..024c9e79 100644 --- a/app/uk/gov/hmrc/apidocumentation/v2/models/DocumentationTypeFilter.scala +++ b/app/uk/gov/hmrc/apidocumentation/models/DocumentationTypeFilter.scala @@ -14,14 +14,13 @@ * limitations under the License. */ -package uk.gov.hmrc.apidocumentation.v2.models +package uk.gov.hmrc.apidocumentation.models import scala.collection.immutable.ListSet import play.api.libs.json.Format import uk.gov.hmrc.apiplatform.modules.common.domain.services.SealedTraitJsonFormatting -import uk.gov.hmrc.apidocumentation.models.DocumentationLabel import uk.gov.hmrc.apidocumentation.models.DocumentationLabel._ sealed trait DocumentationTypeFilter { diff --git a/app/uk/gov/hmrc/apidocumentation/models/JsonSchema.scala b/app/uk/gov/hmrc/apidocumentation/models/JsonSchema.scala deleted file mode 100644 index 0418004f..00000000 --- a/app/uk/gov/hmrc/apidocumentation/models/JsonSchema.scala +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.apidocumentation.models - -import scala.collection.immutable.ListMap - -import play.api.libs.functional.syntax._ -import play.api.libs.json.Json.fromJson -import play.api.libs.json._ - -/* - * ListMap is used instead of Map so that when iterating the entries are returned in insertion order. This means - * that the documentation renders properties in the order defined in the schema rather than in a random order. - * This makes the documentation more usable. - */ -case class JsonSchema( - description: Option[String] = None, - id: Option[String] = None, - `type`: Option[String] = None, - example: Option[String] = None, - title: Option[String] = None, - properties: ListMap[String, JsonSchema] = ListMap(), // See above regarding use of ListMap - patternProperties: ListMap[String, JsonSchema] = ListMap(), // See above regarding use of ListMap - items: Option[JsonSchema] = None, - required: Seq[String] = Nil, - definitions: ListMap[String, JsonSchema] = ListMap(), // See above regarding use of ListMap - ref: Option[String] = None, - `enum`: Seq[EnumerationValue] = Nil, - oneOf: Seq[JsonSchema] = Nil, - pattern: Option[String] = None - ) - -object JsonSchema { - - case object JsonSchemaWithReference { - - def unapply(arg: JsonSchema): Boolean = arg match { - case JsonSchema(description, _, _, _, _, properties, patternProperties, items, _, definitions, ref, _, oneOf, _) => - val hasReference: PartialFunction[JsonSchema, Boolean] = { - case JsonSchemaWithReference() => true - case _ => false - } - - val doesPatternPropertiesHaveReference = patternProperties.exists(v => hasReference(v._2)) - - val doesDefinitionsHaveReference = definitions.exists(v => hasReference(v._2)) - - val doesPropertiesHaveReference = properties.exists(v => hasReference(v._2)) - - val doesItemsHaveReference = items.exists(hasReference) - - val doesOneofHaveReference = oneOf.exists(hasReference) - - val reference = ref.isDefined - - doesPropertiesHaveReference || - doesPatternPropertiesHaveReference || - doesItemsHaveReference || - reference || - doesOneofHaveReference || - doesDefinitionsHaveReference - } - - } - - implicit def listMapReads[V](implicit formatV: Reads[V]): Reads[ListMap[String, V]] = new Reads[ListMap[String, V]] { - - def reads(json: JsValue) = json match { - case JsObject(m) => - type Errors = scala.collection.Seq[(JsPath, scala.collection.Seq[JsonValidationError])] - - def locate(e: Errors, key: String) = e.map { case (path, validationError) => (JsPath \ key) ++ path -> validationError } - - m.foldLeft(Right(ListMap.empty): Either[Errors, ListMap[String, V]]) { - case (acc, (key, value)) => (acc, fromJson[V](value)(formatV)) match { - case (Right(vs), JsSuccess(v, _)) => Right(vs + (key -> v)) - case (Right(_), JsError(e)) => Left(locate(e, key)) - case (Left(e), _: JsSuccess[_]) => Left(e) - case (Left(e1), JsError(e2)) => Left(e1 ++ locate(e2, key)) - } - }.fold(JsError.apply, res => JsSuccess(res)) - - case _ => JsError(Seq(JsPath() -> Seq(JsonValidationError("error.expected.jsobject")))) - } - } - - implicit lazy val reads: Reads[JsonSchema] = ( - (__ \ "description").readNullable[String] and - (__ \ "id").readNullable[String] and - (__ \ "type").readNullable[String] and - (__ \ "example").readNullable[String] and - (__ \ "title").readNullable[String] and - (__ \ "properties").lazyReadNullable[ListMap[String, JsonSchema]](listMapReads[JsonSchema]).map(_.getOrElse(ListMap())) and - (__ \ "patternProperties").lazyReadNullable[ListMap[String, JsonSchema]](listMapReads[JsonSchema]).map(_.getOrElse(ListMap())) and - (__ \ "items").lazyReadNullable[JsonSchema](JsonSchema.reads) and - (__ \ "required").readNullable[Seq[String]].map(_.toSeq.flatten) and - (__ \ "definitions").lazyReadNullable[ListMap[String, JsonSchema]](listMapReads[JsonSchema]).map(_.getOrElse(ListMap())) and - (__ \ """$ref""").readNullable[String] and - (__ \ "enum").readNullable[Seq[EnumerationValue]].map(_.toSeq.flatten) and - (__ \ "oneOf").lazyReadNullable[Seq[JsonSchema]](Reads.seq[JsonSchema]).map(_.toSeq.flatten) and - (__ \ "pattern").readNullable[String] - )(JsonSchema.apply _) -} diff --git a/app/uk/gov/hmrc/apidocumentation/models/NavLink.scala b/app/uk/gov/hmrc/apidocumentation/models/NavLink.scala index 6266a0fb..bc74c7e8 100644 --- a/app/uk/gov/hmrc/apidocumentation/models/NavLink.scala +++ b/app/uk/gov/hmrc/apidocumentation/models/NavLink.scala @@ -44,7 +44,8 @@ case object StaticNavLinks { def apply() = { Seq( - NavLink("Documentation", "/api-documentation/docs/using-the-hub"), + NavLink("Getting Started", "/api-documentation/docs/using-the-hub"), + NavLink("API documentation", "/api-documentation/docs/api"), NavLink("Applications", "/developer/applications"), NavLink("Support", "/developer/support"), NavLink("Service Availability", "https://api-platform-status.production.tax.service.gov.uk/", openInNewWindow = true) diff --git a/app/uk/gov/hmrc/apidocumentation/models/package.scala b/app/uk/gov/hmrc/apidocumentation/models/package.scala index d1c091a4..90ac7e48 100644 --- a/app/uk/gov/hmrc/apidocumentation/models/package.scala +++ b/app/uk/gov/hmrc/apidocumentation/models/package.scala @@ -19,7 +19,6 @@ package uk.gov.hmrc.apidocumentation.models import play.api.libs.json._ package object jsonFormatters { - implicit val formatAPIAccess: OFormat[APIAccess] = Json.format[APIAccess] implicit val formatVersionVisibility: OFormat[VersionVisibility] = Json.format[VersionVisibility] implicit val formatServiceDetails: OFormat[ServiceDetails] = Json.format[ServiceDetails] implicit val formatTestEndpoint: OFormat[TestEndpoint] = Json.format[TestEndpoint] diff --git a/app/uk/gov/hmrc/apidocumentation/services/NavigationService.scala b/app/uk/gov/hmrc/apidocumentation/services/NavigationService.scala index d868e4ab..7e548522 100644 --- a/app/uk/gov/hmrc/apidocumentation/services/NavigationService.scala +++ b/app/uk/gov/hmrc/apidocumentation/services/NavigationService.scala @@ -38,7 +38,7 @@ class NavigationService @Inject() ( routes.DocumentationController.usingTheHubPage().url lazy val apiDocumentationUrl = - routes.ApiDocumentationController.apiIndexPage(None, None, None).url + routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url lazy val referenceGuideUrl = routes.DocumentationController.referenceGuidePage().url diff --git a/app/uk/gov/hmrc/apidocumentation/v2/views/documentFilter.scala.html b/app/uk/gov/hmrc/apidocumentation/v2/views/documentFilter.scala.html deleted file mode 100644 index 47f5198f..00000000 --- a/app/uk/gov/hmrc/apidocumentation/v2/views/documentFilter.scala.html +++ /dev/null @@ -1,68 +0,0 @@ -@* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *@ - -@import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory -@import uk.gov.hmrc.apidocumentation.v2.controllers -@import uk.gov.hmrc.apidocumentation.v2.models.DocumentationTypeFilter - -@(docTypeFilters: List[DocumentationTypeFilter], categoryFilters: List[ApiCategory]) - -

Filters

-
-
-
- - Documentation Type - -
- -
- - @for((x, index) <- DocumentationTypeFilter.values.zipWithIndex){ -
- - -
- } - -
-
- -
-
- - API Category - -
-
- @for((category, index) <- ApiCategory.values.toList.sortBy(_.displayText).zipWithIndex) { -
- - -
- - } -
-
- - -
- - diff --git a/app/uk/gov/hmrc/apidocumentation/views/ApiIndexView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/ApiIndexView.scala.html deleted file mode 100644 index 21fd9055..00000000 --- a/app/uk/gov/hmrc/apidocumentation/views/ApiIndexView.scala.html +++ /dev/null @@ -1,35 +0,0 @@ -@* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *@ - -@import uk.gov.hmrc.apidocumentation.config._ -@import uk.gov.hmrc.apidocumentation.models._ -@import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ - -@import uk.gov.hmrc.apidocumentation.views.html.include._ - -@this(apiMain: apiMain) - -@(pageAttributes: PageAttributes, documentsByCategory: Map[ApiCategory, Seq[Documentation]])(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) - -@apiMain(pageAttributes) { - -

API documentation

- -

View documentation for our RESTful and XML APIs here on the Developer Hub.

- - @documentFilter(documentsByCategory.keys.toList.sorted) - @documentGroups(documentsByCategory) -} diff --git a/app/uk/gov/hmrc/apidocumentation/views/ApisFilteredView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/ApisFilteredView.scala.html deleted file mode 100644 index 3db3da3c..00000000 --- a/app/uk/gov/hmrc/apidocumentation/views/ApisFilteredView.scala.html +++ /dev/null @@ -1,44 +0,0 @@ -@* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *@ - -@import uk.gov.hmrc.apidocumentation.config._ -@import uk.gov.hmrc.apidocumentation.controllers -@import uk.gov.hmrc.apidocumentation.models._ -@import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ -@import uk.gov.hmrc.apidocumentation.views.html.include._ - -@this(apiMain: apiMain) - -@(pageAttributes: PageAttributes, documentsByCategory: Map[ApiCategory, Seq[Documentation]], filter: Option[ApiCategory])(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) - -@apiMain(pageAttributes) { - -

Filtered API documentation

- - View the full API list - - @documentFilter(documentsByCategory.keys.toList, filter) - - @filter.map { f => - @defining(documentsByCategory.view.filterKeys(DocumentationCategory(_).filter == DocumentationCategory(f).filter).toMap) { filteredDocuments => - @defining(filteredDocuments.values.toSeq.flatten.length) { numDocuments => -

@numDocuments document@if(numDocuments != 1){s} found in @f.displayText

- - @documentGroups(filteredDocuments) - } - } - } -} diff --git a/app/uk/gov/hmrc/apidocumentation/views/AuthorisationAppRestrictedEndpointsView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/AuthorisationAppRestrictedEndpointsView.scala.html index 5f2face5..f6d2065b 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/AuthorisationAppRestrictedEndpointsView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/AuthorisationAppRestrictedEndpointsView.scala.html @@ -56,7 +56,7 @@

Application-restricted endpoints

If the endpoint requires a scope, your application must include this scope when creating the access token.

-

Read the API documentation for authorisation rules for specific API endpoints.

+

Read the API documentation for authorisation rules for specific API endpoints.

The access token lasts for 4 hours. When it expires you must generate a new token. diff --git a/app/uk/gov/hmrc/apidocumentation/views/AuthorisationUserRestrictedEndpointsView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/AuthorisationUserRestrictedEndpointsView.scala.html index 191c416c..0b1cf70a 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/AuthorisationUserRestrictedEndpointsView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/AuthorisationUserRestrictedEndpointsView.scala.html @@ -60,7 +60,7 @@

User-restricted endpoints

There are separate HMRC sign in details for individuals, agents and organisations. For individuals and organisations, the access token only gives access to the end user’s own data. For agents the access token gives access to their clients’ data.

-

Authorisation rules for specific API endpoints are given in the API documentation.

+

Authorisation rules for specific API endpoints are given in the API documentation.

The access token lasts for 4 hours. When it expires, it can be refreshed using a single-use refresh token. After 18 months you can no longer refresh the access token and the end user must grant authority again.

diff --git a/app/uk/gov/hmrc/apidocumentation/views/IndexView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/IndexView.scala.html index 5112c25d..cae2e334 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/IndexView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/IndexView.scala.html @@ -47,7 +47,7 @@

Create tax software and apps using HMRC APIs

- Explore our APIs, review documentation and check endpoints. + Explore our APIs, review documentation and check endpoints.

@if(!loggedIn) {

@@ -82,7 +82,7 @@

Get started

Explore APIs

    -
  • API documentation
  • +
  • API documentation
  • XML APIs
  • Reference guide
  • Development practices
  • diff --git a/app/uk/gov/hmrc/apidocumentation/views/MtdIntroductionView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/MtdIntroductionView.scala.html index dfadebda..8116269c 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/MtdIntroductionView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/MtdIntroductionView.scala.html @@ -19,6 +19,8 @@ @import uk.gov.hmrc.apidocumentation.controllers @import uk.gov.hmrc.apidocumentation.views.html.include._ @import uk.gov.hmrc.apidocumentation.views.html.include.apiMain +@import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory.VAT_MTD +@import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory.INCOME_TAX_MTD @this(apiMain: apiMain) @@ -28,7 +30,7 @@

    Making Tax Digital guides

    - These guides have now moved to our API documentation. + These guides have now moved to our API documentation.

    @@ -40,7 +42,7 @@

    - VAT (MTD) API documentation + VAT (MTD) API documentation

    @@ -52,6 +54,6 @@

    - Income Tax (MTD) API documentation + Income Tax (MTD) API documentation

    } diff --git a/app/uk/gov/hmrc/apidocumentation/views/ReferenceView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/ReferenceView.scala.html index 30c7e075..5d79105d 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/ReferenceView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/ReferenceView.scala.html @@ -592,7 +592,7 @@

    Scopes

    These are translated to human-readable descriptions that are shown to the user before they grant authority. This makes sure the user understands and gives access to your application.

    -

    The scope for each user-restricted endpoint is defined in the API documentation.

    +

    The scope for each user-restricted endpoint is defined in the API documentation.

    For details about OAuth 2.0 and scopes, see authorisation.

    diff --git a/app/uk/gov/hmrc/apidocumentation/views/RetiredVersionJumpView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/RetiredVersionJumpView.scala.html index a69c260c..b4e0b773 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/RetiredVersionJumpView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/RetiredVersionJumpView.scala.html @@ -24,7 +24,7 @@ @this(apiMain: apiMain) -@(pageAttributes: PageAttributes, api: ExtendedApiDefinition, useV2: Option[Boolean])(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) +@(pageAttributes: PageAttributes, api: ExtendedApiDefinition)(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) @apiMain(pageAttributes) {
    @@ -40,7 +40,7 @@

    @(api.name) API

    This version of the {api.name} API has been retired and is no longer supported. Please update to - + version {defaultVersion.version} ({defaultVersion.displayedStatus}).

    } diff --git a/app/uk/gov/hmrc/apidocumentation/views/TestUsersDataStatefulBehaviourView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/TestUsersDataStatefulBehaviourView.scala.html index fb04f2ee..978e8eda 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/TestUsersDataStatefulBehaviourView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/TestUsersDataStatefulBehaviourView.scala.html @@ -72,7 +72,7 @@

    Other test data

    requests and then read back that same data through retrieval (GET) requests.

    Some stateful APIs have an accompanying test support API for setting up test data, which you can find on our - API documentation page. + API documentation page. For example, the Individual Tax API only supports retrieval (GET) requests so the accompanying Individual PAYE Test Support API can create (POST) test data for it.

    diff --git a/app/uk/gov/hmrc/apidocumentation/views/TutorialsView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/TutorialsView.scala.html index 3469a73d..2e419eae 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/TutorialsView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/TutorialsView.scala.html @@ -361,7 +361,7 @@

    4. Refresh an expired OAuth 2.0 You should now be ready to start integrating with - our APIs. + our APIs.

    } diff --git a/app/uk/gov/hmrc/apidocumentation/v2/views/FilteredIndexView.scala.html b/app/uk/gov/hmrc/apidocumentation/views/documentationList/FilteredIndexView.scala.html similarity index 86% rename from app/uk/gov/hmrc/apidocumentation/v2/views/FilteredIndexView.scala.html rename to app/uk/gov/hmrc/apidocumentation/views/documentationList/FilteredIndexView.scala.html index 308b4576..2552c8b2 100644 --- a/app/uk/gov/hmrc/apidocumentation/v2/views/FilteredIndexView.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/documentationList/FilteredIndexView.scala.html @@ -16,20 +16,17 @@ @import uk.gov.hmrc.apidocumentation.config._ @import uk.gov.hmrc.apidocumentation.models._ -@import uk.gov.hmrc.apidocumentation.v2.models._ @import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ -@import uk.gov.hmrc.apidocumentation.views.html._ -@import uk.gov.hmrc.apidocumentation.v2.views.html._ -@import uk.gov.hmrc.apidocumentation.views.html.include._ +@import uk.gov.hmrc.apidocumentation.views.html.documentationList._ -@this(apiMainV2: apiMainV2) +@this(apiMain: apiMain) @(pageAttributes: PageAttributes, documents: Seq[ApiDocumentation], docTypeFilters: List[DocumentationTypeFilter], categoryFilters: List[ApiCategory])(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) -@apiMainV2(pageAttributes, docTypeFilters, categoryFilters) { +@apiMain(pageAttributes, docTypeFilters, categoryFilters) { diff --git a/app/uk/gov/hmrc/apidocumentation/v2/views/apiMainV2.scala.html b/app/uk/gov/hmrc/apidocumentation/views/documentationList/apiMain.scala.html similarity index 80% rename from app/uk/gov/hmrc/apidocumentation/v2/views/apiMainV2.scala.html rename to app/uk/gov/hmrc/apidocumentation/views/documentationList/apiMain.scala.html index 8986fd0c..dedf56b5 100644 --- a/app/uk/gov/hmrc/apidocumentation/v2/views/apiMainV2.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/documentationList/apiMain.scala.html @@ -17,17 +17,17 @@ @import uk.gov.hmrc.apidocumentation.config._ @import uk.gov.hmrc.apidocumentation.models._ @import uk.gov.hmrc.apidocumentation.views.html.templates._ -@import uk.gov.hmrc.apidocumentation.v2.views.html.documentFilter -@import play.twirl.api.HtmlFormat -@import uk.gov.hmrc.apidocumentation.v2.models.DocumentationTypeFilter +@import uk.gov.hmrc.apidocumentation.views.html.documentationList.documentFilter +@import uk.gov.hmrc.apidocumentation.models.DocumentationTypeFilter @import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory +@import uk.gov.hmrc.govukfrontend.views.html.components.GovukCheckboxes -@this(govUkWrapper: GovUkWrapper) +@this(govUkWrapper: GovUkWrapper, govukCheckboxes: GovukCheckboxes) @(pageAttributes: PageAttributes, docTypeFilters: List[DocumentationTypeFilter], categoryFilters: List[ApiCategory])(mainContent: Html)(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) @govUkWrapper(pageTitle = Some(pageAttributes.title), - leftNav = Some(documentFilter(docTypeFilters, categoryFilters.sorted)), + leftNav = Some(documentFilter(docTypeFilters, categoryFilters.sorted, govukCheckboxes)), isLeftNavSticky = false, breadcrumbs = Some(pageAttributes.breadcrumbs), navLinks = pageAttributes.headerLinks diff --git a/app/uk/gov/hmrc/apidocumentation/views/documentationList/documentFilter.scala.html b/app/uk/gov/hmrc/apidocumentation/views/documentationList/documentFilter.scala.html new file mode 100644 index 00000000..e224b232 --- /dev/null +++ b/app/uk/gov/hmrc/apidocumentation/views/documentationList/documentFilter.scala.html @@ -0,0 +1,53 @@ +@* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@import uk.gov.hmrc.apidocumentation.controllers +@import uk.gov.hmrc.apidocumentation.models.DocumentationTypeFilter +@import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory +@import uk.gov.hmrc.govukfrontend.views.html.components._ +@import uk.gov.hmrc.govukfrontend.views.viewmodels.checkboxes.Checkboxes +@import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.{Fieldset, Legend} + +@(docTypeFilters: List[DocumentationTypeFilter], categoryFilters: List[ApiCategory], govukCheckboxes: GovukCheckboxes) + +

    Filters

    + +
    + @govukCheckboxes( + Checkboxes( + name = "docTypeFilters", + fieldset = Some(Fieldset(legend = Some(Legend(content = Text("Documentation Type"), classes="govuk-fieldset__legend--s")))), + classes="govuk-checkboxes--small", + items = DocumentationTypeFilter.values.map(filter => + CheckboxItem(content = HtmlContent(s"${filter.displayName}"), value = filter.toString, checked = docTypeFilters.contains(filter))).toSeq + ) + ) + + @govukCheckboxes( + Checkboxes( + name = "categoryFilters", + fieldset = Some(Fieldset(legend = Some(Legend(content = Text("API Category"), classes="govuk-fieldset__legend--s")))), + classes="govuk-checkboxes--small", + items = ApiCategory.values.toList.sortBy(_.displayText).map(category => + CheckboxItem(content = HtmlContent(s"${category.displayText}"), value = category.toString, checked = categoryFilters.contains(category))) + ) + ) + + + +
    + + diff --git a/app/uk/gov/hmrc/apidocumentation/views/include/documentFilter.scala.html b/app/uk/gov/hmrc/apidocumentation/views/include/documentFilter.scala.html deleted file mode 100644 index 0c4c300e..00000000 --- a/app/uk/gov/hmrc/apidocumentation/views/include/documentFilter.scala.html +++ /dev/null @@ -1,37 +0,0 @@ -@* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *@ - -@import uk.gov.hmrc.apidocumentation.models._ -@import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ - -@(categories: List[ApiCategory], filter: Option[ApiCategory] = None) - -
    -
    -
    - - -
    -
    - -
    -
    -
    diff --git a/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html b/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html deleted file mode 100644 index 6d7d6110..00000000 --- a/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html +++ /dev/null @@ -1,47 +0,0 @@ -@* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *@ - -@import uk.gov.hmrc.apidocumentation.models._ -@import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ -@import uk.gov.hmrc.apidocumentation.models.Documentation - -@(documentsByCategory: Map[ApiCategory, Seq[Documentation]]) - - - - - - - - - - - @for((category, documents) <- documentsByCategory) { - - @for((document, index) <- documents.sortBy(_.label).zipWithIndex) { - - @if(index == 0) { } else { } - - - - } - - } -
    Full list of API documentation
    ServiceAPI documentationDocumentation type
    @category.displayText - @document.name - - @document.label.displayName -
    diff --git a/app/uk/gov/hmrc/apidocumentation/views/openapispec/ParentPageOuter.scala.html b/app/uk/gov/hmrc/apidocumentation/views/openapispec/ParentPageOuter.scala.html index 65325149..08bc6fe7 100644 --- a/app/uk/gov/hmrc/apidocumentation/views/openapispec/ParentPageOuter.scala.html +++ b/app/uk/gov/hmrc/apidocumentation/views/openapispec/ParentPageOuter.scala.html @@ -26,18 +26,18 @@ @this(apiMain: apiMain, parentPageView: ParentPageView) -@(pageAttributes: PageAttributes, markdownBlocks: List[DocumentationItem], title: String, api: ExtendedApiDefinition, currentVersion: ExtendedApiVersion, loggedIn: Boolean = false, deprecationMessage: Option[String] = None, useV2: Option[Boolean])(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) +@(pageAttributes: PageAttributes, markdownBlocks: List[DocumentationItem], title: String, api: ExtendedApiDefinition, currentVersion: ExtendedApiVersion, loggedIn: Boolean = false, deprecationMessage: Option[String] = None)(implicit applicationConfig: ApplicationConfig, request: Request[AnyContent], messagesProvider: MessagesProvider) @topContent = {
    diff --git a/build.sbt b/build.sbt index 47efa02b..bd2bf0d5 100644 --- a/build.sbt +++ b/build.sbt @@ -49,7 +49,7 @@ lazy val microservice = Project(appName, file(".")) "uk.gov.hmrc.apidocumentation.controllers.binders._", "uk.gov.hmrc.apiplatform.modules.apis.domain.models._", "uk.gov.hmrc.apiplatform.modules.common.domain.models._", - "uk.gov.hmrc.apidocumentation.v2.models._" + "uk.gov.hmrc.apidocumentation.models._" ) ) .settings(Compile / unmanagedResourceDirectories += baseDirectory.value / "resources") diff --git a/conf/app.routes b/conf/app.routes index a9190a0e..31734df5 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -21,10 +21,10 @@ GET /docs/authorisation/user-restricted-endpoints uk.gov.h GET /docs/authorisation/two-step-verification uk.gov.hmrc.apidocumentation.controllers.AuthorisationController.authorisation2SVPage() -GET /docs/api uk.gov.hmrc.apidocumentation.controllers.ApiDocumentationController.apiIndexPage(service: Option[ServiceName], version: Option[ApiVersionNbr], filter: Option[String]) +GET /docs/api uk.gov.hmrc.apidocumentation.controllers.FilteredDocumentationIndexController.apiListIndexPage(docTypeFilters: List[uk.gov.hmrc.apidocumentation.models.DocumentationTypeFilter], categoryFilters: List[uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory]) GET /docs/api/service/:service uk.gov.hmrc.apidocumentation.controllers.ApiDocumentationController.redirectToApiDocumentation(service: ServiceName, version: Option[ApiVersionNbr]) -GET /docs/api/service/:service/:version uk.gov.hmrc.apidocumentation.controllers.ApiDocumentationController.renderApiDocumentation(service: ServiceName,version: ApiVersionNbr, useV2: Option[Boolean]) +GET /docs/api/service/:service/:version uk.gov.hmrc.apidocumentation.controllers.ApiDocumentationController.renderApiDocumentation(service: ServiceName,version: ApiVersionNbr) # Open API related endpoints GET /docs/api/service/:service/:version/oas/page uk.gov.hmrc.apidocumentation.controllers.OpenApiDocumentationController.renderApiDocumentation(service: ServiceName,version: ApiVersionNbr) @@ -32,12 +32,12 @@ GET /docs/openapi/preview uk.gov.h GET /docs/openapi/preview/action uk.gov.hmrc.apidocumentation.controllers.OpenApiDocumentationController.previewApiDocumentationAction(url: Option[String]) GET /docs/api/service/:service/:version/oas/file uk.gov.hmrc.apidocumentation.controllers.OpenApiDocumentationController.fetchOas(service: ServiceName, version: ApiVersionNbr) GET /docs/api/service/:service/:version/oas/resolved uk.gov.hmrc.apidocumentation.controllers.OpenApiDocumentationController.fetchOasResolved(service: ServiceName,version: ApiVersionNbr) -GET /docs/api/service/:service/:version/oas/*resource uk.gov.hmrc.apidocumentation.controllers.DownloadController.downloadResource(service: ServiceName, version: ApiVersionNbr, resource: String, useV2: Option[Boolean]) +GET /docs/api/service/:service/:version/oas/*resource uk.gov.hmrc.apidocumentation.controllers.DownloadController.downloadResource(service: ServiceName, version: ApiVersionNbr, resource: String) -GET /docs/api/xml/:name uk.gov.hmrc.apidocumentation.controllers.ApiDocumentationController.renderXmlApiDocumentation(name: String, useV2: Option[Boolean]) +GET /docs/api/xml/:name uk.gov.hmrc.apidocumentation.controllers.ApiDocumentationController.renderXmlApiDocumentation(name: String) -GET /docs/apiIndex uk.gov.hmrc.apidocumentation.controllers.RedirectController.redirectToDocumentationIndexPage(useV2: Option[Boolean]) -GET /docs/api/:service/:version/:endpoint uk.gov.hmrc.apidocumentation.controllers.RedirectController.redirectToApiDocumentationPage(service: ServiceName,version: ApiVersionNbr, endpoint: String, useV2: Option[Boolean]) +GET /docs/apiIndex uk.gov.hmrc.apidocumentation.controllers.RedirectController.redirectToDocumentationIndexPage() +GET /docs/api/:service/:version/:endpoint uk.gov.hmrc.apidocumentation.controllers.RedirectController.redirectToApiDocumentationPage(service: ServiceName,version: ApiVersionNbr, endpoint: String) GET /docs/fraud-prevention uk.gov.hmrc.apidocumentation.controllers.RedirectController.redirectToFraudPreventionGuide() GET /docs/api/mtd-income-tax-service-guide uk.gov.hmrc.apidocumentation.controllers.DocumentationController.mtdIncomeTaxServiceGuidePage() @@ -51,10 +51,8 @@ GET /docs/testing uk.gov.h GET /docs/testing/stateful-behaviour uk.gov.hmrc.apidocumentation.controllers.TestingPagesController.testingStatefulBehaviourPage() GET /docs/testing/test-users-test-data-stateful-behaviour uk.gov.hmrc.apidocumentation.controllers.TestingPagesController.testUsersDataStatefulBehaviourPage() -GET /docs/api/download/:service/:version/*resource uk.gov.hmrc.apidocumentation.controllers.DownloadController.downloadResource(service: ServiceName,version: ApiVersionNbr, resource: String, useV2: Option[Boolean]) +GET /docs/api/download/:service/:version/*resource uk.gov.hmrc.apidocumentation.controllers.DownloadController.downloadResource(service: ServiceName,version: ApiVersionNbr, resource: String) GET /assets/*file @controllers.Assets.versioned(path="/public", file: Asset) -GET /docs/v2 uk.gov.hmrc.apidocumentation.v2.controllers.FilteredDocumentationIndexController.apiListIndexPage(docTypeFilters: List[uk.gov.hmrc.apidocumentation.v2.models.DocumentationTypeFilter], categoryFilters: List[uk.gov.hmrc.apiplatform.modules.apis.domain.models.ApiCategory]) - -> /hmrc-frontend hmrcfrontend.Routes \ No newline at end of file diff --git a/project/ScoverageSettings.scala b/project/ScoverageSettings.scala index 3afdedd1..2732bb34 100644 --- a/project/ScoverageSettings.scala +++ b/project/ScoverageSettings.scala @@ -2,7 +2,7 @@ import scoverage.ScoverageKeys._ object ScoverageSettings { def apply() = Seq( - coverageMinimumStmtTotal := 74.00, // TO BE RETURNED TO 80 - when ReDoc is no longer a POC - OVERDUE + coverageMinimumStmtTotal := 77.00, // TO BE RETURNED TO 80 - when ReDoc is no longer a POC - OVERDUE coverageFailOnMinimum := true, coverageHighlighting := true, coverageExcludedPackages := List( diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationControllerSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationControllerSpec.scala index bb3c3599..ac5bc09c 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationControllerSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/ApiDocumentationControllerSpec.scala @@ -28,9 +28,9 @@ import uk.gov.hmrc.apiplatform.modules.common.domain.models._ import uk.gov.hmrc.http.NotFoundException import uk.gov.hmrc.apidocumentation.ErrorHandler -import uk.gov.hmrc.apidocumentation.connectors.DownloadConnector import uk.gov.hmrc.apidocumentation.controllers.utils._ import uk.gov.hmrc.apidocumentation.mocks.config._ +import uk.gov.hmrc.apidocumentation.mocks.connectors.DownloadConnectorMockModule import uk.gov.hmrc.apidocumentation.mocks.services._ import uk.gov.hmrc.apidocumentation.views.html._ import uk.gov.hmrc.apidocumentation.views.html.openapispec.ParentPageOuter @@ -45,18 +45,16 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR with ApiDefinitionServiceMock with LoggedInUserServiceMock with NavigationServiceMock - with XmlServicesServiceMock { + with XmlServicesServiceMock + with DownloadConnectorMockModule { val errorHandler = app.injector.instanceOf[ErrorHandler] val mcc = app.injector.instanceOf[MessagesControllerComponents] - private lazy val apiIndexView = app.injector.instanceOf[ApiIndexView] private lazy val retiredVersionJumpView = app.injector.instanceOf[RetiredVersionJumpView] - private lazy val apisFilteredView = app.injector.instanceOf[ApisFilteredView] private lazy val xmlDocumentationView = app.injector.instanceOf[XmlDocumentationView] private lazy val parentPage = app.injector.instanceOf[ParentPageOuter] private lazy val assets = app.injector.instanceOf[Assets] - val downloadConnector = mock[DownloadConnector] private implicit val materializer: Materializer = app.injector.instanceOf[Materializer] val definitionList: List[ApiDefinition] = List(apiDefinition("service1"), apiDefinition("service2")) @@ -66,58 +64,16 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR loggedInUserService, errorHandler, mcc, - apiIndexView, retiredVersionJumpView, - apisFilteredView, xmlDocumentationView, parentPage, xmlServicesService, - downloadConnector, + DownloadConnectorMock.aMock, assets ) } "ApiDocumentationController" when { - "routing to the apiIndexPage" should { - "render the API List" in new Setup { - theUserIsLoggedIn() - theDefinitionServiceWillReturnApiDefinitions(definitionList) - fetchAllXmlApisReturnsApis() - - val result = underTest.apiIndexPage(None, None, None)(request) - verifyPageRendered(pageTitle("API Documentation"), bodyContains = Seq("API documentation"))(result) - } - - "render the filtered API list" in new Setup { - theUserIsLoggedIn() - theDefinitionServiceWillReturnApiDefinitions(definitionList) - fetchAllXmlApisReturnsVatApi() - - val result = underTest.apiIndexPage(None, None, Some("vat"))(request) - - verifyPageRendered(pageTitle("Filtered API Documentation"), bodyContains = Seq("Filtered API documentation", "1 document found in", "VAT"))(result) - } - - "display the error page when the documentationService throws an exception" in new Setup { - theUserIsLoggedIn() - theDefinitionServiceWillFail(new Exception("Expected unit test failure")) - - val result = underTest.apiIndexPage(None, None, None)(request) - - verifyErrorPageRendered(INTERNAL_SERVER_ERROR, "Sorry, there is a problem with the service")(result) - } - - "display the error page when the xmlServicesService throws an exception" in new Setup { - theUserIsLoggedIn() - theDefinitionServiceWillReturnApiDefinitions(definitionList) - fetchAllXmlApisFails(new Exception("Expected unit test failure")) - - val result = underTest.apiIndexPage(None, None, None)(request) - - verifyErrorPageRendered(INTERNAL_SERVER_ERROR, "Sorry, there is a problem with the service")(result) - } - } - "redirecting to Api Documentation" must { "when given a version" should { val version = ApiVersionNbr("2.0") @@ -222,7 +178,7 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR theUserIsLoggedIn() theDefinitionServiceWillFail(new NotFoundException("Expected unit test failure")) - val result = underTest.renderApiDocumentation(serviceName, versionOne, None)(request) + val result = underTest.renderApiDocumentation(serviceName, versionOne)(request) verifyNotFoundPageRendered(result) } @@ -233,19 +189,37 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR extendedApiDefinitionWithRetiredVersion(serviceName, versionOne, ApiVersionNbr("1.1")) ) - val result = underTest.renderApiDocumentation(serviceName, versionOne, None)(request) + val result = underTest.renderApiDocumentation(serviceName, versionOne)(request) verifyApiDocumentationPageRendered(result) verifyLinkToStableDocumentationRendered(result, serviceName, ApiVersionNbr("1.1")) } + "display the API landing page private trial and private" in new Setup { + theUserIsLoggedIn() + theDefinitionServiceWillReturnAnApiDefinition( + extendedApiDefinitionWithPrincipalAndSubordinateAPIAvailability( + serviceName, + versionOne, + Some(ApiAvailability(true, ApiAccess.Private(true), true, true)), + Some(ApiAvailability(true, ApiAccess.Private(false), true, true)) + ) + ) + DownloadConnectorMock.Fetch.returnsNoneIfNotFound() + + val result = underTest.renderApiDocumentation(serviceName, versionOne)(request) + + verifyApiDocumentationPageRendered(result) + verifyPageRendered(pageTitle("Hello World"), bodyContains = Seq("Yes - private trial"))(result) + } + "display the not found page when invalid version specified" in new Setup { theUserIsLoggedIn() theDefinitionServiceWillReturnAnApiDefinition( extendedApiDefinitionWithRetiredVersion(serviceName, versionOne, ApiVersionNbr("1.1")) ) - val result = underTest.renderApiDocumentation(serviceName, versionTwo, None)(request) + val result = underTest.renderApiDocumentation(serviceName, versionTwo)(request) verifyNotFoundPageRendered(result) } @@ -254,7 +228,7 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR theUserIsLoggedIn() theDefinitionServiceWillReturnNoApiDefinition() - val result = underTest.renderApiDocumentation(serviceName, versionOne, None)(request) + val result = underTest.renderApiDocumentation(serviceName, versionOne)(request) verifyNotFoundPageRendered(result) } @@ -268,7 +242,7 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR fetchXmlApiReturnsApi() val existingXmlApiName = xmlApi1.name - val result = underTest.renderXmlApiDocumentation(existingXmlApiName, None)(request) + val result = underTest.renderXmlApiDocumentation(existingXmlApiName)(request) verifyPageRendered(pageTitle(existingXmlApiName), bodyContains = Seq(existingXmlApiName))(result) } @@ -278,7 +252,7 @@ class ApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageR fetchXmlApiReturnsNone() val nonExistingXmlApiName = "Fake XML API name" - val result = underTest.renderXmlApiDocumentation(nonExistingXmlApiName, None)(request) + val result = underTest.renderXmlApiDocumentation(nonExistingXmlApiName)(request) status(result) shouldBe NOT_FOUND } diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/CommonControllerBaseSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/CommonControllerBaseSpec.scala index 8bcd3215..5c9d1cf9 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/CommonControllerBaseSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/CommonControllerBaseSpec.scala @@ -38,7 +38,11 @@ class CommonControllerBaseSpec extends AsyncHmrcSpec with ApiDefinitionTestDataH override def fakeApplication(): Application = GuiceApplicationBuilder() - .configure(("metrics.jvm", false)) + .configure( + "metrics.jvm" -> false, + "features.showProductionAvailability" -> true, + "features.showSandboxAvailability" -> true + ) .build() implicit lazy val request: Request[AnyContent] = FakeRequest() diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/DocumentationControllerSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/DocumentationControllerSpec.scala index 6843dad8..827d52a7 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/DocumentationControllerSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/DocumentationControllerSpec.scala @@ -54,17 +54,11 @@ class DocumentationControllerSpec private lazy val indexView = app.injector.instanceOf[IndexView] - private lazy val retiredVersionJumpView = - app.injector.instanceOf[RetiredVersionJumpView] - private lazy val tutorialsView = app.injector.instanceOf[TutorialsView] - private lazy val credentialsView = app.injector.instanceOf[CredentialsView] + private lazy val tutorialsView = app.injector.instanceOf[TutorialsView] private lazy val developmentPracticesView = app.injector.instanceOf[DevelopmentPracticesView] - private lazy val mtdIntroductionView = - app.injector.instanceOf[MtdIntroductionView] - private lazy val namingGuidelinesView = app.injector.instanceOf[NamingGuidelinesView] private lazy val referenceView = app.injector.instanceOf[ReferenceView] @@ -85,11 +79,8 @@ class DocumentationControllerSpec partialsService, mcc, indexView, - retiredVersionJumpView, tutorialsView, - credentialsView, developmentPracticesView, - mtdIntroductionView, namingGuidelinesView, referenceView, termsOfUseView, diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/DownloadControllerSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/DownloadControllerSpec.scala index 9aa80367..8391c4a8 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/DownloadControllerSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/DownloadControllerSpec.scala @@ -59,7 +59,7 @@ class DownloadControllerSpec extends CommonControllerBaseSpec { ) theDownloadConnectorWillReturnTheResult(Results.Ok) - await(underTest.downloadResource(serviceName, version, resourceName, None)(request)).header.status shouldBe OK + await(underTest.downloadResource(serviceName, version, resourceName)(request)).header.status shouldBe OK } "return 404 code when the resource not found" in new Setup { @@ -68,7 +68,7 @@ class DownloadControllerSpec extends CommonControllerBaseSpec { ) theDownloadConnectorWillReturnTheResult(Results.NotFound) - await(underTest.downloadResource(serviceName, version, resourceName, None)(request)).header.status shouldBe NOT_FOUND + await(underTest.downloadResource(serviceName, version, resourceName)(request)).header.status shouldBe NOT_FOUND } "error when the resource name contains '..'" in new Setup { @@ -76,7 +76,7 @@ class DownloadControllerSpec extends CommonControllerBaseSpec { extendedApiDefinition(serviceName = serviceName.value, version = version) ) - await(underTest.downloadResource(serviceName, version, "../secret", None)(request)).header.status shouldBe INTERNAL_SERVER_ERROR + await(underTest.downloadResource(serviceName, version, "../secret")(request)).header.status shouldBe INTERNAL_SERVER_ERROR } "redirect to the login page when the API is private and the user is not logged in" in new Setup { @@ -85,7 +85,7 @@ class DownloadControllerSpec extends CommonControllerBaseSpec { extendedApiDefinition(serviceName = serviceName.value, version = version, access = ApiAccess.Private(), authorised = false) ) - val result = underTest.downloadResource(serviceName, version, resourceName, None)(request) + val result = underTest.downloadResource(serviceName, version, resourceName)(request) verifyRedirectToLoginPage(result, serviceName, version) } diff --git a/test/uk/gov/hmrc/apidocumentation/v2/controller/FilteredDocumentationIndexControllerSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/FilteredDocumentationIndexControllerSpec.scala similarity index 80% rename from test/uk/gov/hmrc/apidocumentation/v2/controller/FilteredDocumentationIndexControllerSpec.scala rename to test/uk/gov/hmrc/apidocumentation/controllers/FilteredDocumentationIndexControllerSpec.scala index 416397b7..832c7db3 100644 --- a/test/uk/gov/hmrc/apidocumentation/v2/controller/FilteredDocumentationIndexControllerSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/FilteredDocumentationIndexControllerSpec.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package uk.gov.hmrc.apidocumentation.v2.controller +package uk.gov.hmrc.apidocumentation.controllers import scala.concurrent.ExecutionContext.Implicits.global @@ -24,13 +24,11 @@ import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ import uk.gov.hmrc.http.UpstreamErrorResponse import uk.gov.hmrc.apidocumentation.ErrorHandler -import uk.gov.hmrc.apidocumentation.controllers.CommonControllerBaseSpec import uk.gov.hmrc.apidocumentation.controllers.utils._ import uk.gov.hmrc.apidocumentation.mocks.config._ import uk.gov.hmrc.apidocumentation.mocks.services._ -import uk.gov.hmrc.apidocumentation.v2.controllers.FilteredDocumentationIndexController -import uk.gov.hmrc.apidocumentation.v2.models.DocumentationTypeFilter -import uk.gov.hmrc.apidocumentation.v2.views.html.FilteredIndexView +import uk.gov.hmrc.apidocumentation.models.DocumentationTypeFilter +import uk.gov.hmrc.apidocumentation.views.html.documentationList.FilteredIndexView class FilteredDocumentationIndexControllerSpec extends CommonControllerBaseSpec with PageRenderVerification { @@ -65,7 +63,7 @@ class FilteredDocumentationIndexControllerSpec extends CommonControllerBaseSpec fetchAllXmlApisReturnsApis() val result = underTest.apiListIndexPage(Nil, Nil)(request) - verifyPageRendered(pageTitle("API Documentation"), breadcrumbs = List(apiDocsV2Breadcrumb), sideNavLinkRendered = false, bodyContains = Seq("API documentation"))(result) + verifyPageRendered(pageTitle("API Documentation"), breadcrumbs = List(apiDocsBreadcrumb), sideNavLinkRendered = false, bodyContains = Seq("API documentation"))(result) } "render the filtered API list when doc type filter is road map and service guides but no category filter" in new Setup { @@ -75,7 +73,7 @@ class FilteredDocumentationIndexControllerSpec extends CommonControllerBaseSpec val result = underTest.apiListIndexPage(List(DocumentationTypeFilter.ROADMAPANDSERVICEGUIDE), List.empty)(request) // There are currently 23 Service Guides and 4 roadmaps so should be 25 results - verifyPageRendered(pageTitle("API Documentation"), sideNavLinkRendered = false, breadcrumbs = List(apiDocsV2Breadcrumb), bodyContains = Seq("27 results "))(result) + verifyPageRendered(pageTitle("API Documentation"), sideNavLinkRendered = false, breadcrumbs = List(apiDocsBreadcrumb), bodyContains = Seq("27 results "))(result) } "render the filtered API list when doc type filter is road map and service guides and customs category filter" in new Setup { @@ -88,7 +86,21 @@ class FilteredDocumentationIndexControllerSpec extends CommonControllerBaseSpec verifyPageRendered( pageTitle("API Documentation"), sideNavLinkRendered = false, - breadcrumbs = List(apiDocsV2Breadcrumb), + breadcrumbs = List(apiDocsBreadcrumb), + bodyContains = Seq("2 results ", "Income Tax (MTD) end-to-end service guide", "Income Tax (MTD) roadmap") + )(result) + } + + "render the filtered API list when only customs category filter" in new Setup { + theUserIsLoggedIn() + theDefinitionServiceWillReturnApiDefinitions(definitionList) + fetchAllXmlApisReturnsVatApi() + + val result = underTest.apiListIndexPage(List.empty, List(ApiCategory.INCOME_TAX_MTD))(request) + verifyPageRendered( + pageTitle("API Documentation"), + sideNavLinkRendered = false, + breadcrumbs = List(apiDocsBreadcrumb), bodyContains = Seq("2 results ", "Income Tax (MTD) end-to-end service guide", "Income Tax (MTD) roadmap") )(result) } diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationControllerSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationControllerSpec.scala index 802ae487..a68f2904 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationControllerSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/OpenApiDocumentationControllerSpec.scala @@ -31,12 +31,13 @@ import uk.gov.hmrc.apiplatform.modules.apis.domain.models.ServiceName import uk.gov.hmrc.apiplatform.modules.common.domain.models.ApiVersionNbr import uk.gov.hmrc.apidocumentation.ErrorHandler +import uk.gov.hmrc.apidocumentation.controllers.utils.PageRenderVerification import uk.gov.hmrc.apidocumentation.mocks.config._ import uk.gov.hmrc.apidocumentation.mocks.connectors.DownloadConnectorMockModule import uk.gov.hmrc.apidocumentation.mocks.services._ import uk.gov.hmrc.apidocumentation.views.html._ -class OpenApiDocumentationControllerSpec extends CommonControllerBaseSpec { +class OpenApiDocumentationControllerSpec extends CommonControllerBaseSpec with PageRenderVerification { trait Setup extends DownloadConnectorMockModule @@ -99,5 +100,40 @@ class OpenApiDocumentationControllerSpec extends CommonControllerBaseSpec { status(result) shouldBe NOT_FOUND } + + "should successfully show the open api preview page when flagged on" in new Setup { + when(appConfig.openApiPreviewEnabled).thenReturn(true) + + val result = underTest.previewApiDocumentationPage()(request) + verifyPageRendered(pageTitle("OpenAPI Documentation Preview"))(result) + } + + "should NOT FOUND show the open api preview page when flagged off" in new Setup { + when(appConfig.openApiPreviewEnabled).thenReturn(false) + + val result = underTest.previewApiDocumentationPage()(request) + status(result) shouldBe NOT_FOUND + } + + "should successfully show the open api preview action when flagged on but no URL" in new Setup { + when(appConfig.openApiPreviewEnabled).thenReturn(true) + + val result = underTest.previewApiDocumentationAction(None)(request) + verifyPageRendered(pageTitle("OpenAPI Documentation Preview"))(result) + } + + "should successfully show the open api preview action when flagged on" in new Setup { + when(appConfig.openApiPreviewEnabled).thenReturn(true) + + val result = underTest.previewApiDocumentationAction(Some("http://localhost:1234"))(request) + status(result) shouldBe OK + } + + "should NOT FOUND show the open api preview action when flagged off" in new Setup { + when(appConfig.openApiPreviewEnabled).thenReturn(false) + + val result = underTest.previewApiDocumentationAction(None)(request) + status(result) shouldBe NOT_FOUND + } } } diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/PageRenderVerification.scala b/test/uk/gov/hmrc/apidocumentation/controllers/PageRenderVerification.scala index fa5e354d..3a177f68 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/PageRenderVerification.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/PageRenderVerification.scala @@ -33,12 +33,7 @@ trait PageRenderVerification { import NavigationServiceMock.sidebarLink lazy val homeBreadcrumb = Crumb("Home", routes.DocumentationController.indexPage().url) - lazy val apiDocsBreadcrumb = Crumb("API Documentation", routes.ApiDocumentationController.apiIndexPage(None, None, None).url) - - lazy val apiDocsV2Breadcrumb = Crumb( - "API Documentation", - uk.gov.hmrc.apidocumentation.v2.controllers.routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url - ) + lazy val apiDocsBreadcrumb = Crumb("API Documentation", routes.FilteredDocumentationIndexController.apiListIndexPage(List.empty, List.empty).url) def titleOf(result: Future[Result]) = { val titleRegEx = """]*>(.*)""".r diff --git a/test/uk/gov/hmrc/apidocumentation/controllers/RedirectControllerSpec.scala b/test/uk/gov/hmrc/apidocumentation/controllers/RedirectControllerSpec.scala index 0fc509b8..bee29ab5 100644 --- a/test/uk/gov/hmrc/apidocumentation/controllers/RedirectControllerSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/controllers/RedirectControllerSpec.scala @@ -38,7 +38,7 @@ class RedirectControllerSpec extends CommonControllerBaseSpec { "RedirectController" should { "redirect to the index page" in new Setup { verifyPageRedirected( - underTest.redirectToDocumentationIndexPage(None)(request), + underTest.redirectToDocumentationIndexPage()(request), "/api-documentation/docs/api" ) } @@ -48,8 +48,7 @@ class RedirectControllerSpec extends CommonControllerBaseSpec { underTest.redirectToApiDocumentationPage( ServiceName("my-service"), ApiVersionNbr("1.0"), - "my-endpoint", - None + "my-endpoint" )(request), "/api-documentation/docs/api/service/my-service/1.0" ) @@ -58,8 +57,7 @@ class RedirectControllerSpec extends CommonControllerBaseSpec { underTest.redirectToApiDocumentationPage( ServiceName("my-other-service"), ApiVersionNbr("7.3"), - "my-other-endpoint", - None + "my-other-endpoint" )(request), "/api-documentation/docs/api/service/my-other-service/7.3" ) diff --git a/test/uk/gov/hmrc/apidocumentation/models/JsonSchemaSpec.scala b/test/uk/gov/hmrc/apidocumentation/models/JsonSchemaSpec.scala deleted file mode 100644 index 2718f02d..00000000 --- a/test/uk/gov/hmrc/apidocumentation/models/JsonSchemaSpec.scala +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.apidocumentation.models - -import scala.collection.immutable.ListMap - -import play.api.libs.json.Json -import uk.gov.hmrc.apiplatform.modules.common.utils.HmrcSpec - -class JsonSchemaSpec extends HmrcSpec { - - def parseSchema(schema: String) = { Json.parse(schema).as[JsonSchema] } - - "JsonSchema" should { - - "support scalar types" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "title": "Business name", - | "description": "Name of the business", - | "type": "string" - |} - """.stripMargin - ) - - actual shouldBe JsonSchema(title = Some("Business name"), description = Some("Name of the business"), `type` = Some("string")) - } - - "support provision of an example" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "description": "Name of the business", - | "example": "Json Limited", - | "type": "string" - |} - """.stripMargin - ) - - actual shouldBe JsonSchema(description = Some("Name of the business"), example = Some("Json Limited"), `type` = Some("string")) - } - - "support objects with properties" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "type": "object", - | "properties": { - | "name": { - | "description": "Business name", - | "type": "string" - | }, - | "activities": { - | "description": "Activities of the business", - | "type": "string" - | } - | } - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - `type` = Some("object"), - properties = ListMap( - "name" -> JsonSchema(description = Some("Business name"), `type` = Some("string")), - "activities" -> JsonSchema(description = Some("Activities of the business"), `type` = Some("string")) - ) - ) - } - - "support objects containing objects" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "type": "object", - | "properties": { - | "name": { - | "description": "Business name", - | "type": "object", - | "properties": { - | "registeredName" : { - | "description": "The registered name for the business", - | "type": "string" - | }, - | "tradingName": { - | "description": "The name the business trades by", - | "type": "string" - | } - | } - | }, - | "activities": { - | "description": "Activities of the business", - | "type": "string" - | } - | } - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - `type` = Some("object"), - properties = ListMap( - "name" -> JsonSchema( - description = Some("Business name"), - `type` = Some("object"), - properties = ListMap( - "registeredName" -> JsonSchema(description = Some("The registered name for the business"), `type` = Some("string")), - "tradingName" -> JsonSchema(description = Some("The name the business trades by"), `type` = Some("string")) - ) - ), - "activities" -> JsonSchema(description = Some("Activities of the business"), `type` = Some("string")) - ) - ) - } - - "support objects with patternProperties" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "type": "object", - | "patternProperties": { - | "[A-Z0-9]{4}-[A-Z0-9]{5}": { - | "description": "First", - | "type": "string" - | }, - | "\\d{5}-\\d{2}": { - | "description": "Second", - | "type": "string" - | } - | } - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - `type` = Some("object"), - patternProperties = ListMap( - "[A-Z0-9]{4}-[A-Z0-9]{5}" -> JsonSchema(description = Some("First"), `type` = Some("string")), - "\\d{5}-\\d{2}" -> JsonSchema(description = Some("Second"), `type` = Some("string")) - ) - ) - } - - "support specifying required properties" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "type": "object", - | "properties": { - | "name": { - | "description": "Business name", - | "type": "string" - | }, - | "activities": { - | "description": "Activities of the business", - | "type": "string" - | } - | }, - | "required": ["name"] - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - `type` = Some("object"), - properties = ListMap( - "name" -> JsonSchema(description = Some("Business name"), `type` = Some("string")), - "activities" -> JsonSchema(description = Some("Activities of the business"), `type` = Some("string")) - ), - required = Seq("name") - ) - } - - "support arrays" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "type": "array", - | "items": { - | "description": "Business name", - | "type": "string" - | } - |} - """.stripMargin - ) - - actual shouldBe JsonSchema(`type` = Some("array"), items = Some(JsonSchema(description = Some("Business name"), `type` = Some("string")))) - } - - "support definitions" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "definitions": { - | "name": { - | "description": "Business name", - | "type": "string" - | }, - | "activities": { - | "description": "Activities of the business", - | "type": "string" - | } - | } - |} - """.stripMargin - ) - - actual shouldBe JsonSchema(definitions = - ListMap( - "name" -> JsonSchema(description = Some("Business name"), `type` = Some("string")), - "activities" -> JsonSchema(description = Some("Activities of the business"), `type` = Some("string")) - ) - ) - } - - "support references" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "type": "object", - | "properties": { - | "name": { - | "$ref": "#/definitions/name" - | } - | }, - | "definitions": { - | "name": { - | "description": "Business name", - | "type": "string" - | } - | } - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - `type` = Some("object"), - properties = ListMap( - "name" -> JsonSchema(ref = Some("#/definitions/name")) - ), - definitions = ListMap( - "name" -> JsonSchema(description = Some("Business name"), `type` = Some("string")) - ) - ) - } - - "support enums" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "description": "Transaction type", - | "type": "string", - | "enum": ["CREDIT", "DEBIT"] - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - description = Some("Transaction type"), - `type` = Some("string"), - enum = Seq(EnumerationValue("CREDIT"), EnumerationValue("DEBIT")) - ) - } - - "support oneOf for specifying enums with descriptions" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "description": "Transaction type", - | "oneOf": [ - | { "enum": ["CREDIT"], "description": "A credit" }, - | { "enum": ["DEBIT"], "description": "A debit" } - | ] - |} - """.stripMargin - ) - - actual shouldBe JsonSchema( - description = Some("Transaction type"), - oneOf = Seq( - JsonSchema(enum = Seq(EnumerationValue("CREDIT")), description = Some("A credit")), - JsonSchema(enum = Seq(EnumerationValue("DEBIT")), description = Some("A debit")) - ) - ) - } - - "support specifying a pattern" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "description": "Name of the business", - | "type": "string", - | "pattern": "^[A-Z0-9]{6}$" - |} - """.stripMargin - ) - - actual shouldBe JsonSchema(description = Some("Name of the business"), pattern = Some("^[A-Z0-9]{6}$"), `type` = Some("string")) - } - - "support specifying an ID for the type" in { - val actual = parseSchema( - """ - |{ - | "$schema": "http://json-schema.org/schema", - | "description": "Date", - | "type": "string", - | "id": "full-date" - |} - """.stripMargin - ) - - actual shouldBe JsonSchema(description = Some("Date"), id = Some("full-date"), `type` = Some("string")) - } - } -} diff --git a/test/uk/gov/hmrc/apidocumentation/models/NavLinkSpec.scala b/test/uk/gov/hmrc/apidocumentation/models/NavLinkSpec.scala index c1fbb93c..092daa0e 100644 --- a/test/uk/gov/hmrc/apidocumentation/models/NavLinkSpec.scala +++ b/test/uk/gov/hmrc/apidocumentation/models/NavLinkSpec.scala @@ -25,7 +25,8 @@ class NavLinkSpec extends HmrcSpec { "return static navlinks for devhub" in { StaticNavLinks() shouldBe Seq( - NavLink("Documentation", "/api-documentation/docs/using-the-hub"), + NavLink("Getting Started", "/api-documentation/docs/using-the-hub"), + NavLink("API documentation", "/api-documentation/docs/api"), NavLink("Applications", "/developer/applications"), NavLink("Support", "/developer/support"), NavLink("Service Availability", "https://api-platform-status.production.tax.service.gov.uk/", openInNewWindow = true) diff --git a/test/uk/gov/hmrc/apidocumentation/utils/ApiDefinitionTestDataHelper.scala b/test/uk/gov/hmrc/apidocumentation/utils/ApiDefinitionTestDataHelper.scala index 9861ae32..f7de6948 100644 --- a/test/uk/gov/hmrc/apidocumentation/utils/ApiDefinitionTestDataHelper.scala +++ b/test/uk/gov/hmrc/apidocumentation/utils/ApiDefinitionTestDataHelper.scala @@ -19,33 +19,12 @@ package uk.gov.hmrc.apidocumentation.utils import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ import uk.gov.hmrc.apiplatform.modules.common.domain.models._ -import uk.gov.hmrc.apidocumentation.models._ - trait ApiDefinitionTestDataHelper { def apiDefinition(name: String, versions: Seq[ApiVersion] = Seq(apiVersion("1.0", ApiStatus.STABLE)), categories: List[ApiCategory] = List.empty) = { ApiDefinition(ServiceName(name), name, name, name, ApiContext("hello"), versions.map(version => version.versionNbr -> version).toMap, categories = categories) } - implicit class ApiAccessModifier(val inner: APIAccess) { - - def asPublic: APIAccess = { - inner.copy(`type` = ApiAccessType.PUBLIC) - } - - def asPrivate: APIAccess = { - inner.copy(`type` = ApiAccessType.PRIVATE) - } - - def asTrial: APIAccess = { - inner.copy(isTrial = Some(true)) - } - - def notTrial: APIAccess = { - inner.copy(isTrial = Some(false)) - } - } - def apiAvailability() = { ApiAvailability( endpointsEnabled = true, diff --git a/test/uk/gov/hmrc/apidocumentation/views/include/APIFilterSpec.scala b/test/uk/gov/hmrc/apidocumentation/views/include/APIFilterSpec.scala deleted file mode 100644 index fa2d8616..00000000 --- a/test/uk/gov/hmrc/apidocumentation/views/include/APIFilterSpec.scala +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.apidocumentation.views.include - -import org.jsoup.Jsoup -import org.jsoup.nodes.Document - -import play.twirl.api.HtmlFormat.Appendable -import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ - -import uk.gov.hmrc.apidocumentation.common.utils.AsyncHmrcSpec -import uk.gov.hmrc.apidocumentation.views - -class APIFilterSpec extends AsyncHmrcSpec { - - case class Page(doc: Appendable) { - lazy val dom: Document = Jsoup.parse(doc.body) - lazy val dropdown = dom.getElementById("service-filter") - lazy val options = dropdown.getElementsByTag("option") - lazy val selectedVersion = dropdown.getElementsByAttribute("selected").last - } - - class Setup(filter: Option[ApiCategory] = None) { - - val apisByCategory = List(ApiCategory.CUSTOMS, ApiCategory.VAT) - val page = Page(views.html.include.documentFilter(apisByCategory, filter)) - } - - "api filter" when { - "no filter provided" should { - "render the dropdown based on the provided categories" in new Setup { - page.options.size shouldBe apisByCategory.size + 1 - } - - "select the default disabled option" in new Setup { - page.selectedVersion.hasAttr("disabled") shouldBe true - } - } - - "filter is provided" should { - "render the dropdown based on the provided categories" in new Setup(filter = Some(ApiCategory.CUSTOMS)) { - page.options.size shouldBe apisByCategory.size + 1 - } - - "select the provided category" in new Setup(filter = Some(ApiCategory.CUSTOMS)) { - page.selectedVersion.attr("value") shouldBe "customs" - } - } - } -} diff --git a/test/uk/gov/hmrc/apidocumentation/views/include/APIGroupsSpec.scala b/test/uk/gov/hmrc/apidocumentation/views/include/APIGroupsSpec.scala deleted file mode 100644 index 469f0b00..00000000 --- a/test/uk/gov/hmrc/apidocumentation/views/include/APIGroupsSpec.scala +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.gov.hmrc.apidocumentation.views.include - -import scala.jdk.CollectionConverters._ - -import org.jsoup.Jsoup -import org.jsoup.nodes.Document - -import play.twirl.api.HtmlFormat.Appendable -import uk.gov.hmrc.apiplatform.modules.apis.domain.models._ -import uk.gov.hmrc.apiplatform.modules.common.domain.models._ - -import uk.gov.hmrc.apidocumentation.common.utils.AsyncHmrcSpec -import uk.gov.hmrc.apidocumentation.models._ -import uk.gov.hmrc.apidocumentation.utils.ApiDefinitionTestDataHelper -import uk.gov.hmrc.apidocumentation.views - -class APIGroupsSpec extends AsyncHmrcSpec { - - case class Page(doc: Appendable) { - lazy val dom: Document = Jsoup.parse(doc.body) - lazy val tableBodies = dom.getElementsByTag("tbody") - lazy val tableHeadings = dom.getElementsByClass("api-group") - lazy val serviceTags = dom.getElementsByClass("govuk-tag") - } - - def anXmlApiDefinition(name: String) = - XmlApiDocumentation(name, "description", "context") - - def aServiceGuide(name: String) = - ServiceGuide(name, "context") - - trait Setup extends ApiDefinitionTestDataHelper { - - val customsApis = Seq( - WrappedApiDefinition(apiDefinition("customsTestSupport1").copy(isTestSupport = true)), - anXmlApiDefinition("customsXmlApi2"), - WrappedApiDefinition(apiDefinition("customsRestApi2")), - WrappedApiDefinition(apiDefinition("customsRestApi1")), - anXmlApiDefinition("customsXmlApi1"), - WrappedApiDefinition(apiDefinition("customsTestSupport2").copy(isTestSupport = true)) - ) - - val vatApis = Seq( - WrappedApiDefinition(apiDefinition("vatTestSupport1").copy(isTestSupport = true)), - anXmlApiDefinition("vatXmlApi1"), - WrappedApiDefinition(apiDefinition("vatRestApi2")), - WrappedApiDefinition(apiDefinition("vatRestApi1")), - WrappedApiDefinition(apiDefinition("vatTestSupport2").copy(isTestSupport = true)) - ) - - val apisByCategory: Map[ApiCategory, Seq[Documentation]] = Map(ApiCategory.CUSTOMS -> customsApis, ApiCategory.VAT -> vatApis) - val page = Page(views.html.include.documentGroups(apisByCategory)) - } - - "API Groups view" should { - "display each category as a group" in new Setup { - page.tableBodies.size shouldBe 2 - page.tableHeadings.first.text shouldBe ApiCategory.CUSTOMS.displayText - page.tableHeadings.last.text shouldBe ApiCategory.VAT.displayText - } - - "sort the definitions by their label" in new Setup { - val classList = page.serviceTags.eachAttr("class").asScala.map(_.stripPrefix("govuk-tag govuk-tag--")) - classList shouldBe Seq("rest", "rest", "test", "test", "xml", "xml", "rest", "rest", "test", "test", "xml") - } - } -}