-
Notifications
You must be signed in to change notification settings - Fork 69
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
Changes from 1 commit
848cad8
1ee1876
296711d
ae94c4d
11ad06b
fe7dd01
046a4f9
90af9d8
30c8e1c
8b2085c
2d9ba19
31a737e
d28ed75
5485d41
be2c463
0c112da
bdcdcbc
7237dd4
f58aacf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,11 @@ import smithy4s.schema.SchemaVisitor | |
import smithy4s.schema.CompilationCache | ||
|
||
final case class codecs( | ||
hintMask: HintMask = codecs.defaultHintMask | ||
) extends JsonCodecAPI(codecs.schemaVisitorJCodec(_), Some(hintMask)) | ||
hintMask: HintMask = codecs.defaultHintMask, | ||
maxArity: Int = codecs.defaultMaxArity | ||
) extends JsonCodecAPI(codecs.schemaVisitorJCodec(_, maxArity), Some(hintMask)){ | ||
def withMaxArity(maxArity: Int): codecs = copy(maxArity = maxArity) | ||
} | ||
|
||
object codecs { | ||
|
||
|
@@ -43,13 +46,18 @@ object codecs { | |
// TODO: add tests for `codecs` understanding int enums. Maybe pizza spec | ||
IntEnum | ||
) | ||
val defaultMaxArity: Int = 1024 | ||
|
||
private[smithy4s] def schemaVisitorJCodec( | ||
cache: CompilationCache[JCodec] | ||
): SchemaVisitor[JCodec] = | ||
new SchemaVisitorJCodec(maxArity = 1024, cache) | ||
cache: CompilationCache[JCodec], | ||
maxArity: Int = defaultMaxArity | ||
): SchemaVisitor[JCodec] = | ||
new SchemaVisitorJCodec(maxArity, cache) | ||
|
||
private[smithy4s] val schemaVisitorJCodec: SchemaVisitor[JCodec] = | ||
new SchemaVisitorJCodec(maxArity = 1024, CompilationCache.nop[JCodec]) | ||
new SchemaVisitorJCodec( | ||
maxArity = defaultMaxArity, | ||
CompilationCache.nop[JCodec] | ||
) | ||
Comment on lines
+56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im not sure what you mean by version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
good point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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. |
||
|
||
} |
There was a problem hiding this comment.
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:
where the call to
withMaxJsonArity
is not necessary if you want to use the default.We could also take the more flexible approach of:
What do you think?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 justCodecApi
?There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)