Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra dollar sign to avoid env var substitution in docs #1241

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ version
.bsp

.direnv

#smithy cli metadata
build/smithy/classpath.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package smithy4s.example

import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

/** This is meant to be used with $${ENV_VAR}
* @param member
* This is meant to be used with $$ENV_VAR
*/
final case class EnvVarString(member: Option[String] = None)

object EnvVarString extends ShapeTag.Companion[EnvVarString] {
val id: ShapeId = ShapeId("smithy4s.example", "EnvVarString")

val hints: Hints = Hints(
smithy.api.Documentation(s"This is meant to be used with $${ENV_VAR}"),
)

implicit val schema: Schema[EnvVarString] = struct(
string.optional[EnvVarString]("member", _.member).addHints(smithy.api.Documentation(s"This is meant to be used with $$ENV_VAR")),
){
EnvVarString.apply
}.withId(id).addHints(hints)
}
9 changes: 7 additions & 2 deletions modules/codegen/src/smithy4s/codegen/internals/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,22 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self =>
hints: List[Hint],
skipMemberDocs: Boolean = false
): Lines = {
def atLiteral(s: String) = s.replace("@", "{@literal @}")
def dollarLiteral(s: String) = s.replace("$", "$$")
hints
.collectFirst { case h: Hint.Documentation => h }
.foldMap { doc =>
val shapeDocs: List[String] =
doc.docLines.map(_.replace("@", "{@literal @}"))
doc.docLines
.map(atLiteral)
.map(dollarLiteral)
val memberDocs: List[String] =
if (skipMemberDocs) List.empty
else
doc.memberDocLines.flatMap { case (memberName, text) =>
s"@param $memberName" :: text
.map(_.replace("@", "{@literal @}"))
.map(atLiteral)
.map(dollarLiteral)
.map(" " + _)
}.toList

Expand Down
7 changes: 6 additions & 1 deletion sampleSpecs/quoted_string.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ string AString
string AnotherString

structure AStructure {

astring: AString = "\"Hello World\" with \"quotes\""
}

@documentation("This is meant to be used with ${ENV_VAR}")
structure EnvVarString {
@documentation("This is meant to be used with $ENV_VAR")
member: String
}