Steps to reproduce:
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.
When that is in place the structure then becomes:
class GetCityInput:
city_id: str
Or maybe this is by design? #182
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
GetCityInputstructure 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.classis set on the member.When that is in place the structure then becomes:
Or maybe this is by design? #182