-
Notifications
You must be signed in to change notification settings - Fork 102
Add documentation on spec documentation #638
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Documenting the API specification | ||
|
||
A specification is not only about formalizing data structures, it's also about explaining what these structures and their properties are used for. | ||
|
||
Documentation of the TypeScript specification is made using [JSDoc](https://jsdoc.app/) comments, i.e. multiline comments starting with `/**` above a type or field declaration. | ||
|
||
Additional lines start with a `*` followed by a space. Long lines are allowed but it's better if text is formatted to a maximum of 120 characters per line. | ||
|
||
## Example | ||
|
||
```ts | ||
/** | ||
* @rest_spec_name rank_eval | ||
* @since 6.2.0 | ||
*/ | ||
export interface Request extends RequestBase { | ||
path_parts: { | ||
/** | ||
* List of data streams, indices, and index aliases used to limit the request. Wildcard (`*`) expressions are supported. | ||
* | ||
* To target all data streams and indices in a cluster, omit this parameter or use `_all` or `*`. | ||
*/ | ||
index: Indices | ||
} | ||
query_parameters?: { | ||
/** | ||
* Accept no matching indices? | ||
* | ||
* If `false`, the request returns an error if any wildcard expression, index alias, or _all value targets only | ||
* missing or closed indices. This behavior applies even if the request targets other open indices. For example, | ||
* a request targeting `foo*,bar*` returns an error if an index starts with `foo` but no index starts with `bar`. | ||
* | ||
* @server_default true | ||
*/ | ||
allow_no_indices?: boolean | ||
|
||
expand_wildcards?: ExpandWildcards | ||
|
||
/** | ||
* If `true`, missing or closed indices are not included in the response. | ||
* @server_default false | ||
*/ | ||
ignore_unavailable?: boolean | ||
|
||
search_type?: string | ||
} | ||
body: { | ||
/** | ||
* A set of typical search requests, together with their provided ratings. | ||
*/ | ||
requests: RankEvalRequestItem[] | ||
|
||
/** | ||
* Definition of the evaluation metric to calculate. | ||
* | ||
* @doc_url https://www.elastic.co/guide/en/elasticsearch/reference/current/search-rank-eval.html#_available_evaluation_metrics | ||
*/ | ||
metric?: RankEvalMetric | ||
} | ||
} | ||
``` | ||
|
||
([original source code](https://github.com/elastic/elasticsearch-specification/blob/main/specification/_global/rank_eval/RankEvalRequest.ts)) | ||
|
||
|
||
## Markup language | ||
|
||
The specification is the starting point for a number of generators that produce a large range of artifacts, starting with source code in 10 different programming languages. It's essential for the API documentation to be part of these generated artifacts, e.g. to provide autocompletion help in IDEs when using a client library. | ||
|
||
Each of these targets has a different way to format inline documentation: Java code uses HTML, Python uses reStructuredText, Rust uses Markdown, etc. To enable rich documentation to be output, the specification doc comments must not be just plain text, but use a well-defined markup language so that generators can reliably transcode them to their target representation. | ||
|
||
**We have settled on using [GitHub Flavored Markdown](https://github.github.com/gfm/) (GFM) for doc comments.** It is based on the well-defined [CommonMark](https://commonmark.org/) specification with a few additions, most notably tables. | ||
|
||
GFM also has implementations in most languages, meaning that code generators will be able to easily parse the doc comments and transcode them. | ||
|
||
## Structuring a doc-comment | ||
|
||
### Terseness | ||
|
||
**Doc comments are reference material**: they should be as succinct as possible while capturing all the necessary information to use the elements they're documenting. Remember that they will often show up in small IDE autocompletion popups! | ||
|
||
In particular, doc comments are not the right place for tutorials or examples, which should be in dedicated documentation pages. These pages can of course be linked from the doc comments. | ||
|
||
API endpoints will also have a `@doc_url` JSDoc tag that links to that API's detailed documentation page. | ||
|
||
### Multi-paragraph doc comments | ||
|
||
A single sentence is not always enough to explain a type or a field and doc comments will have multiple paragraphs. It is important that **the first paragraph provides a self-contained description** of the item that is being documented. The reason is twofold: | ||
- people skim documentation quickly and should get the gist of the information from that first sentence, and read others if they want to dive in, | ||
- Some IDEs may choose to display only the first paragraph or even the first sentence of a doc-comment in their help popup to keep it small, and then require an additional action from the user to display the full text. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge the content with this section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a commit that that adds a link to this document in that section.