smithy icon indicating copy to clipboard operation
smithy copied to clipboard

Validation issue with `nestedProperties` and member elision.

Open libre-man opened this issue 1 year ago • 7 comments

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.

libre-man avatar May 21 '24 10:05 libre-man

If I add @resourceIdentifier("tenantId") to $tenantId it does work.

libre-man avatar May 21 '24 10:05 libre-man

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.

hpmellema avatar May 21 '24 12:05 hpmellema

Even adding a required trait does not help unfortunately.

libre-man avatar May 21 '24 13:05 libre-man

Same issue -- adding @required does not help, but adding @resourceIdentifier does

natehardison avatar May 23 '24 22:05 natehardison

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
}

sugmanue avatar May 23 '24 22:05 sugmanue

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.

natehardison avatar May 24 '24 00:05 natehardison

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.

medwards avatar Sep 02 '24 18:09 medwards

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.

github-actions[bot] avatar Sep 03 '25 00:09 github-actions[bot]