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

Add support for @nullable trait in order to support MergePatch usecases #1408

Merged
merged 30 commits into from
Feb 27, 2024

Commits on Feb 20, 2024

  1. Add nullable support to JSON parsing

    The JSON codec will now check for a Nullable hint on the schema it is
    parsing and not immediately parse fields as None if present. Note that
    getting this to work with a new Nullable type does require adjusting
    the code checking whether a Schema is for an Option a little so that it
    can also include bijections from an option type.
    astridej committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    65e5ed1 View commit details
    Browse the repository at this point in the history
  2. Adjust codegen code to handle Nullable

    This involves totally reworking the Field.Modifier logic, as the
    addition of Nullable makes the number of cases too complex to keep track
    of in an enum alone: the modifier logic now depends on
    * whether there is a @required annotation present
    * whether there is a @nullable annotation present
    * whether there is a default value present, and (for nullable) whether
    this value is null or a concrete value
    
    making for a total of ten theoretical cases resulting in four possible
    types in the Scala code. We model this in a case class and attempt to
    shift some of the logic, such as ordering or working out the wrapped
    type, to the class itself in order to avoid other parts of the code
    needing to work with its internals.
    astridej committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    87ca4c9 View commit details
    Browse the repository at this point in the history
  3. Add nullable sample spec and smoke tests

    There is a mild tension here: on the one hand, we really want to test
    all the edge cases of different field modifier combinations to make sure
    the generation code works as wel expect. On the other, these combinations
    generally have only an extremely limited use or are just overly convoluted
    ways to specify the default behaviour, and so they shouldn't be in the
    sample specs people use to check usage. We handle this by providing two
    test cases: Patchable, which handles the merge patch behaviour this whole
    change is meant to support, and PatchableEdgeCases which is explicitly
    described as only there for testing purposes.
    astridej committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    8a64977 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    8edf430 View commit details
    Browse the repository at this point in the history
  5. Minor refactor

    astridej committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    62e4ca8 View commit details
    Browse the repository at this point in the history
  6. Scalafmt

    astridej committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    2e177fe View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    388b45e View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    67c06bc View commit details
    Browse the repository at this point in the history

Commits on Feb 21, 2024

  1. Update modules/core/src/smithy4s/Nullable.scala

    Co-authored-by: Olivier Mélois <baccata64@gmail.com>
    astridej and Baccata committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    41fb310 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5062108 View commit details
    Browse the repository at this point in the history
  3. Add tests for error messages

    The error message rendering code for custom error message fields is
    different for every type modification and also for custom vs primitive
    types - we add a test case for every combination to be absolutely sure
    they're being rendered correctly.
    astridej committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    8b42288 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e4b86e9 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    119aabf View commit details
    Browse the repository at this point in the history
  6. Remove unneeded TODO comment

    Although technically the FieldTN representations aren't correct,
    this part of the code should never use the @nullable annotation and
    it's considered acceptable to leave as is.
    astridej committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    092eab6 View commit details
    Browse the repository at this point in the history
  7. Add cats instances for Nullable

    This does not include every type class satisfied by Option but just the
    ones we think are most likely to be needed by a consumer.
    astridej committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    e387b94 View commit details
    Browse the repository at this point in the history
  8. Add test and refactor for getUnlessDefault

    We refactor foreachUnlessDefault so the logic is not duplicated across
    two methods, and add some tests to confirm that it works as expected on
    a nullable field.
    astridej committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    ef98fc2 View commit details
    Browse the repository at this point in the history
  9. Scalafmt

    astridej committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    388c1fc View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    eacf966 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    95abbc4 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    ee44174 View commit details
    Browse the repository at this point in the history

Commits on Feb 22, 2024

  1. Add support for Nullable in dynamic module

    Including tests to make sure all traits and schemas behave as expected -
    this does unfortunately require trying to figure out whether a schema is
    Nullable at runtime, which is an awkward process.
    astridej committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    c6be356 View commit details
    Browse the repository at this point in the history
  2. Scalafmt

    astridej committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    2dbb0bb View commit details
    Browse the repository at this point in the history
  3. Fix trait reference in dynamic module

    Not 100% sure why this compiled locally, but it looks like this should
    fix it?
    astridej committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    d0926e8 View commit details
    Browse the repository at this point in the history
  4. Revert extra handling of default in dynamic module

    It's acceptable for fields with a default value to be wrapped in Option
    in the dynamically generated code, and trying to align it with the
    static codegen behaviour is causing problems in the compliance tests.
    We remove that change and any tests that relied on it.
    astridej committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    8344e40 View commit details
    Browse the repository at this point in the history
  5. Add docs for @nullable

    astridej committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    b2ae9d7 View commit details
    Browse the repository at this point in the history

Commits on Feb 23, 2024

  1. Scalafmt, redux

    Apparently 2.13 is more picky about line length for scalafmt than the
    other Scala versions, and I hadn't formatted the test files right - this
    should fix it.
    astridej committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    67ae7ba View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b3f7996 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    85da837 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    c268f7c View commit details
    Browse the repository at this point in the history

Commits on Feb 26, 2024

  1. Update modules/docs/markdown/04-codegen/01-customisation/13-nullable-…

    …values.md
    
    Co-authored-by: Olivier Mélois <baccata64@gmail.com>
    astridej and Baccata committed Feb 26, 2024
    Configuration menu
    Copy the full SHA
    7c44617 View commit details
    Browse the repository at this point in the history