Skip to content
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

feat: Explicitly reject unsupported shapes, traits, etc. #256

Closed
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
12 changes: 12 additions & 0 deletions TestModels/SimpleTypes/SimpleDocument/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

CORES=2

include ../../SharedMakefile.mk

NAMESPACE=simple.types.document

# This project has no dependencies
# DEPENDENT-MODELS:=
# LIBRARIES :=
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace simple.types.document

@aws.polymorph#localService(
sdkId: "SimpleDocument",
config: SimpleDocumentConfig,
)
service SimpleTypesDocument {
version: "2021-11-01",
resources: [],
operations: [ GetDocument ],
errors: [],
}

structure SimpleDocumentConfig {}

operation GetDocument {
input: GetDocumentInput,
output: GetDocumentOutput,
}

structure GetDocumentInput {
value: Document
}

structure GetDocumentOutput {
value: Document
}
9 changes: 9 additions & 0 deletions TestModels/SimpleTypes/SimpleDocument/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SimpleTimestamp

This project will implement the smithy type [document](https://smithy.io/2.0/spec/simple-types.html#document) and the associated operations in `dafny`.

## Status

This project does not build. The `software.amazon.polymorph.smithydafny` project does not support code generation for the "Document" shape.

Once the Polymorph code generator supports code generation for this shape, these files should be extended to complete the type implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@
import software.amazon.polymorph.smithyjava.generator.awssdk.v2.JavaAwsSdkV2;
import software.amazon.polymorph.smithyjava.generator.library.JavaLibrary;
import software.amazon.polymorph.smithyjava.generator.library.TestJavaLibrary;
import software.amazon.polymorph.smithyjava.nameresolver.Dafny;
import software.amazon.polymorph.utils.IOUtils;
import software.amazon.polymorph.utils.ModelUtils;
import software.amazon.smithy.aws.traits.ServiceTrait;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.selector.Selector;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.utils.IoUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

public class CodegenEngine {
private static final Logger LOGGER = LoggerFactory.getLogger(CodegenEngine.class);
Expand Down Expand Up @@ -89,7 +95,7 @@ private CodegenEngine(
/**
* Executes code generation for the configured language(s).
* This method is designed to be internally stateless
* and idempotent with respect with respect to the file system.
* and idempotent with respect to the file system.
*/
public void run() {
try {
Expand All @@ -103,6 +109,19 @@ public void run() {
}

for (final TargetLanguage lang : targetLangOutputDirs.keySet()) {
String supportedFeatures = SupportedFeaturesByTargetLanguage.get(lang);
if (supportedFeatures != null) {
// TODO: look for unsupported traits too
Selector s = Selector.parse("[id=" + serviceShape.getId() + "] :is(*, ~> *) :not(" + supportedFeatures + ")");
Set<Shape> notSupported = s.select(model);
if (!notSupported.isEmpty()) {
String message = "The following shapes in the service's closure are not supported: \n" +
notSupported.stream().map(shape -> shape.toString()).collect(Collectors.joining("\n"));
// TODO: don't use an exception
throw new IllegalArgumentException(message);
}
}

final Path outputDir = targetLangOutputDirs.get(lang).toAbsolutePath().normalize();
switch (lang) {
case DAFNY -> generateDafny(outputDir);
Expand Down Expand Up @@ -374,4 +393,11 @@ public enum TargetLanguage {
JAVA,
DOTNET,
}

private static final Map<TargetLanguage, String> SupportedFeaturesByTargetLanguage = new HashMap<>();
static {
var commonSelector = ":is(service, operation, structure, string, boolean, member, list)";

SupportedFeaturesByTargetLanguage.put(TargetLanguage.DAFNY, commonSelector);
}
}