Closed emonadeo closed 8 months ago
Looks great, thank you !
The issue with implementing interop between libraries is that inevitably the up to date version will clash with the implemented version. We had massive issues when a major version changed for axum and sqlx. For this reason we now prefer to implement interop with the newtype pattern that works as a drop in replacement.
Would that be ok for you ? We can either accept a subcrate or you can publish it on your own as aide-typed-multipart.
Sure, shouldn't be a problem.
Looks good to me !
You may want to create your own proc macro based on the axum one if you wish to truly document all the different aspects. However just having the general type for most cases is good enough, i would accept it as-is and allow for future expansion as the need arises in your usecase. It's up to you.
Yes, I have been considering using a macro to document the encoding, but I am very inexperienced in authoring macros. Let me explore this a bit and follow up with a new PR.
For the time being I think this is sufficient for 0.1.0. I will add documentation and then ask for review and merge.
Thanks @emonadeo this PR! @Wicpar any ETA on merging and cutting a new release?
Not yet, i have a tight deadline at the moment. I still need to configure the changelog before release. If you do that (based on the other crates and the contributing.md command) i can merge sooner.
Oops I broke the tests, I forgot that Rust runs code blocks in docstrings. Will fix in a new PR.
i fixed it, no worries. published
Is there a way to validate the file extension like you did for file limit. For instance, if I want to take only png or pdf files, how do I do it ?
Checking for the extension of file is an option, but I was wondering if we can do it in a way that is similar to checking limit #[form_data(limit = "unlimited")]
Is there a way to validate the file extension like you did for file limit. For instance, if I want to take only png or pdf files, how do I do it ? Checking for the extension of file is an option, but I was wondering if we can do it in a way that is similar to checking limit
#[form_data(limit = "unlimited")]
#[form_data(limit = "unlimited")]
is part of the derive macro provided by axum_typed_multipart
, aide_axum_typed_multipart
(this PR) only implements the traits needed to generate OpenAPI schemas from a TypedMultipart<>
extractor.
I think checking the file extension is perfectly fine. You could also check the Content-Type
header of the file, although I wouldn't rely on it. And if you really want to make sure that you 100% have a file that is a valid png or pdf, you'll need to validate the file contents (probably using a third party library).
Is there a way to validate the file extension like you did for file limit. For instance, if I want to take only png or pdf files, how do I do it ? Checking for the extension of file is an option, but I was wondering if we can do it in a way that is similar to checking limit
#[form_data(limit = "unlimited")]
#[form_data(limit = "unlimited")]
is part of the derive macro provided byaxum_typed_multipart
,aide_axum_typed_multipart
(this PR) only implements the traits needed to generate OpenAPI schemas from aTypedMultipart<>
extractor.I think checking the file extension is perfectly fine. You could also check the
Content-Type
header of the file, although I wouldn't rely on it. And if you really want to make sure that you 100% have a file that is a valid png or pdf, you'll need to validate the file contents (probably using a third party library).
Ooh got it, Thankss!
Currently, aide generates a very generic schema from the multipart extractor:
This is impossible to fix with vanilla axum, as it only provides a plain
Multipart
extractor which imperatively reads the fields without providing types beyond that.This PR adds integration for https://github.com/murar8/axum_typed_multipart, which provides a fully typed multipart extractor.
Example
generates
and the schemas
Still not great
The image input, represented in Rust as
axum::body::Bytes
serialises toArray_of_uint8
JsonSchema as implemented in schemars with the bytes feature enabled, but OpenAPI offers more advanced options to specify this.The current state of this PR does not yet cover Encoding Objects, which allow something like this:
Tasks
I can see multiple directions to design such an API, but I would prefer to discuss this before I implement something in a bad direction, which is why I created this draft PR. Feedback is much appreciated.