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

Newlines removed in move from doc comment to OpenAPI description #402

Open
david-crespo opened this issue Jul 26, 2022 · 3 comments
Open

Comments

@david-crespo
Copy link
Contributor

david-crespo commented Jul 26, 2022

Seems like double newlines are being kept but single newlines are being turned into spaces.

/// Note that any gaps, unsorted bins, or non-finite values will result in an error.
///
/// Example
/// -------
/// ```rust
/// use oximeter::histogram::{BinRange, Histogram};

https://github.com/oxidecomputer/omicron/blob/e9554ad930665e82526b784b1f12300f067298fa/oximeter/oximeter/src/histogram.rs#L201-L222

becomes

an error.\n\nExample ------- ```rust use oximeter::histogram::{BinRange, Histogram};\n\nlet edges

https://github.com/oxidecomputer/omicron/blob/e9554ad930665e82526b784b1f12300f067298fa/openapi/nexus.json#L8018

@ahl
Copy link
Collaborator

ahl commented Aug 1, 2022

Tricky! It's hard to distinguish, say, a line-wrapped paragraph from intentional newlines. In this particular case, it seems like the comments are intended for the local crate and aren't appropriate to include in the OpenAPI document at all.

@bnaecker
Copy link
Contributor

bnaecker commented Aug 1, 2022

Yeah, this particular comment predates using a generator, and wasn't originally intended to be part of the OpenAPI spec. I think this one deserves either a wrapper type with a more clear and language-agnostic docstring, or moving most of the existing string to a private comment, e.g., /// to // in the source file.

@david-crespo
Copy link
Contributor Author

Fine with me, seems like most of the fix here is to fix the comment itself.

Maybe a dumb question, but why do we need to process the newlines in the doc comments at all?

match (summary, first) {
(None, _) => (None, None),
(summary, None) => (summary, None),
(Some(summary), Some(first)) => (
Some(summary),
Some(
lines
.fold(first, |acc, comment| {
if acc.ends_with('-')
|| acc.ends_with('\n')
|| acc.is_empty()
{
// Continuation lines and newlines.
format!("{}{}", acc, comment)
} else if comment.is_empty() {
// Handle fully blank comments as newlines we keep.
format!("{}\n", acc)
} else {
// Default to space-separating comment fragments.
format!("{} {}", acc, comment)
}
})
.trim_end()
.to_string(),
),
),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants