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

Add includePreludeShapes in model plugin #1693

Merged
merged 1 commit into from
Mar 27, 2023
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
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ make html
To view the output, just open up `build/html/index.html` in your browser:

```
open build/html/index.html
open build/html/1.0/index.html
open build/html/2.0/index.html
```
16 changes: 15 additions & 1 deletion docs/source-2.0/guides/building-models/build-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,21 @@ model plugin

The ``model`` plugin serializes a self-contained and filtered version of the
model as a single file. All of the dependencies of the model are included
in the file.
in the file. By default the serialized model excludes :ref:`prelude <prelude>` shapes.

To include prelude shapes in the serialized model, add the ``model`` plugin with an :ref:`artifact-name <plugin-id>`
to the ``smithy-build.json`` file with the ``includePreludeShapes`` property set to ``true``.

.. code-block:: json

{
"version": "1.0",
"plugins": {
"model::withPrelude": {
"includePreludeShapes": true
}
}
}


.. _build-info-plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public String getName() {

@Override
public void execute(PluginContext context) {
context.getFileManifest().writeJson("model.json", serializeModel(context.getModel()));
boolean includePrelude = context.getSettings().getBooleanMemberOrDefault("includePreludeShapes");
context.getFileManifest().writeJson("model.json", serializeModel(context.getModel(), includePrelude));
}

private static Node serializeModel(Model model) {
return ModelSerializer.builder().build().serialize(model);
private static Node serializeModel(Model model, boolean includePrelude) {
return ModelSerializer.builder().includePrelude(includePrelude).build().serialize(model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,44 @@ public void createsEmptyManifest() throws Exception {
.get())));
}

@Test
public void modeExcludePreludeShapes() throws Exception {
SmithyBuildConfig config = SmithyBuildConfig.builder()
.load(Paths.get(getClass().getResource("exclude-prelude-shapes.json").toURI()))
.outputDirectory(outputDirectory.toString())
.build();
Model model = Model.assembler()
.assemble()
.unwrap();
SmithyBuildResult results = new SmithyBuild().config(config).model(model).build();
String content = IoUtils.readUtf8File(results.allArtifacts()
.filter(path -> path.toString().endsWith("withoutPrelude" + System.getProperty("file.separator") + "model.json"))
.findFirst()
.get());
assertThat(Files.isRegularFile(outputDirectory.resolve("source/withoutPrelude/model.json")), is(true));
assertThat(content, not(containsString("smithy.api#Boolean")));
assertThat(content, not(containsString("smithy.api#Integer")));
}

@Test
public void modeIncludePreludeShapes() throws Exception {
SmithyBuildConfig config = SmithyBuildConfig.builder()
.load(Paths.get(getClass().getResource("include-prelude-shapes.json").toURI()))
.outputDirectory(outputDirectory.toString())
.build();
Model model = Model.assembler()
.assemble()
.unwrap();
SmithyBuildResult results = new SmithyBuild().config(config).model(model).build();
String content = IoUtils.readUtf8File(results.allArtifacts()
.filter(path -> path.toString().endsWith("withPrelude" + System.getProperty("file.separator") + "model.json"))
.findFirst()
.get());
assertThat(Files.isRegularFile(outputDirectory.resolve("source/withPrelude/model.json")), is(true));
assertThat(content, containsString("smithy.api#Boolean"));
assertThat(content, containsString("smithy.api#Integer"));
}

@Test
public void doesNotCopyErroneousModelsToBuildOutput() throws Exception {
SmithyBuildConfig config = SmithyBuildConfig.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "1.0",
"plugins": {
"model::withoutPrelude": {
"includePreludeShapes": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "1.0",
"plugins": {
"model::withPrelude": {
"includePreludeShapes": true
}
}
}