-
-
Notifications
You must be signed in to change notification settings - Fork 299
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
[Feature Request] Don't create allOf when adding description to ref field #385
Comments
|
This is the correct result and is intentional. // if you make this a doc string, this field becomes allof
pub number: U64, This line defines a new description for |
But why can't you just put the description alongside it, like in my last snippet? The validator I used online says it's valid, and that way we don't add an unnecessary extra type just for the sake of having a doc string. |
I tried it and Swagger UI doesn't seem to recognize this new
|
Hmmm yeah you're right, I tried a different UI generator and it didn't like it either. I feel like this is a potential foot gun in the future, when people add a docstring to a field in a struct they don't expect that that will result in a change in the actual representation of the types. Is there a way to make including a doc string a compile time error instead? For example how it's an error in clap to add a docstring to a |
I want to revive this issue, it's actually problematic behavior - by adding a doc comment, in fact, we're changing the structure expected. "allOf": [
{
"$ref": "#/components/schemas/SomeObj"
},
{
"description": "Some comment",
"default": "y"
}
]
For example, this causes problems when generating clients from such openapi-specs. Probably it should be just ignored in openapi spec until 3.1 is supported? 🤔 cc @sunli829 |
First off, here is how you repro the problem:
Once you've got this,
cargo run
and check the generated YAML spec:In the spec you can see this:
Now if you change line 63 in
src/main.rs
to a doc comment (///
) and generate the spec, you get this:As you can see, if you add a docstring to the field in this struct, the spec generator uses
allOf
so it can include the description.According to this validator (https://apitools.dev/swagger-parser/online/), you can just include the description side by side with the ref like this:
allOf
behavior feels like a real footgun. Or at least include some way to opt in to making it a compilation error.I understand it's possible that the macro I'm using is also a bit messed up, but it feels like Poem should still do either one of these two things above.
Thanks a lot!
For context, here is the PR where we unexpectedly ran into this problem: aptos-labs/aptos-core#3774. Here is the PR where we fixed it for now by reverting these changes: aptos-labs/aptos-core#4007.
The text was updated successfully, but these errors were encountered: