Skip to content

Commit

Permalink
API-7009 Fix invalid IDs for links in API documentation table (hmrc#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
petekirby-ee authored Jun 1, 2023
1 parent 262c752 commit eaddc1b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<tr class="govuk-table__row">
@if(index == 0) { <td class="govuk-table__cell api-group">@category.displayName</td> } else { <td class="govuk-table__cell"></td> }
<td class="govuk-table__cell">
<a id="@document.name" class="govuk-link" href="@document.documentationUrl">@document.name</a>
<a id="@document.nameAsId" class="govuk-link" href="@document.documentationUrl">@document.name</a>
</td>
<td class="govuk-table__cell">
<strong class="govuk-tag [email protected]">@document.label.displayName</strong>
Expand Down
42 changes: 29 additions & 13 deletions test/uk/gov/hmrc/apidocumentation/models/DocumentationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit eaddc1b

Please sign in to comment.