You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cd smithy-python/codegen
./gradlew smithy-python-codegen-test:build
This produces the file: smithy-python/codegen/smithy-python-codegen-test/build/smithyprojections/smithy-python-codegen-test/source/python-client-codegen/weather/models.py.
Looking at the GetCityInput structure you will see showing that city_id is not required because it allows None.
class GetCityInput:
city_id: str | None = None
The smithy model for GetCityInput shows:
@http(method: "GET", uri: "/cities/{cityId}")
operation GetCity {
input := {
// "cityId" provides the identifier for the resource and
// has to be marked as required.
@required
@httpLabel
cityId: CityId
}
The determination to see if a field is required is done in StructureGenerator.java.
var required = new ArrayList<MemberShape>();
var optional = new ArrayList<MemberShape>();
var index = NullableIndex.of(context.model());
for (MemberShape member: shape.members()) {
if (index.isMemberNullable(member) || member.hasTrait(DefaultTrait.class)) {
optional.add(member);
} else {
required.add(member);
}
}
isMemberNullable is returning True for the cityId, and therefore is marked as optional.
I'll PR adding an additional check to see if the RequiredTrait.class is set on the member.
This is by design. When you use the inline syntax for creating an input structure (:=), the structure created has the @input trait, which changes nullability for the sake of backwards compatibility.
Steps to reproduce:
This produces the file:
smithy-python/codegen/smithy-python-codegen-test/build/smithyprojections/smithy-python-codegen-test/source/python-client-codegen/weather/models.py
.Looking at the
GetCityInput
structure you will see showing that city_id is not required because it allows None.The smithy model for GetCityInput shows:
The determination to see if a field is required is done in
StructureGenerator.java
.isMemberNullable is returning True for the cityId, and therefore is marked as optional.
I'll PR adding an additional check to see if the
RequiredTrait.class
is set on the member.When that is in place the structure then becomes:
Or maybe this is by design? #182
The text was updated successfully, but these errors were encountered: