Skip to content

Conversation

@kubukoz
Copy link
Member

@kubukoz kubukoz commented May 1, 2025

Workaround / fix for smithy-lang/smithy#2596. Even fixes #336.

tl;dr without passing the classloader to assembler(), we can run into strange cases where the validator gets loaded and the trait services don't - meaning the validators won't behave like they're supposed to.

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

  • 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

@kubukoz kubukoz changed the title More deterministic model loader More precise model loader May 1, 2025
// Loading the upstream model
val upstreamModel = Model
.assembler()
.assembler(validatorClassLoader)
Copy link
Member Author

Choose a reason for hiding this comment

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

This should make the classes (validators, trait services) visible to the assembler - but notably not making the models visible.

Copy link
Member Author

Choose a reason for hiding this comment

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

notably this doesn't solve the problems that #1705 and #1707 are attempting to solve, but it's a step in the right direction and doesn't clash with them

@kubukoz kubukoz changed the title More precise model loader More predictable handling of trait/validator classes model loader May 1, 2025
@kubukoz
Copy link
Member Author

kubukoz commented May 14, 2025

ok I think the easiest way to test this will be to use a custom (non-alloy) trait class in a plugin/CLI test - as proven by polyvariant/smithy4s-bsp#10 this finally allows us to use those properly.

the other thing would still be nice to test though, I'll need to think of a library that we can use as the example (or make a plugin test like that somehow)

@kubukoz kubukoz marked this pull request as ready for review May 15, 2025 00:01
@@ -0,0 +1,4 @@
# check if the app runs successfully.
# if it doesn't compile, it could be because the transformation wasn't applied.
Copy link
Member Author

Choose a reason for hiding this comment

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

thought: it is WAY too easy to misconfigure a transformation, hence this extra care

Copy link
Member Author

@kubukoz kubukoz May 15, 2025

Choose a reason for hiding this comment

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

BTW we had no other tests that involved user-provided transformations/validators, apparently. There's no software.amazon.smithy.build.ProjectionTransformer or software.amazon.smithy.model.validation.Validator in the test resources. I think these tests suffice, but maybe we should have a more minimal one for both too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe indeed

@Baccata Baccata merged commit a00a28c into series/0.18 May 15, 2025
11 checks passed
@Baccata Baccata deleted the modelloader-more-determinism branch May 15, 2025 12:17
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.

Custom library-defined traits don't work with the codegen plugin

3 participants