-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: discover schema with lifetimes and const generics #42
Conversation
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.
Please also run cargo fmt to fix the ci
898dacd
to
66167eb
Compare
Apologies! I presumed fmt wasn't in use after running it and seeing a litany of changed files in my diff. Little did I know it was git converting the files to CRLF, sigh. Should be sorted now |
I still do not get it. How does your change add functionality? You filter the list so it gets smaller how does this is better then a simple .is_empty() on the same unfiltered list? |
I have created a new branch with the fix removed to demonstrate the problem. For your convenience, the output of running tests:
As you can see from this line, if there are any generics on a struct the value of Struct with lifetimes #[derive(ToSchema)]
pub struct LifetimeStructSchema<'a> {
foo: &'a str,
} Output of
Now if we look at the definition of In order to fix this, my solution is to filter out of Perhaps I should also rename |
Ahh okay now I understand. But then I would rather check if we have any GenericParam::Type as this is the Type of Generic we want. |
I'll take a further look at this when I get time, hopefully tomorrow. Currently this does not compile for whatever reason
|
Very weird I am also enhancing the acceptance tests to cover generics. |
I've managed to track down the issue. #[derive(utoipa::ToSchema)]
pub struct ConstGenericStructSchema<const N: usize> {
foo: [u16; N],
} The struct above once discovered is internally represented as Current output which fails to compile: #[openapi(components(schemas(crate::ConstGenericStructSchema)))] Modified output which successfully compiles: #[openapi(components(schemas(crate::ConstGenericStructSchema<0>)))] Best I can see, the value of N is totally disregarded in the final openapi representation: {
"properties": {
"foo": {
"items": {
"format": "int32",
"minimum": 0,
"type": "integer"
},
"type": "array"
}
},
"required": [
"foo"
],
"type": "object"
} I do not understand the implications of my proposed solution, however I would suggest we instead internally represent the struct as I'm happy to code this up, if you deem it an acceptable solution |
No not at all Generic schemas are meant to used with the aliases attribute. |
OpenApi does not support generic Schemas afaik. |
Ah well, it appears my lack of knowledge on utoipauto and utoipa in general has shown itself. I'll see what I can figure out with this new info, thanks |
No I find it very confusing too. |
Your last commit looks really good on the first glance. Also I am reworking how special imports are processed. I have to think how to develop everything in parallel and merge them with one semi-big pr. (Otherwise the acceptance tests will fail!) But that's a task for tomorrow let me know when you finish this pr. For now: |
No problem at all, thanks for your work on the crates! This has presented me a good excuse to finally learn proc macros I've managed to get lifetimes, const and type generics all to work nicely in isolation, however when mixing lifetimes with either results in a compile error From my initial looks it might be a difficult one to solve, but I'll take a stab at it and let you know how it goes |
35675f0
to
c7490aa
Compare
c7490aa
to
8510db8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Okay, tests pass and I believe this is good to go. Thanks for your help on this! |
No thank you for doing this :) I'll take a look when I find more time. |
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.
Looks good to me.
@ProbablyClem Would be great if you can look at this too. |
Okay @Calum4 Thank you for your work :) |
Fixed as issue where schema with lifetimes were ignored due to the overly eager
.generics.params.is_empty()
found here and here.Disclaimer that I'm not at all familiar with the inner workings of the crate so there may be unintended consequences I've overlooked.