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

allow passing in the MaxArity for the JsonSchemaVisitor #569

Merged
merged 19 commits into from
Nov 16, 2022
Merged

Conversation

yisraelU
Copy link
Contributor

@yisraelU yisraelU commented Nov 3, 2022

I added a method build to restJsonBuilder companion to disambiguate between the apply method which has a default value.
Im trying to minimize impact on UX.
RE: #531

@@ -31,7 +31,7 @@ object Launcher extends IOApp {
val serverRes = for {
impl <- Resource.eval(ObjectServiceImpl.makeIO)
docs = smithy4s.http4s.swagger.docs[IO](ObjectService)
service <- SimpleRestJsonBuilder.routes(impl).resource
service <- SimpleRestJsonBuilder.build.routes(impl).resource
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm not sure I like the idea of building the builder like this. Seems like the ideal UX would be something like:

SimpleRestJsonBuilder.routes(impl).withMaxJsonArity(2048).resource

where the call to withMaxJsonArity is not necessary if you want to use the default.

We could also take the more flexible approach of:

SimpleRestJsonBuilder.routes(impl).withJsonCodec(myJsonCodecApi).resource

What do you think?

Copy link
Contributor Author

@yisraelU yisraelU Nov 3, 2022

Choose a reason for hiding this comment

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

I definitely agree,
The problem is that SimpleProtocolBuilder doesnt have access to the JsonCodecApi as its typed to CodecApi, so we cant access the existing codec to make a copy .
We can create a new instance of JsonCodecApi inside the builder , or allow a user to pass one in , which i think is more safe and deterministic

Copy link
Member

Choose a reason for hiding this comment

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

does it even need to be typed to JsonCodecApi? Couldn't it be just CodecApi?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kubukoz does it make sense to allow any codec on a RestJsonBuilder ?

Copy link
Member

@kubukoz kubukoz Nov 3, 2022

Choose a reason for hiding this comment

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

hmm now that you said it out loud...

I'd say not in general. But requiring a JSON codec on SimpleProtocolBuilder is worse.

Maybe let's add the method inside SRJB instead of the generic builder, then? And allow SimpleProtocolBuilder users to override the CodecAPI as they see fit (at the very least, with a protected method so that they're forced to subclass the protocol builder)

@yisraelU yisraelU marked this pull request as ready for review November 8, 2022 14:38
@@ -19,12 +19,17 @@ package http4s

import smithy4s.internals.InputOutput

object SimpleRestJsonBuilder
object SimpleRestJsonBuilder extends SimpleRestJsonBuilder(1024) {
def withMaxArity(maxArity: Int): SimpleRestJsonBuilder =
Copy link
Contributor

Choose a reason for hiding this comment

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

the method ought to go on the class, not the object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it a bit odd to be on the class ,being that the class has a maxArity parameter in the constructor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's the "fluent builder" pattern. Each withMethod is basically equivalent to a copy modifying just one field, but has the quality of being much more nicer wrt bincompat.

The point of having the method on the class is that we can add more methods later on if we need to amend the builder to carry more customisation.

@Baccata
Copy link
Contributor

Baccata commented Nov 9, 2022

Also this PR needs to be sync'd with series/0.17 to trigger CI

Copy link
Contributor

@lewisjkl lewisjkl left a comment

Choose a reason for hiding this comment

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

Let's add some documentation showing how to increase the maxArity and what that means

Comment on lines +56 to +59
new SchemaVisitorJCodec(
maxArity = defaultMaxArity,
CompilationCache.nop[JCodec]
)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this version currently used for? From a quick look it seems like only in tests. Maybe we can remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im not sure what you mean by version?

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 add some documentation showing how to increase the maxArity and what that means

good point

Copy link
Contributor

Choose a reason for hiding this comment

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

Im not sure what you mean by version?

Yeah sorry that is super confusing! I meant the "Val" vs the "def" above. The val I'm not sure is used anywhere. Thought we could remove it if that is in fact the case.

@Baccata Baccata merged commit d298d17 into series/0.17 Nov 16, 2022
@Baccata Baccata deleted the maxArity branch November 16, 2022 14:11
@Baccata Baccata added this to the 0.17.0 milestone Nov 23, 2022
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.

None yet

5 participants