Skip to content

Commit

Permalink
Make IDL commas whitespace and newlines optional
Browse files Browse the repository at this point in the history
Commas are now treated as whitespace to reduce visual noise in models,
reduce diff noise when changes are made to models, and prevent modelers
from worrying about tricks like trailing commas. Commas are still
allowed because they do make traits and JSON-like node values defined on
a single line easier to read; however, they should be omitted everywhere
else.

The IDL previously required a newline after various statements. This
wasn't grammatically necessary, but was done to force good practice in
models. However, it added complexity to the grammar and parser. While
models should still define all statements on different lines, to simplify
parsers and the grammar, a new line after statements is no longer
required.
  • Loading branch information
mtdowling committed Apr 16, 2021
1 parent 4e6a363 commit 0eed31b
Show file tree
Hide file tree
Showing 53 changed files with 1,394 additions and 1,327 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ shapes.
namespace example.weather
service Weather {
version: "2006-03-01",
resources: [City],
version: "2006-03-01"
resources: [City]
operations: [GetCurrentTime]
}
resource City {
identifiers: { cityId: CityId },
read: GetCity,
list: ListCities,
resources: [Forecast],
identifiers: { cityId: CityId }
read: GetCity
list: ListCities
resources: [Forecast]
}
// See the full example at https://awslabs.github.io/smithy/quickstart.html#complete-example
Expand Down
19 changes: 10 additions & 9 deletions docs/source/1.0/guides/converting-to-openapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ For example, given the following Smithy model:
@restJson1
@httpApiKeyAuth(name: "x-api-key", in: "header")
service Foo {
version: "2006-03-01",
operations: [ExampleOperation],
version: "2006-03-01"
operations: [ExampleOperation]
}
@http(method: "GET", uri: "/")
Expand Down Expand Up @@ -957,12 +957,13 @@ The following Smithy model:
@sigv4(name: "service")
@authorizer("foo")
@authorizers(
foo: {scheme: sigv4, type: "aws", uri: "arn:foo"},
baz: {scheme: sigv4, type: "aws", uri: "arn:foo"})
foo: {scheme: sigv4, type: "aws", uri: "arn:foo"}
baz: {scheme: sigv4, type: "aws", uri: "arn:foo"}
)
service Example {
version: "2019-06-17",
operations: [OperationA, OperationB],
resources: [ResourceA, ResourceB],
version: "2019-06-17"
operations: [OperationA, OperationB]
resources: [ResourceA, ResourceB]
}
// Inherits the authorizer of the service
Expand Down Expand Up @@ -1205,8 +1206,8 @@ The following Smithy model enables API Gateway's API key usage plans on the
@authorizer("api_key")
@authorizers(api_key: {scheme: "smithy.api#httpApiKeyAuth"})
service Example {
version: "2019-06-17",
operations: [OperationA],
version: "2019-06-17"
operations: [OperationA]
}
operation OperationA {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ generate one Resource Schema with the ``typeName`` of ``AWS:Queues:Queue``.
@service(sdkId: "Queues", cloudFormationName: "Queues")
service QueueService {
version: "2020-07-02",
resources: [Queue],
version: "2020-07-02"
resources: [Queue]
}
.. important::
Expand Down
26 changes: 13 additions & 13 deletions docs/source/1.0/guides/model-linters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ Example:
metadata validators = [{
id: "FooReservedWords"
name: "ReservedWords",
name: "ReservedWords"
configuration: {
reserved: [
{
words: ["Codename"],
reason: "This is the internal project name.",
},
words: ["Codename"]
reason: "This is the internal project name."
}
]
}
}]
Expand Down Expand Up @@ -341,13 +341,13 @@ Example:
$version: "1.0"
metadata validators = [{
name: "StandardOperationVerb",
name: "StandardOperationVerb"
configuration: {
verbs: ["Register", "Deregister", "Associate"],
prefixes: ["Batch"],
verbs: ["Register", "Deregister", "Associate"]
prefixes: ["Batch"]
suggestAlternatives: {
"Make": ["Create"],
"Transition": ["Update"],
"Make": ["Create"]
"Transition": ["Update"]
}
}
}]
Expand Down Expand Up @@ -676,7 +676,7 @@ example warns each time the word "meow" appears in documentation:
metadata validators = [
{
name: "ForbiddenDocumentation",
name: "ForbiddenDocumentation"
configuration: {
forbid: ["meow"]
}
Expand All @@ -695,9 +695,9 @@ example warns each time the word "meow" appears in documentation:
metadata validators = [
{
name: "EmitEachSelector",
id: "ForbiddenDocumentation",
message: "Documentation uses forbidden text",
name: "EmitEachSelector"
id: "ForbiddenDocumentation"
message: "Documentation uses forbidden text"
configuration: {
selector: "[trait|documentation*='meow']"
}
Expand Down
65 changes: 61 additions & 4 deletions docs/source/1.0/guides/style-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ Smithy models SHOULD resemble the following example:
structure MyStructure {
/// Documentation about the member.
@required
foo: String,
foo: String
}
// Example of creating custom traits.
@trait(selector: "string")
structure myTrait {}
* Each statement should appear on its own line.


File encoding
-------------
Expand Down Expand Up @@ -93,10 +95,65 @@ Whitespace
4. Members of an object are not horizontally aligned.


Trailing commas
---------------
Commas
------

Omit commas everywhere except in traits or node values defined on a
single line.

Do:

.. code-block:: smithy
$version: "1.0"
metadata validators = [{
name: "StandardOperationVerb"
configuration: {
verbs: ["Get", "Delete", "Create", "Update"]
prefixes: ["Batch"]
}
}]
namespace smithy.example.namespace
Include trailing commas to limit diff noise.
/// Gets a resource by ID.
@http(method: "GET", uri: "/message/{userId}")
operation GetMessage {
input: GetMessageInput
output: GetMessageOutput
errors: [
ValidationError
ResourceNotFoundError
]
}
Do not:

.. code-block:: smithy
$version: "1.0"
metadata validators = [{
name: "StandardOperationVerb",
configuration: {
verbs: ["Get" "Delete" "Create" "Update"],
prefixes: ["Batch"],
},
},]
namespace smithy.example.namespace
/// Gets a resource by ID.
@http(method: "GET" uri: "/message/{userId}")
operation GetMessage {
input: GetMessageInput,
output: GetMessageOutput,
errors: [
ValidationError,
ResourceNotFoundError,
],
}
Naming
Expand Down
15 changes: 8 additions & 7 deletions docs/source/1.0/spec/aws/amazon-apigateway.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,15 @@ An *authorizer* definition is a structure that supports the following members:
@authorizer("arbitrary-name")
@authorizers(
"arbitrary-name": {
scheme: sigv4,
type: "request",
uri: "arn:foo:baz",
credentials: "arn:foo:bar",
identitySource: "mapping.expression",
identityValidationExpression: "[A-Z]+",
scheme: sigv4
type: "request"
uri: "arn:foo:baz"
credentials: "arn:foo:bar"
identitySource: "mapping.expression"
identityValidationExpression: "[A-Z]+"
resultTtlInSeconds: 100
})
}
)
service Weather {
version: "2018-03-17"
}
Expand Down
6 changes: 3 additions & 3 deletions docs/source/1.0/spec/aws/aws-auth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Trait value
@sigv4(name: "foobaz")
@restJson1
service FooBaz {
version: "2018-03-17",
version: "2018-03-17"
}

.. code-tab:: json
Expand Down Expand Up @@ -109,7 +109,7 @@ operation MUST NOT be used as part of the request signature calculation:

@unsignedPayload
operation PutThings {
input: PutThingsInput,
input: PutThingsInput
output: PutThingsOutput
}

Expand Down Expand Up @@ -182,7 +182,7 @@ Trait value
providerArns: ["arn:aws:cognito-idp:us-east-1:123:userpool/123"])
@restJson1
service FooBaz {
version: "2018-03-17",
version: "2018-03-17"
}
Expand Down
Loading

0 comments on commit 0eed31b

Please sign in to comment.