Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public static void generateAll(
var index = TopologicalIndex.of(context.model());
Stream.concat(index.getOrderedShapes().stream(), index.getRecursiveShapes().stream())
.filter(shapes::contains)
.filter(shape -> !shape.isOperationShape() && !shape.isResourceShape()
&& !shape.isServiceShape()
.filter(shape -> !shape.isResourceShape()
&& !shape.isMemberShape()
&& !Prelude.isPreludeShape(shape))
.filter(filter::apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void serializeHeaders(
) {
writer.pushState(new SerializeFieldsSection(operation));
writer.addDependency(SmithyPythonDependency.SMITHY_HTTP);
writer.addImports("smithy_http", Set.of("Field", "Fields"));
writer.addImport("smithy_http", "Fields");
writer.write("""
headers = Fields(
[
Expand Down Expand Up @@ -234,9 +234,12 @@ private void writeContentType(GenerationContext context, PythonWriter writer, Op
if (optionalContentType.isEmpty() && shouldWriteDefaultBody(context, operation)) {
optionalContentType = Optional.of(getDocumentContentType());
}
optionalContentType.ifPresent(contentType -> writer.write(
"Field(name=\"Content-Type\", values=[$S]),",
contentType));
if (optionalContentType.isPresent()) {
writer.addImport("smithy_http", "Field");
writer.write(
"Field(name=\"Content-Type\", values=[$S]),",
optionalContentType.get());
}
}

private void writeContentLength(GenerationContext context, PythonWriter writer, OperationShape operation) {
Expand All @@ -249,6 +252,7 @@ private void writeContentLength(GenerationContext context, PythonWriter writer,
// The requiresLength trait, however, can force a length calculation.
// see: https://smithy.io/2.0/spec/streaming.html#requireslength-trait
if (requiresLength(context, operation)) {
writer.addImport("smithy_http", "Field");
writer.write("Field(name=\"Content-Length\", values=[str(content_length)]),");
}
return;
Expand All @@ -262,6 +266,7 @@ private void writeContentLength(GenerationContext context, PythonWriter writer,
.anyMatch(binding -> binding.getLocation() == PAYLOAD || binding.getLocation() == DOCUMENT);

if (hasBodyBindings) {
writer.addImport("smithy_http", "Field");
writer.write("Field(name=\"Content-Length\", values=[str(content_length)]),");
}
}
Expand Down Expand Up @@ -331,6 +336,7 @@ private void serializeIndividualHeaders(GenerationContext context, PythonWriter
headers.extend(tuples_to_fields(($S, $L) for e in input.$L$L))
""", binding.getLocationName(), inputValue, pythonName, trailer);
} else {
writer.addImport("smithy_http", "Field");
var dataSource = "input." + pythonName;
var inputValue = target.accept(new HttpMemberSerVisitor(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public GenerationContext createContext(CreateContextDirective<PythonSettings, Py
public void customizeBeforeShapeGeneration(CustomizeDirective<GenerationContext, PythonSettings> directive) {
new ServiceErrorGenerator(directive.settings(), directive.context().writerDelegator()).run();
SchemaGenerator.generateAll(directive.context(), directive.connectedShapes().values(), shape -> {
if (shape.isOperationShape() || shape.isServiceShape()) {
return false;
}
if (shape.isStructureShape()) {
return shouldGenerateStructure(directive.settings(), shape);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/weather/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": [
"software.amazon.smithy:smithy-model:[1.41.0,2.0)",
"software.amazon.smithy:smithy-aws-traits:[1.41.0,2.0)",
"software.amazon.smithy.python:smithy-python-codegen:0.1.0"
"software.amazon.smithy.python.codegen:core:0.0.1"
]
},
"projections": {
Expand Down
10 changes: 9 additions & 1 deletion packages/smithy-core/src/smithy_core/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def __init__(
else:
self._value = value

if self._schema.shape_type is not ShapeType.DOCUMENT:
if self._schema.shape_type not in (
ShapeType.DOCUMENT,
ShapeType.OPERATION,
ShapeType.SERVICE,
):
self._type = self._schema.shape_type
else:
# TODO: set an appropriate schema if one was not provided
Expand Down Expand Up @@ -311,6 +315,10 @@ def serialize_contents(self, serializer: ShapeSerializer) -> None:
raise SmithyException(
f"Unexpexcted DOCUMENT shape type for document value: {self.as_value()}"
)
case _:
raise SmithyException(
f"Unexpected {self._type} shape type for document value: {self.as_value()}"
)

def serialize_members(self, serializer: ShapeSerializer) -> None:
for value in self.as_map().values():
Expand Down
4 changes: 2 additions & 2 deletions packages/smithy-core/src/smithy_core/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ class ShapeType(Enum):

# We won't acutally be using these, probably
# MEMBER = 20
# SERVICE = 21
SERVICE = 21
# RESOURCE = 22
# OPERATION = 23
OPERATION = 23
Loading