Skip to content

Commit

Permalink
Generate union docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Nov 7, 2023
1 parent afb1c42 commit 47cce5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void generateError(GenerateErrorDirective<DocGenerationContext, DocSettin

@Override
public void generateUnion(GenerateUnionDirective<DocGenerationContext, DocSettings> directive) {
// no-op for now
new StructuredShapeGenerator(directive.context()).accept(directive.shape(), MemberListingType.OPTIONS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions smithy-docgen-test/model/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}

0 comments on commit 47cce5f

Please sign in to comment.