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

customization of default rendering #414

Merged
merged 7 commits into from
Aug 29, 2022
Merged

customization of default rendering #414

merged 7 commits into from
Aug 29, 2022

Conversation

lewisjkl
Copy link
Contributor

Allows rendering defaults in three different modes: FULL, OPTION_ONLY, NONE.

See docs in PR for full explanation.

```kotlin
use smithy4s.meta#defaultRender

@defaultRender(mode: "FULL")
Copy link
Contributor

@Baccata Baccata Aug 26, 2022

Choose a reason for hiding this comment

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

not quite sure it should be a trait. The preference probably applies to all case classes that users generate, so I'm thinking it should be a piece of metadata instead, that'd apply globally.

Now the problem is that the rendering of trait values relies on the ordering of parameters. We might want to change it to named parameters instead, which would remove the need to know which ordering was applied during the rendering of upstream namespaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

two things:

  1. preference probably applies to all case classes

The opposite could be just as true I guess, some people may want to change the behaviour for one specific case class.

  1. the rendering of trait values relies on the ordering of parameters

I don't understand what you mean by the rendering of trait values in this context, do you have an example?

Copy link
Contributor

@Baccata Baccata Aug 26, 2022

Choose a reason for hiding this comment

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

  1. we have optimise user-facing features in terms of what most users will benefit from. Though you are not technically incorrect, I'm pretty sure that if someone dislikes default values in one case, they'll dislike default values in all cases, because default values have very tangible downsides to them. Therefore, it's likely that a piece of UX that would allow to disable defaults altogether across the whole code-gen pipeline, people who dislike defaults will be happy about the low-boilerplate solution. They will be less happy about having to annotate all of their shapes.
  2. I meant rendering of hints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points, I forgot that we had talked about using the metadata for this. I'll update the PR with that and using named parameters in hints 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in: 0b9d512

lmk if this doesn't match what you are talking about wrt the named parameters in hints

Copy link
Contributor

Choose a reason for hiding this comment

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

lmk if this doesn't match what you are talking about wrt the named parameters in hints

It is indeed

`FULL` means that default values are rendered for all field types. For example:

```kotlin
metadata defaultRenderMode = "FULL"
Copy link
Contributor

Choose a reason for hiding this comment

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

All the metadata bits that smithy4s surfaces/uses should be prefixed with smithy4s one way or another. If . are allowed in metadata keys, we could make it smithy4s.defaultRenderMode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, dots aren't allowed. But I changed it to smithy4sDefaultRenderMode

@@ -11,3 +13,10 @@ structure DefaultTest {
two: String = "test"
three: StringList = []
}

structure DefaultOrderingTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mmm, I think it might be a good opportunity to add unit tests in the codegen module, since relying on our usual smoke-test way of doing things ain't gonna work (as metadata is meant to be unique across a smithy model).

Would you mind adding such a unit test, a little bit like the smithy-translate ones, where we dynamically parse a model and run it through the codegen pipeline, and assert that the output code is what we think it should be ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good idea, will add 👍

@Baccata Baccata merged commit ae73ce5 into main Aug 29, 2022
@Baccata Baccata deleted the default-customization branch August 29, 2022 18:36
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.

4 participants