microsoft / typespec

https://typespec.io/
MIT License
4.35k stars 201 forks source link

Add documentation to `@doc` and other documentation components that they could contain markdown or other formatting #171

Open johanste opened 2 years ago

johanste commented 2 years ago

Rich text formatting in descriptions/documentation

Documentation for APIs often involve more than just raw text. Common reasons to use rich text formatting include rendering of tables or embedding links into the generated reference documentation.

For an example, see the APIM List By Tags endpoint which illustrates the attempt to use (valid) openapi descriptions that contains a table in the API documentation as well as the issue with tools treating description fields as plain text (broken rendering).

OpenAPI support for rich text

OpenAPI allows for rich text formatting in description fields using CommonMark. As evident from the example above, there are gaps in our toolset with regards to how rich text is handled.

Possible solution

@richDoc(
"""
|One|Two|
|-|-|
|1|2|
|3|4|
""", "CommonMark")
model ModelWithTableDocs {};

Alternate solution

Change the @doc decorator so that it accepts CommonMark instead of raw text. For the most part, that is an extension to its current decorator definition (in most cases, you don't have accidental markup in the raw text), but it adds complexity to emitters since they have to sniff the format/convert to something they can manage or risk broken rendering as shown above.

Challenges/questions:

markcowl commented 2 years ago

Notes from design meeting

tjprescott commented 2 years ago

From the most recent review with the API review board, they weren't a fan of HTML in the docstrings and would prefer something like markdown.

mikekistler commented 1 year ago

I think the answer here is to just state that @doc/doc comments can support markdown -- we could treat it as a documentation issue.

markcowl commented 1 year ago

Implementation issue for beta is just documentation, per Mike's comment and discussion

markcowl commented 8 months ago

est: 1, pri: 2