From 47cce5f1f54b86483f6f745c9625722d8ca576ac Mon Sep 17 00:00:00 2001 From: Jordon Phillips Date: Tue, 7 Nov 2023 15:26:36 +0100 Subject: [PATCH] Generate union docs --- .../smithy/docgen/core/DirectedDocGen.java | 2 +- .../smithy/docgen/core/DocSymbolProvider.java | 8 ++++++++ smithy-docgen-test/model/main.smithy | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DirectedDocGen.java b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DirectedDocGen.java index 17a19ed..87a8217 100644 --- a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DirectedDocGen.java +++ b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DirectedDocGen.java @@ -74,7 +74,7 @@ public void generateError(GenerateErrorDirective directive) { - // no-op for now + new StructuredShapeGenerator(directive.context()).accept(directive.shape(), MemberListingType.OPTIONS); } @Override diff --git a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocSymbolProvider.java b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocSymbolProvider.java index e3affa4..f66cb0d 100644 --- a/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocSymbolProvider.java +++ b/smithy-docgen-core/src/main/java/software/amazon/smithy/docgen/core/DocSymbolProvider.java @@ -26,6 +26,7 @@ import software.amazon.smithy.model.shapes.ShapeId; import software.amazon.smithy.model.shapes.ShapeVisitor; import software.amazon.smithy.model.shapes.StructureShape; +import software.amazon.smithy.model.shapes.UnionShape; import software.amazon.smithy.model.traits.InputTrait; import software.amazon.smithy.model.traits.OutputTrait; import software.amazon.smithy.model.traits.StringTrait; @@ -215,6 +216,13 @@ public Symbol intEnumShape(IntEnumShape shape) { .build(); } + @Override + public Symbol unionShape(UnionShape shape) { + return getSymbolBuilder(shape) + .definitionFile(getDefinitionFile(serviceShape, shape)) + .build(); + } + @Override public Symbol memberShape(MemberShape shape) { var builder = getSymbolBuilder(shape) diff --git a/smithy-docgen-test/model/main.smithy b/smithy-docgen-test/model/main.smithy index 383eb26..157fee5 100644 --- a/smithy-docgen-test/model/main.smithy +++ b/smithy-docgen-test/model/main.smithy @@ -77,6 +77,8 @@ structure DocumentedStructure { /// This is a self-referential member. This is a thing that should be possible. self: DocumentedStructure + + union: DocumentedUnion } /// This in an enum that can have one of the following values: @@ -133,3 +135,17 @@ structure ServiceError with [ErrorMixin] {} /// This error is only returned by DocumentedOperation structure DocumentedOperationError with [ErrorMixin] {} + +/// Unions can only have one member set. The member name is used as a tag to +/// determine which member is intended at runtime. +union DocumentedUnion { + /// Union members for the most part look like structure members, with the exception + /// that exactly one must be set. + string: String + + /// It doesn't matter that multiple members target the same type, since the type + /// isn't the discriminator, the tag (member name) is. + otherString: String + + struct: DocumentedStructure +}