diff --git a/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala b/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala
index 9ec6e7bd..ecfa1f75 100644
--- a/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala
+++ b/app/uk/gov/hmrc/apidocumentation/models/Documentation.scala
@@ -46,6 +46,7 @@ trait Documentation {
lazy val isRestOrXmlApi = label == REST_API || label == XML_API
+ lazy val nameAsId = name.toLowerCase().replaceAll(" ", "-").replaceAll("[^a-z0-9-]", "")
}
object Documentation {
diff --git a/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html b/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html
index ce7f58c7..287cc45e 100644
--- a/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html
+++ b/app/uk/gov/hmrc/apidocumentation/views/include/documentGroups.scala.html
@@ -35,7 +35,7 @@
@if(index == 0) { @category.displayName | } else { | }
- @document.name
+ @document.name
|
@document.label.displayName
diff --git a/test/uk/gov/hmrc/apidocumentation/models/DocumentationSpec.scala b/test/uk/gov/hmrc/apidocumentation/models/DocumentationSpec.scala
index ab556ed8..9d7c7871 100644
--- a/test/uk/gov/hmrc/apidocumentation/models/DocumentationSpec.scala
+++ b/test/uk/gov/hmrc/apidocumentation/models/DocumentationSpec.scala
@@ -363,19 +363,6 @@ class DocumentationSpec extends HmrcSpec {
result shouldBe Map.empty
}
-
- def anApiDefinition(name: String, categories: Option[Seq[APICategory]] = None, isTestSupport: Option[Boolean] = None) =
- APIDefinition("serviceName", name, "description", "context", None, isTestSupport, Seq(APIVersion("1.0", None, STABLE, Seq.empty)), categories)
-
- def anXmlApiDefinition(name: String, categories: Option[Seq[APICategory]] = None) =
- XmlApiDocumentation(name, "description", "context", categories)
-
- def aServiceGuide(name: String, categories: Option[Seq[APICategory]] = None) =
- ServiceGuide(name, "context", categories)
-
- def aRoadMap(name: String, categories: Option[Seq[APICategory]] = None) =
- RoadMap(name, "context", categories)
-
}
"decoratedUriPattern" should {
@@ -403,4 +390,33 @@ class DocumentationSpec extends HmrcSpec {
Endpoint("Get Today's Date", uriPattern, HttpMethod.GET, parameters)
}
}
+
+ "nameAsId" should {
+ "swap spaces for hyphens and lower case" in {
+ val api1 = anApiDefinition("Hello World")
+ api1.nameAsId shouldBe "hello-world"
+ }
+
+ "remove brackets" in {
+ val api1 = anApiDefinition("Income Tax (MTD) end-to-end service guide")
+ api1.nameAsId shouldBe "income-tax-mtd-end-to-end-service-guide"
+ }
+
+ "remove any other chars" in {
+ val api1 = anApiDefinition("Income Tax (MTD):+{}=#@£!& [end-to-end service guide]")
+ api1.nameAsId shouldBe "income-tax-mtd-end-to-end-service-guide"
+ }
+ }
+
+ def anApiDefinition(name: String, categories: Option[Seq[APICategory]] = None, isTestSupport: Option[Boolean] = None) =
+ APIDefinition("serviceName", name, "description", "context", None, isTestSupport, Seq(APIVersion("1.0", None, STABLE, Seq.empty)), categories)
+
+ def anXmlApiDefinition(name: String, categories: Option[Seq[APICategory]] = None) =
+ XmlApiDocumentation(name, "description", "context", categories)
+
+ def aServiceGuide(name: String, categories: Option[Seq[APICategory]] = None) =
+ ServiceGuide(name, "context", categories)
+
+ def aRoadMap(name: String, categories: Option[Seq[APICategory]] = None) =
+ RoadMap(name, "context", categories)
}
|