Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct issues and bugs with neighbor traversal #2020

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 39 additions & 48 deletions docs/source-1.0/spec/core/selectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1151,61 +1151,50 @@ The table below lists the labeled directed relationships from each shape.
- Description
* - service
- operation
- Each operation that is bound to a service.
- Each operation bound to a service.
* - service
- resource
- Each resource that is bound to a service.
- Each resource bound to a service.
* - service
- error
- Each error structure referenced by the service (if present).
- Each error structure referenced by the service.
* - resource
- identifier
- The identifier referenced by the resource (if specified).
- Each identifier shape of a resource.
* - resource
- operation
- Each operation that is bound to a resource through the
"operations", "create", "put", "read", "update", "delete", and "list"
properties.
- property
- Each property shape of a resource.
* - resource
- instanceOperation
- Each operation that is bound to a resource through the
"operations", "put", "read", "update", and "delete" properties.
- resource
- Each resource bound to a resource.
* - resource
- collectionOperation
- Each operation that is bound to a resource through the
"collectionOperations", "create", and "list" properties.
- operation
- Each operation bound to a resource through the "operations" property.
* - resource
- resource
- Each resource that is bound to a resource.
- collectionOperation
- Each operation bound to a resource through the "collectionOperations"
property.
* - resource
- create
- The operation referenced by the :ref:`create-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`create-lifecycle` of a resource.
* - resource
- read
- The operation referenced by the :ref:`read-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`read-lifecycle` of a resource.
* - resource
- update
- The operation referenced by the :ref:`update-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`update-lifecycle` of a resource.
* - resource
- delete
- The operation referenced by the :ref:`delete-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`delete-lifecycle` of a resource.
* - resource
- list
- The operation referenced by the :ref:`list-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`list-lifecycle` of a resource.
* - resource
- bound
- The service or resource to which the resource is bound.
* - operation
- bound
- The service or resource to which the operation is bound.
- put
- The operation defined as the :ref:`put-lifecycle` of a resource.
* - operation
- input
- The input structure of the operation (if present).
- The input structure of an operation.

.. note::

Expand All @@ -1214,7 +1203,7 @@ The table below lists the labeled directed relationships from each shape.

* - operation
- output
- The output structure of the operation (if present).
- The output structure of an operation.

.. note::

Expand All @@ -1223,23 +1212,25 @@ The table below lists the labeled directed relationships from each shape.

* - operation
- error
- Each error structure referenced by the operation (if present).
- Each error structure of an operation.
* - list
- member
- The :ref:`member` of the list. Note that this is not the shape targeted
by the member.
- The :ref:`member <member>` of a list.
* - map
- member
- The key and value members of the map. Note that these are not the
shapes targeted by the member.
- The key and value members of a map.
* - structure
- member
- Each structure member. Note that these are not the shapes targeted by
the members.
- Each structure member.
* - union
- member
- Each union member. Note that these are not the shapes targeted by
the members.
- Each union member.
* - enum
- member
- Each enum member.
* - intEnum
- member
- Each intEnum member.
* - member
-
- The shape targeted by the member. Note that member targets have no
Expand All @@ -1249,13 +1240,13 @@ The table below lists the labeled directed relationships from each shape.
- Each trait applied to a shape. The neighbor shape is the shape that
defines the trait. This kind of relationship is only traversed if the
``trait`` relationship is explicitly stated as a desired directed
neighbor relationship type.
neighbor relationship type (for example, ``-[trait]->``).

.. important::
.. note::

Implementations MUST tolerate parsing unknown relationship types. When
evaluated, the directed traversal of unknown relationship types yields
no shapes.
Implementations MAY tolerate parsing unknown relationship types. When
evaluated, the traversal of unknown relationship types SHOULD yield
nothing.


Functions
Expand Down Expand Up @@ -1300,7 +1291,7 @@ no documentation:

.. code-block:: none

:test(-[bound, resource]->)
:test(resource >)
:not([trait|documentation])


Expand Down
96 changes: 41 additions & 55 deletions docs/source-2.0/spec/selectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,8 @@ Forward undirected neighbor
----------------------------

A :token:`forward undirected neighbor <selectors:SelectorForwardUndirectedNeighbor>`
(``>``) yields every shape that is connected to the current shape. For
example, the following selector matches the key and value members of
every map:
(``>``) yields every shape referred to by the current shape. For example, the
following selector matches the key and value members of every map:

.. code-block:: none

Expand All @@ -1020,7 +1019,7 @@ Forward directed neighbors

The forward undirected neighbor selector (``>``) is an *undirected* edge
traversal. Sometimes, a directed edge traversal is necessary. For example,
the following selector matches the "bound", "input", "output", and "error"
the following selector matches the "input", "output", "error", and "mixin"
relationships of each operation:

.. code-block:: none
Expand Down Expand Up @@ -1159,64 +1158,50 @@ The table below lists the labeled directed relationships from each shape.
- Description
* - service
- operation
- Each operation that is bound to a service.
- Each operation bound to a service.
* - service
- resource
- Each resource that is bound to a service.
- Each resource bound to a service.
* - service
- error
- Each error structure referenced by the service (if present).
- Each error structure referenced by the service.
* - resource
- identifier
- An identifier referenced by the resource (if specified).
- Each identifier shape of a resource.
* - resource
- property
- A property referenced by the resource.
- Each property shape of a resource.
* - resource
- operation
- Each operation that is bound to a resource through the
"operations", "create", "put", "read", "update", "delete", and "list"
properties.
- resource
- Each resource bound to a resource.
* - resource
- instanceOperation
- Each operation that is bound to a resource through the
"operations", "put", "read", "update", and "delete" properties.
- operation
- Each operation bound to a resource through the "operations" property.
* - resource
- collectionOperation
- Each operation that is bound to a resource through the
"collectionOperations", "create", and "list" properties.
* - resource
- resource
- Each resource that is bound to a resource.
- Each operation bound to a resource through the "collectionOperations"
property.
* - resource
- create
- The operation referenced by the :ref:`create-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`create-lifecycle` of a resource.
* - resource
- read
- The operation referenced by the :ref:`read-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`read-lifecycle` of a resource.
* - resource
- update
- The operation referenced by the :ref:`update-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`update-lifecycle` of a resource.
* - resource
- delete
- The operation referenced by the :ref:`delete-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`delete-lifecycle` of a resource.
* - resource
- list
- The operation referenced by the :ref:`list-lifecycle` property of
a resource (if present).
- The operation defined as the :ref:`list-lifecycle` of a resource.
* - resource
- bound
- The service or resource to which the resource is bound.
* - operation
- bound
- The service or resource to which the operation is bound.
- put
- The operation defined as the :ref:`put-lifecycle` of a resource.
* - operation
- input
- The input structure of the operation (if present).
- The input structure of an operation.

.. note::

Expand All @@ -1225,7 +1210,7 @@ The table below lists the labeled directed relationships from each shape.

* - operation
- output
- The output structure of the operation (if present).
- The output structure of an operation.

.. note::

Expand All @@ -1234,23 +1219,25 @@ The table below lists the labeled directed relationships from each shape.

* - operation
- error
- Each error structure referenced by the operation (if present).
- Each error structure of an operation.
* - list
- member
- The :ref:`member` of the list, including if it was inherited from a
mixin. Note that this is not the shape targeted by the member.
- The :ref:`member <member>` of a list.
* - map
- member
- The key and value members of the map, including those inherited from
mixins. Note that these are not the shapes targeted by the member.
- The key and value members of a map.
* - structure
- member
- Each structure member, including members inherited from mixins. Note
that these are not the shapes targeted by the members.
- Each structure member.
* - union
- member
- Each union member, including members inherited from mixins. Note that
these are not the shapes targeted by the members.
- Each union member.
* - enum
- member
- Each enum member.
* - intEnum
- member
- Each intEnum member.
* - member
-
- The shape targeted by the member. Note that member targets have no
Expand All @@ -1260,21 +1247,21 @@ The table below lists the labeled directed relationships from each shape.
- Each trait applied to a shape. The neighbor shape is the shape that
defines the trait. This kind of relationship is only traversed if the
``trait`` relationship is explicitly stated as a desired directed
neighbor relationship type.
neighbor relationship type (for example, ``-[trait]->``).
* - ``*``
- mixin
- Every mixin applied to the shape.

.. note::

A normal ``member`` relationship exists from a given shape to all
its inherited mixin members.
its mixed in members.

.. important::
.. note::

Implementations MUST tolerate parsing unknown relationship types. When
evaluated, the directed traversal of unknown relationship types yields
no shapes.
Implementations MAY tolerate parsing unknown relationship types. When
evaluated, the traversal of unknown relationship types SHOULD yield
nothing.


Functions
Expand Down Expand Up @@ -1319,8 +1306,7 @@ no documentation:

.. code-block:: none

:test(-[bound, resource]->)
:not([trait|documentation])
:test(< resource) :not([trait|documentation])


``:is``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.neighbor.NeighborProvider;
import software.amazon.smithy.model.neighbor.Relationship;
import software.amazon.smithy.model.neighbor.RelationshipType;
import software.amazon.smithy.model.neighbor.Walker;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ResourceShape;
Expand All @@ -48,18 +49,8 @@ public TopDownIndex(Model model) {

// Only traverse resource and operation bindings.
Predicate<Relationship> filter = rel -> {
switch (rel.getRelationshipType()) {
case RESOURCE:
case OPERATION:
case CREATE:
case READ:
case UPDATE:
case DELETE:
case LIST:
return true;
default:
return false;
}
RelationshipType type = rel.getRelationshipType();
return type == RelationshipType.RESOURCE || type.isOperationBinding();
};

for (ResourceShape resource : model.getResourceShapes()) {
Expand Down
Loading
Loading