From 4e509980d8097a5d99c7c7bc9080e0b38efd7f59 Mon Sep 17 00:00:00 2001 From: Hunter Mellema Date: Wed, 13 Nov 2024 08:41:29 -0700 Subject: [PATCH 1/2] Expand usage of title trait --- docs/source-2.0/spec/documentation-traits.rst | 4 ++-- .../software/amazon/smithy/model/loader/prelude.smithy | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/source-2.0/spec/documentation-traits.rst b/docs/source-2.0/spec/documentation-traits.rst index f0748626a38..58182ee19ea 100644 --- a/docs/source-2.0/spec/documentation-traits.rst +++ b/docs/source-2.0/spec/documentation-traits.rst @@ -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 diff --git a/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy b/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy index b8a92aff775..84bd11528a5 100644 --- a/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy +++ b/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy @@ -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 From ae5692495c27fc871ecef70c87620d93d77a8024 Mon Sep 17 00:00:00 2001 From: Hunter Mellema Date: Wed, 13 Nov 2024 10:19:57 -0700 Subject: [PATCH 2/2] Add test for jsonschema behavior --- .../jsonschema/JsonSchemaConverterTest.java | 16 +++++++ .../title-added.jsonschema.v07.json | 44 +++++++++++++++++++ .../smithy/jsonschema/title-added.smithy | 22 ++++++++++ 3 files changed, 82 insertions(+) create mode 100644 smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.jsonschema.v07.json create mode 100644 smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.smithy diff --git a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java index b3c74ad0202..dd0458b1dfd 100644 --- a/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java +++ b/smithy-jsonschema/src/test/java/software/amazon/smithy/jsonschema/JsonSchemaConverterTest.java @@ -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); + } } diff --git a/smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.jsonschema.v07.json b/smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.jsonschema.v07.json new file mode 100644 index 00000000000..084201fffdd --- /dev/null +++ b/smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.jsonschema.v07.json @@ -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!" + } + } +} diff --git a/smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.smithy b/smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.smithy new file mode 100644 index 00000000000..338a57168df --- /dev/null +++ b/smithy-jsonschema/src/test/resources/software/amazon/smithy/jsonschema/title-added.smithy @@ -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 +}