Skip to content

Commit

Permalink
Add IDL version 0.5.0
Browse files Browse the repository at this point in the history
- Remove onVersion since LoaderVisitor is version independent
- Simplify ModelLoader and use InputStream. This commit simplifies
  ModelLoader to be a single class with static methods rather than a
  series of internal-only ModelLoader interfaces. Further, it converts
  model loading to using InputStreams rather than Strings so that files
  can be parsed and streamed directly from their source rather than first
  loaded into a string and then into a Model. We should follow up on this
  by making the SmithyModelLexer streaming too.
- Update specification for 0.5.0 IDL
  • Loading branch information
mtdowling committed Dec 12, 2019
1 parent cc234f0 commit f37dedb
Show file tree
Hide file tree
Showing 49 changed files with 1,235 additions and 1,142 deletions.
2 changes: 1 addition & 1 deletion aws/smithy-aws-traits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See the Smithy specification for details on how these traits are used.
Example usage:

```smithy
$version: "0.4.0"
$version: "0.5.0"
namespace ns.foo
@aws.api#service(sdkId: "Some Value")
Expand Down
52 changes: 13 additions & 39 deletions docs/source/spec/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,8 @@ Version compatibility

A single version statement can appear in a model file. Different versions MAY
be encountered when merging multiple model files together. Multiple versions
are supported if and only if all of the version statements are compatible
according to the following constraints:

1. Each version MUST specify the same major version number. For example,
``0.2.0`` and ``1.0.0`` are **not** compatible because they use different
major version numbers.
2. When dealing with a major version of "0" (for example, ``0.2.0``), versions
that use the same minor version are considered compatible regardless of the
patch version. For example, if models are loaded that use a version of
``0.2.0``, ``0.1.1``, and ``0.1.2``, then all of the models are considered
to be compatible. However, ``0.2.0`` and ``0.1.99`` are **not** compatible.
3. When dealing with a major version of "1" or higher, all versions that use
the same major version number are considered compatible. For example, if
models are loaded that use a version of ``1.0.0``, ``1.0.1``, and
``1.1.0``, then all of the models are considered to be compatible.
However, ``1.0.0`` and ``2.0.0`` are **not** compatible.
are supported if and only if all of the version statements are supported by
the tool loading the models.


.. _metadata:
Expand All @@ -114,6 +100,8 @@ Model metadata
to a model using a :ref:`metadata statement <metadata-statement>`. Metadata
statements start with ``metadata``, followed by the key to set, followed by
``=``, followed by the JSON-like :ref:`node value <node-values>` to assign.
Metadata statements MUST appear before any namespace statements or shapes
are defined.

.. tabs::

Expand Down Expand Up @@ -155,20 +143,18 @@ models without naming conflicts.

A :ref:`namespace statement <namespace-statement>` is used to change the
*current namespace*. A namespace MUST be defined before a shape can be
defined. Any number of namespaces can appear in a model.
defined. Only a single namespace can appear in an IDL model file, but any
number of namespaces can appear in a JSON AST model file.

The following example defines a string shape named ``MyString`` in the
``smithy.example`` namespace and a string shape named ``MyString`` in the
``another.example`` namespace:
``smithy.example`` namespace:

.. tabs::

.. code-tab:: smithy

namespace smithy.example
string MyString

namespace another.example
string MyString

.. code-tab:: json
Expand All @@ -178,9 +164,6 @@ The following example defines a string shape named ``MyString`` in the
"shapes": {
"smithy.example#MyString": {
"type": "string"
},
"another.example#MyString": {
"type": "string"
}
}
}
Expand Down Expand Up @@ -2378,30 +2361,21 @@ Consider the following metadata definition:

.. code-block:: smithy
namespace smithy.example
metadata foo = {
MyString: MyString,
String: String,
}
string MyString
The object key remains the same literal string value while the value is
treated as a shape ID and resolves to the string literal
``"smithy.example#MyString"``. This IDL model is equivalent to the
following JSON AST model:
The object key remains the same literal string value of ``String`` while the
value is treated as a shape ID and resolves to the string literal
``"smithy.api#String"``. This IDL model is equivalent to the following
JSON AST model:

.. code-block:: json
{
"smithy": "0.5.0",
"shapes": {
"smithy.example#MyString": {
"type": "string"
}
},
"metadata": {
"MyString": "smithy.example#MyString"
"String": "smithy.api#String"
}
}
Expand Down
47 changes: 25 additions & 22 deletions docs/source/spec/language-specification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Version statement

The version control statement is used to set the :ref:`version <smithy-version>`
of a Smithy model file. The value of a version statement MUST be a string.
Only a single version statement can appear in a model file.

Example:

Expand Down Expand Up @@ -133,7 +134,27 @@ Example:
metadata example.null = null

Top-level metadata key-value pair conflicts are resolved by
:ref:`merging metadata <merging-metadata>`
:ref:`merging metadata <merging-metadata>`. Metadata statements MUST appear
before any namespace statements or shapes are defined.


.. _namespace-statement:

Namespace statement
-------------------

The namespace statement is used to set the *current namespace*. Shapes
can only be defined if a current namespace is defined. Only a single
namespace can appear in an IDL model file.

.. productionlist:: smithy
namespace_statement :"namespace" `namespace`

Example:

::

namespace com.foo.baz


.. _use-statement:
Expand All @@ -142,8 +163,9 @@ Use statement
-------------

A use statement is used to import shapes and traits into the current namespace
so that they can be referred to using relative shape. A use statement MUST come
before any shapes are defined in an IDL model file.
so that they can be referred to using relative shape. A use statement MUST
come after a :ref:`namespace statement <namespace-statement>` and before any
shapes are defined in an IDL model file.

.. productionlist:: smithy
use_statement :"use" `absolute_shape_id`
Expand Down Expand Up @@ -189,25 +211,6 @@ See :ref:`relative-shape-id` for an in-depth description of how relative
shape IDs are resolved in the IDL.


.. _namespace-statement:

Namespace statement
-------------------

The namespace statement is used to set the *current namespace*. Shapes
can only be defined if a current namespace is defined. Any number of namespace
statements can appear in a model.

.. productionlist:: smithy
namespace_statement :"namespace" `namespace`

Example:

::

namespace com.foo.baz


Shape statements
----------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ enum AstModelLoader {
void load(ObjectNode model, StringNode version, LoaderVisitor visitor) {
model.expectNoAdditionalProperties(TOP_LEVEL_PROPERTIES);
visitor.onOpenFile(model.getSourceLocation().getFilename());
visitor.onVersion(version.getSourceLocation(), version.expectStringNode().getValue());
loadMetadata(model, visitor);
loadShapes(model, visitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ void load(ObjectNode model, StringNode version, LoaderVisitor visitor) {
+ "(" + version.getSourceLocation() + ")");

visitor.onOpenFile(model.getSourceLocation().getFilename());
visitor.onVersion(version.getSourceLocation(), version.expectStringNode().getValue());

try {
model.getMember(METADATA).ifPresent(value -> {
ObjectNode metadata = value.expectObjectNode("`metadata` must be an object");
Expand Down
Loading

0 comments on commit f37dedb

Please sign in to comment.