Skip to content
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

Add a default impl of ToSchema::name() #1096

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

ValentinColin
Copy link
Contributor

@ValentinColin ValentinColin commented Oct 5, 2024

I suggest adding a default implementation of the ToSchema trait.

This is a naive implementation that takes the type name and removes the module path and generic elements.

Copy link

@DenuxPlays DenuxPlays left a comment

Choose a reason for hiding this comment

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

I am Not Sure how the Tests are done in this Library but I think a few Tests to Validate the Output would be a good idea.

@juhaku
Copy link
Owner

juhaku commented Oct 6, 2024

Yup that's a valid point.

Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

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

While this is definitely handy for people manually implementing ToSchema it would be a good idea to write couple of tests to validate the output.

@juhaku
Copy link
Owner

juhaku commented Oct 6, 2024

This is a naive implementation that takes the type name and removes the module path and generic elements.

This naive implementation is enough since the name is by default for a type calculated only from the name without generics. Generic args in the name will come from the inner generic types respectively upon schema creation. When users want more advanced name, they can easily override the default functionality and provide their own solution IMO.

@ValentinColin
Copy link
Contributor Author

Absolutely right for unit test!

I've added some documentation too.

Copy link

@DenuxPlays DenuxPlays left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Owner

@juhaku juhaku left a comment

Choose a reason for hiding this comment

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

💯 super

@juhaku
Copy link
Owner

juhaku commented Oct 6, 2024

One thing though, could you add a line (title o the PR) to CHANGELOG.md of in utoipa/CHANGELOG.md Add an new entry to top of the Added section of Unreleased release.

@juhaku juhaku changed the title Provide a default impl of ToSchema::name() Add a default impl of ToSchema::name() Oct 6, 2024
@juhaku
Copy link
Owner

juhaku commented Oct 6, 2024

Great, thansk 🙂

@juhaku juhaku merged commit c9f8408 into juhaku:master Oct 6, 2024
11 checks passed
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.

3 participants