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

Response references, IntoResponseComponent and IntoResponses #215

Merged
merged 13 commits into from
Aug 5, 2022

Conversation

kellpossible
Copy link
Contributor

@kellpossible kellpossible commented Jul 11, 2022

Close #201

TODO:

This work was sponsored by Arctoris.

@kellpossible kellpossible marked this pull request as ready for review July 12, 2022 03:19
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.

Awesome work. 🏆 just a few comments to clarify and this could also be merged, supposely. Also there is a need to take a rebase from the upstream. :)

src/lib.rs Outdated
/// }
/// }
/// ```
pub trait ResponseComponent {
Copy link
Owner

Choose a reason for hiding this comment

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

Just wondering should this actually just be Response instead of a ResponseComponent? Component response seems quite long name feels like little bit stuttering? Although if the name is just a Response it easily will conflict with other crates which offer types with same name.

Also wondering should the Component derive trait be renamed to Schema but it might be too big breaking change for people already using the library. Basically they would have to change it to every type they previously had Component

Copy link
Contributor Author

@kellpossible kellpossible Jul 14, 2022

Choose a reason for hiding this comment

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

Also wondering should the Component derive trait be renamed to Schema but it might be too big breaking change for people already using the library. Basically they would have to change it to every type they previously had Component

I was also tempted by this change, it would be good to make for the sake of clarity and consistency, but perhaps too big of a break? At least with renames it's usually not too difficult to fix with a grep + sed style find replace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wondering should this actually just be Response instead of a ResponseComponent? Component response seems quite long name feels like little bit stuttering? Although if the name is just a Response it easily will conflict with other crates which offer types with same name.

Sure I would be happy to rename it. If it's a conflict people can import it with a rename or with a module scope 🙂

Copy link
Owner

Choose a reason for hiding this comment

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

I was also tempted by this change, it would be good to make for the sake of clarity and consistency, but perhaps too big of a break? At least with renames it's usually not too difficult to fix with a grep + sed style find replace.

Yeah changing it within utoipa should be quite painless change except those 50 + breaking tests. 😄 Since it is also a breaking change and if wanted to make it is in fact good to do now, because there are other breaking changes pending in this next release. Then it just need to be documented to the #181 discussion. I guess we could just do it too? Should it be another PR though?

Sure I would be happy to rename it. If it's a conflict people can import it with a rename or with a module scope

Lest rename it 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's do it in a subsequent PR, seeing as it it is a rather large change!

Copy link
Owner

Choose a reason for hiding this comment

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

That looks good, do you think it might be good to represent this structure in the underlying data types using something like a ComponentsBuilder?

If something then the Comonent references should be probably renamed to Schemas. And similarly the function components_from_iter and component should be renamed to schemas_from_iter and to schema. Then it would follow the spec more closely.

Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps SchemaGenerator or something with a similar meaning

Yeah the SchemaGenerator indicate that it creates a generator object. Perhaps GenerateSchema but again it would be unnecessary long or GenSchema? Like serde's Serialize or Deserialize what would be if possible one word or as short as possible descriptive action that it would perform. Rust prefers naming traits as one verb but also or and er endings are somewhat common too. I guess ToSchema and ToResponse would be not too far fetched and sound quite reasonable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

components_from_iter and component should be renamed to schemas_from_iter and to schema. Then it would follow the spec more closely.

I've made that change in the PR for ComponentsBuilder, because it stores the components in a variable called schemas already, so I made it match.

Copy link
Contributor Author

@kellpossible kellpossible Aug 5, 2022

Choose a reason for hiding this comment

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

Yeah the SchemaGenerator indicate that it creates a generator object. Perhaps GenerateSchema but again it would be unnecessary long or GenSchema? Like serde's Serialize or Deserialize what would be if possible one word or as short as possible descriptive action that it would perform. Rust prefers naming traits as one verb but also or and er endings are somewhat common too. I guess ToSchema and ToResponse would be not too far fetched and sound quite reasonable?

I think using the full word is usually better than shortcuts because it makes the code more accessible to those who don't speak English natively (and are using translation to understand), or those who are using screen readers or dictation to work with the code. We should optimize for reading. But ToSchema and ToResponse seem like a reasonable option to me, let's go with that. I've renamed the ResponseComponent to ToResponse. I can do the Component to ToSchema rename in the next PR.

Is this PR ready now do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah you are right.. Let's get the ball rolling and get this thing to the upstream. Thanks for your work ❤️

utoipa-gen/src/openapi.rs Outdated Show resolved Hide resolved
utoipa-gen/src/path/response.rs Show resolved Hide resolved
utoipa-gen/src/schema/component.rs Outdated Show resolved Hide resolved
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.

Awesome.. 👍

@juhaku juhaku merged commit 29216ed into juhaku:master Aug 5, 2022
@kellpossible kellpossible mentioned this pull request Aug 6, 2022
3 tasks
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.

IntoResponses trait
2 participants