Skip to content

Question about input trait that implies clientOptional on required fields #3203

Description

@timocov

Hi team,

Sorry for a bit weird title and it is probably just very stupid question, please bear with me.

Based on https://smithy.io/2.0/spec/type-refinement-traits.html#input-trait:

Required members of a structure marked with the @input trait are implicitly considered clientOptional

clientOptional on the other hand:

Requires that non-authoritative generators like clients treat a structure member as optional regardless of if the member is also marked with the required trait or default trait.

So if I have the following model:

operation GetItem {
    input := {
        @required
        itemId: String
    }
}

Based on the documentation above, itemId shouldn't be considered to be required from the client side, but it should be treated as such from the server side.

I understand that intention is to prevent breaking changes, but if later I decide to add another input:

operation GetItem {
    input := {
        @required
        itemId: String

        @required
        category: String
    }
}

And if I run smithy diff tool for this model against the one above - it won't report any breaking changes because category: String is implicitly marked as clientOptional, but if you make a call without this field from the client side - it will result in a request rejection because the server requires this field (it doesn't have a default value nor it is optional). To me it feels like implicitly adding clientOptional to all required fields hides the backward compatibility issue that could have been detected with diff tool, but it wasn't because of clientOptional.

I understand that if you re-use types between inputs and outputs, then having clientOptional on required fields makes sense - a field always returned/generated by the server can be optional for the client to provide (or even ignored by the server if provided). But @input explicitly disallows using the type it is attached to as an output or in other operations.

So I'm a bit confused why @input should imply clientOptional and what potential problems it prevents (if you can give some examples that would be awesome).

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions