Skip to content

Updates for HTTP serde correctness and safety #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2019
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
2 changes: 1 addition & 1 deletion smithy-typescript-codegen-test/model/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ structure GetCityImageInput {
}

structure GetCityImageOutput {
@streaming
@httpPayload
image: CityImageData,
}

@streaming
blob CityImageData
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeIndex;
import software.amazon.smithy.model.shapes.ShapeVisitor;
import software.amazon.smithy.model.shapes.StringShape;
import software.amazon.smithy.model.shapes.StructureShape;
Expand Down Expand Up @@ -64,7 +63,7 @@ class CodegenVisitor extends ShapeVisitor.Default<Void> {
private final ServiceShape service;
private final FileManifest fileManifest;
private final SymbolProvider symbolProvider;
private final ShapeIndex nonTraits;
private final Model nonTraits;
private final TypeScriptDelegator writers;
private final List<TypeScriptIntegration> integrations = new ArrayList<>();
private final List<RuntimeClientPlugin> runtimePlugins = new ArrayList<>();
Expand All @@ -73,7 +72,7 @@ class CodegenVisitor extends ShapeVisitor.Default<Void> {

CodegenVisitor(PluginContext context) {
settings = TypeScriptSettings.from(context.getModel(), context.getSettings());
nonTraits = context.getNonTraitShapes();
nonTraits = context.getModelWithoutTraitShapes();
model = context.getModel();
service = settings.getService(model);
fileManifest = context.getFileManifest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class SymbolVisitor implements SymbolProvider, ShapeVisitor<Symbol> {

// Get each structure that's used as output or errors.
OperationIndex operationIndex = model.getKnowledge(OperationIndex.class);
model.getShapeIndex().shapes(OperationShape.class).forEach(operationShape -> {
model.shapes(OperationShape.class).forEach(operationShape -> {
operationIndex.getOutput(operationShape).ifPresent(outputShapes::add);
outputShapes.addAll(operationIndex.getErrors(operationShape));
});
Expand Down Expand Up @@ -297,7 +297,7 @@ public Symbol unionShape(UnionShape shape) {

@Override
public Symbol memberShape(MemberShape shape) {
Shape targetShape = model.getShapeIndex().getShape(shape.getTarget())
Shape targetShape = model.getShape(shape.getTarget())
.orElseThrow(() -> new CodegenException("Shape not found: " + shape.getTarget()));
Symbol targetSymbol = targetShape.accept(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static TypeScriptSettings from(Model model, ObjectNode config) {

// TODO: this seems reusable across generators.
private static ShapeId inferService(Model model) {
List<ShapeId> services = model.getShapeIndex()
List<ShapeId> services = model
.shapes(ServiceShape.class)
.map(Shape::getId)
.sorted()
Expand Down Expand Up @@ -205,7 +205,7 @@ public void setPluginSettings(ObjectNode pluginSettings) {
* @throws CodegenException if the service is invalid or not found.
*/
public ServiceShape getService(Model model) {
return model.getShapeIndex()
return model
.getShape(getService())
.orElseThrow(() -> new CodegenException("Service shape not found: " + getService()))
.asServiceShape()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ boolean writeShapeDocs(Shape shape) {
* @return Returns true if docs were written.
*/
boolean writeMemberDocs(Model model, MemberShape member) {
return member.getMemberTrait(model.getShapeIndex(), DocumentationTrait.class)
return member.getMemberTrait(model, DocumentationTrait.class)
.map(DocumentationTrait::getValue)
.map(docs -> {
writeDocs(docs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* more complex deserialization strategies for those types.
*
* This class reduces the effort necessary to build protocol implementations, specifically when
* implementing {@link HttpBindingProtocolGenerator#generateDocumentShapeDeserializers(GenerationContext, Set)}.
* implementing {@link HttpBindingProtocolGenerator#generateDocumentBodyShapeDeserializers(GenerationContext, Set)}.
*
* Implementations of this class independent of protocol documents are also possible.
*
Expand Down Expand Up @@ -305,7 +305,7 @@ protected final void generateDeserFunction(
writer.addImport(symbol, symbol.getName());
writer.openBlock("const $L = (\n"
+ " output: any,\n"
+ " context: SerdeContext\n"
+ " context: __SerdeContext\n"
+ "): $T => {", "}", methodName, symbol, () -> functionBody.accept(context, shape));
writer.write("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* complex serialization strategies for those types.
*
* This class reduces the effort necessary to build protocol implementations, specifically when
* implementing {@link HttpBindingProtocolGenerator#generateDocumentShapeSerializers(GenerationContext, Set)}.
* implementing {@link HttpBindingProtocolGenerator#generateDocumentBodyShapeSerializers(GenerationContext, Set)}.
*
* Implementations of this class independent of protocol documents are also possible.
*
Expand Down Expand Up @@ -300,7 +300,7 @@ private void generateSerFunction(
writer.addImport(symbol, symbol.getName());
writer.openBlock("const $L = (\n"
+ " input: $T,\n"
+ " context: SerdeContext\n"
+ " context: __SerdeContext\n"
+ "): any => {", "}", methodName, symbol, () -> functionBody.accept(context, shape));
writer.write("");
}
Expand Down
Loading