Skip to content

Commit

Permalink
slightly tidier
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsimpson committed Jul 24, 2023
1 parent 97a8d3c commit a2b5897
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class EndpointGenerator {
|""".stripMargin
}

private val legalNameRegex = """([a-zA-Z$_][0-9a-zA-Z$_]*)""".r
private[codegen] def generatedEndpoints(p: OpenapiPath): Seq[(String, String)] = {
p.methods.map { m =>
val definition =
Expand All @@ -39,11 +38,12 @@ class EndpointGenerator {
|""".stripMargin

val name = m.operationId
.getOrElse(m.methodType + p.url.split('/').map(_.replace("{", "").replace("}", "").toLowerCase.capitalize).mkString) match {
case legalNameRegex(n) => n
case n =>
n.split("[^a-zA-Z$_]").filter(_.nonEmpty).zipWithIndex.map { case (part, 0) => part; case (part, _) => part.capitalize }.mkString
}
.getOrElse(m.methodType + p.url.capitalize)
.split("[^a-zA-Z0-9$_]")
.filter(_.nonEmpty)
.zipWithIndex
.map { case (part, 0) => part; case (part, _) => part.capitalize }
.mkString
(name, definition)
}
}
Expand Down

0 comments on commit a2b5897

Please sign in to comment.