Skip to content

V0.2.0 preparation / Utoipa v5 support #45

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

Merged
merged 14 commits into from
Oct 17, 2024
Merged

V0.2.0 preparation / Utoipa v5 support #45

merged 14 commits into from
Oct 17, 2024

Conversation

DenuxPlays
Copy link
Collaborator

@DenuxPlays DenuxPlays commented Oct 2, 2024

The main goal is to get 100% compatible with utoipa v5.
closes: #44

TODOs

  • add/complete the changelog
  • add more acceptance tests
  • fix tests
  • remove generic schema discovery
  • update documentation

Changelog

Breaking

  • updated msrv to 1.75.0
  • removed generic_full_path feature

Added

  • generics acceptance tests
  • responses acceptance tests

Changes

  • added generic acceptance tests
  • added responses acceptance tests
  • updated test to utoipa v5

Removed

  • removed Generic Schema support (as this is handled by utoipa now)

preparation for v0.2.0 as we have to rework the whole generic feature
Note: for now as we will create new ones when the core is restructured
@DenuxPlays
Copy link
Collaborator Author

Test fail because the ToSchema derive is broken for constant generics:
juhaku/utoipa#1115

@DenuxPlays
Copy link
Collaborator Author

Still some weird things that needs investigating:

Without the new schema_discovery feature there are routes missing?
Still no schemas are auto-discovered by utoipa (I guess this has something to do with the other issue mentioned above)

@DenuxPlays
Copy link
Collaborator Author

As long as responses (including their schemas) are not being auto-discovered we cannot remove schema discovery/put it behind a feature flag.
Related issue: juhaku/utoipa#1094

This will not stop or impact the development just a note.

@DenuxPlays DenuxPlays marked this pull request as ready for review October 14, 2024 20:00
@DenuxPlays
Copy link
Collaborator Author

@ProbablyClem I think this is ready.

Can you please take a look at it.

@DenuxPlays DenuxPlays changed the title V0.2.0 preparation V0.2.0 preparation / Utoipa v5 support Oct 14, 2024
Copy link
Owner

@ProbablyClem ProbablyClem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR thanks :

@DenuxPlays
Copy link
Collaborator Author

Thank you :)

I would merge this pr.
Can you create a new release then?

@DenuxPlays DenuxPlays merged commit 7469f9d into main Oct 17, 2024
7 checks passed
@DenuxPlays DenuxPlays deleted the feature/utoipa-v5 branch October 17, 2024 18:20
Comment on lines +96 to +98
if !generic_params.is_empty() {
return out;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DenuxPlays is it intentional that this means that structs that derive ToResponse but have a lifetime will no longer be detected? We have some code that looks like

#[derive(Debug, Clone, Serialize, ToSchema, ToResponse)]
pub(crate) struct TopicInfo<'a> {
    #[schema(schema_with = kind_schema)]
    topics: HashMap<&'a str, Kind>,
}

which we use to avoid allocating Strings for these topics that are going to be serialized anyways as part of the response. In [email protected], this was discovered by utoipauto and added to the #[openapi] directive - we just had responses( (status = StatusCode::OK, response = TopicInfo) ) on the #[utoipa::path]. In 0.2, TopicInfo disappears from the schema.

If I put (status = StatusCode::OK, description = "A list of known topics.", body = TopicInfo) as the responses instead, it shows up (only in the schemas part) - unsure if that's utoipauto or the new schema discovery in utoipa@5. But I have also confirmed that if I use the old condition for the early return instead, TopicInfo is included in the responses as well.

Would there be any issues with only using the new, more strict check for schemas but keep the old check for responses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really remember this code tbh.

But I think lifetimes aren't supported by utoipa in v5?
If they are then they should be auto discovered.

If there is a bug in the auto-discovery feature feel free to open a pr to fix it or an issue to document it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think the code is faulty.

We should check for explicit generic parameters excluding lifetimes.
But I remember that something like this has already be done or came up?
Idk really remember tbh.

Copy link

@domenicquirl domenicquirl Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly do you mean by "not supported"? Both ToSchema and ToResponse work fine with, for example, MyType<'a> containing a &'a str (which is correctly represented as schema type "string"). So as long as the type is part of the OpenAPI declaration at all, this has been working fine even in v4. Or maybe I'm missing something?

utoipa very much claims support for generics in their README (as long as you use the derives). juhaku/utoipa#1034 also includes a type with a lifetime parameter in the examples, so I'd expect this to "just work" (except for maybe const generics) 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait my memory is coming back.
We do this because schemas are getting autodiscovered.
Our Problem is that we cannot predict which type of generic you use.
I think that Utoipa converts this SomeType<String> to SomeTypeString.
So basically what the aliases macro did in v4.
In v4 we parsed the aliases macro and added all the types but this isn't possible in v5.

So the real issue is this:
juhaku/utoipa#1094

I am not sure if we can develop a work-around for now.
Atleast I don't have the time to.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why do we need to predict anything here? Can't we (syn) look at what kind of generic the macro is parsing?

What you're saying about the name change seems right (except that I think it becomes SomeType_String), but I can't see how this is particularly related to lifetimes, which should just be ignored by the name conversion?

FWIW, I also opened #50 which just reverts the discovery check. It doesn't do anything about previously having handling for aliases, honestly I haven't ever used it so I'm not sure what we would need to be doing there either.

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

Successfully merging this pull request may close these issues.

Version 0.2.0 (For utoipa v5)
3 participants