diff --git a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/SchemaGenerator.java b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/SchemaGenerator.java index 8e863fc31..7711d97ba 100644 --- a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/SchemaGenerator.java +++ b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/generators/SchemaGenerator.java @@ -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) diff --git a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/integrations/HttpBindingProtocolGenerator.java b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/integrations/HttpBindingProtocolGenerator.java index 8042663b9..367712c58 100644 --- a/codegen/core/src/main/java/software/amazon/smithy/python/codegen/integrations/HttpBindingProtocolGenerator.java +++ b/codegen/core/src/main/java/software/amazon/smithy/python/codegen/integrations/HttpBindingProtocolGenerator.java @@ -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( [ @@ -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) { @@ -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; @@ -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)]),"); } } @@ -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, diff --git a/codegen/plugins/types/src/main/java/software/amazon/smithy/python/codegen/types/DirectedPythonTypeCodegen.java b/codegen/plugins/types/src/main/java/software/amazon/smithy/python/codegen/types/DirectedPythonTypeCodegen.java index 852a7e432..41fde17dc 100644 --- a/codegen/plugins/types/src/main/java/software/amazon/smithy/python/codegen/types/DirectedPythonTypeCodegen.java +++ b/codegen/plugins/types/src/main/java/software/amazon/smithy/python/codegen/types/DirectedPythonTypeCodegen.java @@ -64,6 +64,9 @@ public GenerationContext createContext(CreateContextDirective 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); } diff --git a/examples/weather/smithy-build.json b/examples/weather/smithy-build.json index becbde21a..8a291f616 100644 --- a/examples/weather/smithy-build.json +++ b/examples/weather/smithy-build.json @@ -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": { diff --git a/packages/smithy-core/src/smithy_core/documents.py b/packages/smithy-core/src/smithy_core/documents.py index 4f01d6916..b9af55cf5 100644 --- a/packages/smithy-core/src/smithy_core/documents.py +++ b/packages/smithy-core/src/smithy_core/documents.py @@ -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 @@ -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(): diff --git a/packages/smithy-core/src/smithy_core/shapes.py b/packages/smithy-core/src/smithy_core/shapes.py index 1eebfac15..3f9505165 100644 --- a/packages/smithy-core/src/smithy_core/shapes.py +++ b/packages/smithy-core/src/smithy_core/shapes.py @@ -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