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

Default handling #1315

Merged
merged 10 commits into from
Jan 19, 2024
Merged

Conversation

msosnicki
Copy link
Contributor

@msosnicki msosnicki commented Nov 27, 2023

PR Checklist (not all items are relevant to all PRs)

Closes #1290

  • Added unit-tests (for runtime code)
  • Added bootstrapped code + smoke tests (when the rendering logic is modified)
  • Added build-plugins integration tests (when reflection loading is required at codegen-time)
  • Added alloy compliance tests (when simpleRestJson protocol behaviour is expanded/updated)
  • Updated dynamic module to match generated-code behaviour
  • Added documentation
  • Updated changelog

@msosnicki msosnicki changed the title WIP Default handling Nov 27, 2023
}
}

test("document encoder - all default") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: Do we need a flag to control the Document.Encoder behavior?

Copy link
Member

Choose a reason for hiding this comment

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

imo yes

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 think this will be a breaking change, it requires changing DocumentEncoderSchemaVisitor, which is public.

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering it's in internals, we deem it's okay to break. If you're a third party who depends on what's in an internals package, it's your funeral.

Moreover, the reason we've not been ultra strict wrt private/public is because of a drastic lack of tooling that would help us do so. We'd like to build such tooling (probably by means of scalafix)

But I think it'd be totally possible to retain binary compatibility by means of secondary constructors.

Copy link
Member

Choose a reason for hiding this comment

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

ah, I didn't realize it was in internals. Alright then

) {
type Compiler = CachedSchemaCompiler[Encoder]

def make(
Copy link
Contributor

@Baccata Baccata Jan 5, 2024

Choose a reason for hiding this comment

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

not a fan of this. awsHeaderEncoding shouldn't be exposed to the users here.

Also, the UX I'd like would be : Encoder.withExplicitDefaultsEncoding(true). The CachedEncoderCompilerImpl class should carry the method, which implies that we need to create an public interface for this that it will implement (as CachedEncoderCompilerImpl is private).

Also this make method should be removed.

def fromSchema[A](
schema: Schema[A],
cache: Cache,
explicitDefaultsEncoding: Boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly to my comment here, this method should be removed in favour of a withExplicitDefaultsEncoding(explicitDefaults: Boolean) on the Encoder.

This implies the creation of public interface. You can take this as inspiration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one problem with the above approach, currently, the following doesn't compile:

Json.jsoniter.withMaxArity(1).fromSchema(Schema.string, CompilationCache.nop)

This is because JsoniterCodecCompiler inherits abstract type Cache type, wheareas in CachedSchemaCompiler.Impl it is set to type Cache = CompilationCache[Aux]. So the information about cache is lost when calling methods from JsoniterCodecCompiler.

Is it a known limitation?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a bug, it's a feature 😄

If you want to compile a codec without cache, you should be able to call

Json.jsoniter.withMaxArity(1).fromSchema(Schema.string)

Otherwise, if you wanted to use a shared cache across several codec compilations, you would have to do :

val compiler = Json.jsoniter.withMaxArity(1) 
val cache = compiler.createCache() 
val stringCodec = compiler.fromSchema(Schema.string, cache) 

)
}

test("document encoder - all default - explicit defaults encoding = true") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go in the DocumentSpec in the bootstrapped module.

)
}

test("document encoder - default overrides") {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go in the DocumentSpec in the bootstrapped module.

Copy link
Contributor

@Baccata Baccata left a comment

Choose a reason for hiding this comment

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

Good work overall, but the UX needs to be addressed. Also a couple tests need to be moved

@msosnicki
Copy link
Contributor Author

@Baccata addressed all the comments, not sure if EncoderCompilers should stay where they are or should be moved somewhere.

@Baccata
Copy link
Contributor

Baccata commented Jan 16, 2024

@kubukoz do you want to review again ? In particular, do you want more documentation ? I wouldn't mind having more of it

@kubukoz
Copy link
Member

kubukoz commented Jan 16, 2024

@kubukoz do you want to review again ? In particular, do you want more documentation ? I wouldn't mind having more of it

I'm happy with the current state, but some docs for the Document encoding/decoding would be welcome. I think that doesn't exist at all, though, so let's make it a separate issue which will cover the basics and the config options.

Copy link
Member

@kubukoz kubukoz left a comment

Choose a reason for hiding this comment

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

Needs a changelog entry

@msosnicki
Copy link
Contributor Author

Needs a changelog entry

Done

@kubukoz
Copy link
Member

kubukoz commented Jan 19, 2024

Needs a changelog entry

Done

didn't notice this 😭 thanks, LGTM

@kubukoz kubukoz merged commit 2a5007a into disneystreaming:series/0.18 Jan 19, 2024
11 checks passed
Baccata added a commit that referenced this pull request Jan 26, 2024
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.

Support configuration of explicit defaults in more encoders
3 participants