Skip to content

Commit

Permalink
Expand usage of title trait (#2461)
Browse files Browse the repository at this point in the history
Expands the usage of the `@title` trait to allow application to any non-member shape.
  • Loading branch information
hpmellema authored Nov 13, 2024
1 parent cc4b0e1 commit 6d296d5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/source-2.0/spec/documentation-traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ tags trait are arbitrary and up to the model author.
Summary
Defines a proper name for a service or resource shape. This title can be
used in automatically generated documentation and other contexts to
provide a user friendly name for services and resources.
provide a user friendly name for a shape.
Trait selector
``:is(service, resource)``
``:not(member)``

*Any service or resource*
Value type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,4 +962,20 @@ public void canAddMemberDocumentation() {
IoUtils.toUtf8String(getClass().getResourceAsStream("member-documentation.jsonschema.json")));
Node.assertEquals(document.toNode(), expected);
}

@Test
public void appliesTitlesCorrectly() {
Model model = Model.assembler()
.addImport(getClass().getResource("title-added.smithy"))
.assemble()
.unwrap();
SchemaDocument document = JsonSchemaConverter.builder()
.model(model)
.build()
.convert();

Node expected = Node.parse(
IoUtils.toUtf8String(getClass().getResourceAsStream("title-added.jsonschema.v07.json")));
Node.assertEquals(document.toNode(), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"definitions": {
"Foo": {
"type": "object",
"properties": {
"bam": {
"type": "array",
"items": {
"type": "string"
},
"title": "A list of strings",
"default": []
},
"bar": {
"type": "number",
"default": 0
},
"bat": {
"allOf": [
{
"$ref": "#/definitions/TestEnum"
},
{
"default": "FOO"
}
]
},
"baz": {
"type": "string",
"default": ""
}
},
"title": "A structure"
},
"TestEnum": {
"type": "string",
"enum": [
"FOO",
"BAR"
],
"title": "A Test Enum!"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$version: "2.0"

namespace smithy.example

@title("A structure")
structure Foo {
bar: Integer = 0
baz: String = ""
bam: StringList = [],
bat: TestEnum = "FOO"
}

@title("A list of strings")
list StringList {
member: String
}

@title("A Test Enum!")
enum TestEnum {
FOO
BAR
}
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,8 @@ list tags {
/// Defines a proper name for a service or resource shape.
///
/// This title can be used in automatically generated documentation
/// and other contexts to provide a user friendly name for services
/// and resources.
@trait(selector: ":is(service, resource)")
/// and other contexts to provide a user friendly for shapes.
@trait(selector: ":not(member)")
string title

/// Constrains the acceptable values of a string to a fixed set
Expand Down

0 comments on commit 6d296d5

Please sign in to comment.