-
Notifications
You must be signed in to change notification settings - Fork 191
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
Namespacing same types #187
Conversation
0e7e463
to
4358be5
Compare
Right now there is a failing test for: #[derive(Component)]
struct Bar {
args: Vec<std::vec::Vec<std::string::String>>
} I'm wondering whether it's reasonable to even resolve primitive types when they have a path? |
It seems like I may have also broken some of the optional features format resolution with this. |
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.
I refactored the value_type
functionality for Component
and added it to IntoParams
as well. This PR needs rebase from latest master.
There are couple of things need a bit of rethinking. One being the namespacing. At least we cannot have it namespaced with the Rust path which will result invalid OpenAPI spec. Maybe better way is to allow users to use as MyAnotherType
but this might not be feasible because the question relies who to reference such type which uses as MyType
syntax.
Another thing is that I have been planning on refactoring the component()
function to return a name of the component as well along side with the component. This would allow users to use serde's rename
on container level. But with this as well the hot question is how to reference such component which has been renamed.
Lastly is it too cumbersome to support sort of namespacing? It would be great to have some solution to this but after all if one was to write a OpenAPI spec manually he/she would need to write distinct type names for each type. So there would not be a clash in such scenario. Point being use uniques type names for Component
s as well. 😂
); | ||
|
||
let argument_path: &TypePath = match argument { | ||
GenericArgument::Type(syn::Type::Path(path)) => path, |
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.
We probably could get rid of this whole custom type parsing and use the ComponentPart
. This would allow users to use the regular Rust types as arguments.
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.
Unfortunately it fails to parse things like [Foo]
and Option<[Foo]>
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.
Perhaps we could do a breaking change, and make it so people need to use Vec<Foo>
and Option<Vec<Foo>>
instead?
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.
Yeah. That kind of was my assumption as well. With allowing users to use Vec<Foo>
and Option<Vec<Foo>>
using ComponentPart
we could possibly get rid of this custom type thing which is not necessary a bad thing. It can be addressed in another PR and it surely could be a breaking change.
let path = TypePath { | ||
qself: None, | ||
path: syn::Path::from(segment.clone()), | ||
}; | ||
|
||
let mut generic_component_type = ComponentPart::convert(Cow::Owned(path)); |
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.
Hmm.. interesting approach 🤔
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.
Do you think there is a better way to do it?
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.
Actually not sure whether there is any better approach. 😄
Is this true? It seems to work fine in swagger, and I can't see anything in the spec which says that component references can't contain
Let's say you have module |
It actually works but not without caveats. If you try out the spec with https://editor.swagger.io/ and try to use If we want to have namespaces implemented there. I guess we need to do manual mangling of the type name according to the rules of Swagger.
Yeah I agree it's not optimal solution not necessary fan of implementing such thing too though 😄 |
That sounds reasonable. How about this proposal, we replace |
I reckon we could go with the dot Also another thing I am wondering could we use sort of special syntax like |
Yeah I think
I think I agree that this is unnecessary at this stage if we have the |
Yeah good |
We probably need to strip the generics out of the path. The error in build is because the path has generic params Failing test: derive_component_with_complex_enum_lifetimes |
Thanks! Yes I didn't have time to fix that one yet, I'll fix it next week and the other comments, and hopefully ready to merge soon so it doesn't require another large merge conflict resolution. |
Yeah sorry about that previously 🙇 . Hopefully not, I'm working on the extension part which is getting some refinment there and the impact should not be too big. |
@juhaku I can't figure out why the |
Ahh.. I had broken the tests there previously. It was missing a feature flag from actix-web framework. I merged the encoding PR and fixed the test. If you take rebase from master I guess this issue will get sorted out. :) |
There seems to be broken rocket related tests. You can run all tests with command
|
@juhaku I had a look into it today, it seems that the parsing for rocket arguments types (and perhaps actix too?) is pretty limited, ideally we should share code with the component derive macro? |
I'm thinking maybe to quickly fix this bug with a work around, and lodge a new issue to propose a refactor in this regard |
I'm also thinking maybe we should merge this with the Edit: mentioned in issue #217 |
Yeah those use cases are quite specific. And there is surely room to improve and refactor the implementation. The axum integration will party address this issue. But will not fully "fix" it. My plan is to address the steps in #217 regarding this matter.
Yeah that is okay for now.
I also commented there about this issue. |
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.
Super. 🚀 Few comments only and soon this can be merged :)
); | ||
|
||
let argument_path: &TypePath = match argument { | ||
GenericArgument::Type(syn::Type::Path(path)) => path, |
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.
Yeah. That kind of was my assumption as well. With allowing users to use Vec<Foo>
and Option<Vec<Foo>>
using ComponentPart
we could possibly get rid of this custom type thing which is not necessary a bad thing. It can be addressed in another PR and it surely could be a breaking change.
let path = TypePath { | ||
qself: None, | ||
path: syn::Path::from(segment.clone()), | ||
}; | ||
|
||
let mut generic_component_type = ComponentPart::convert(Cow::Owned(path)); |
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.
Actually not sure whether there is any better approach. 😄
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.
👍
@juhaku thanks for reviewing this PR, it was a bit of a mammoth in the end! |
Fix #186
This work was sponsored by Arctoris.