smithy
smithy copied to clipboard
Validation issue with `nestedProperties` and member elision.
I have a resource like this:
string TenantId
resource TenantResource {
identifiers: { tenantId: TenantId }
read: GetTenant
}
And the following models:
@output
structure GetTenantResponse {
@required
@nestedProperties
@httpPayload
tenant: Tenant
}
structure Tenant for TenantResource {
$tenantId
}
When compiling this I get: Member tenantId does not target a property or identifier for resource TenantResource.
When I remove the nestedProperties trait I don't get this error anymore.
If I add @resourceIdentifier("tenantId") to $tenantId it does work.
I suspect the root issue here is that the $tenantId field is missing a @required trait. Elided resource Identifiers should always be required fields. The error messages returned for elided identifiers are currently a bit unclear and probably need to be updated.
Even adding a required trait does not help unfortunately.
Same issue -- adding @required does not help, but adding @resourceIdentifier does
Thomas and Nate
Care to provide a self-contained minimal model we can use to reproduce the issue?
I just tried with this and validates just fine:
$version: "2"
namespace com.example
string TenantId
resource TenantResource {
identifiers: { tenantId: TenantId }
read: GetTenant
}
@readonly
operation GetTenant {
input: GetTenantRequest
output: GetTenantResponse
}
@input
structure GetTenantRequest for TenantResource {
@required
$tenantId
}
@output
structure GetTenantResponse {
@required
@nestedProperties
@httpPayload
tenant: Tenant
}
structure Tenant for TenantResource {
$tenantId
}
Sure, building off of @libre-man's starting point:
$version: "2"
namespace com.example
string TenantId
resource TenantResource {
identifiers: { tenantId: TenantId }
properties: { name: String }
read: GetTenant
}
@readonly
operation GetTenant {
input := for TenantResource {
@required
$tenantId
}
output := for TenantResource {
@required
@nestedProperties
data: Tenant
}
}
structure Tenant for TenantResource {
$tenantId
$name
}
example validation fail:
smithy validate example.smithy
── ERROR ──────────────────────────────────────── ResourceOperationInputOutput
Shape: com.example#Tenant$tenantId
File: example.smithy:29:5
28| structure Tenant for TenantResource {
29| $tenantId
| ^
Member tenantId does not target a property or identifier for resource
com.example#TenantResource
FAILURE: Validated 226 shapes (ERROR: 1)
Notably, if I remove the properties field entirely from TenantResource, then things validate just fine.
Am using Smithy version 1.49.0.
I don't think this is the same as libre-man's model. If you remove nestedProperties you get
Member data does not target a property or identifier for resource com.example#TenantResource
but "When I remove the nestedProperties trait I don't get this error anymore."
I found this issue because of the "Member data does not target" error. It may not be the same root cause as libre-man but I found closely reading Resource property binding validation to be very helpful in figuring out what was wrong.
We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.