diff --git a/docs/README.md b/docs/README.md index 6cf64a05e0b..d30c5f49a40 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 ``` diff --git a/docs/source-2.0/guides/building-models/build-config.rst b/docs/source-2.0/guides/building-models/build-config.rst index bd6bbbb3ab6..fd83b4da592 100644 --- a/docs/source-2.0/guides/building-models/build-config.rst +++ b/docs/source-2.0/guides/building-models/build-config.rst @@ -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 ` shapes. + +To include prelude shapes in the serialized model, add the ``model`` plugin with an :ref:`artifact-name ` +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: diff --git a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java index d2f42c49ce1..854dcfbbc29 100644 --- a/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java +++ b/smithy-build/src/main/java/software/amazon/smithy/build/plugins/ModelPlugin.java @@ -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); } } diff --git a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java index c72ec5d753f..47398bdfcb7 100644 --- a/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java +++ b/smithy-build/src/test/java/software/amazon/smithy/build/SmithyBuildTest.java @@ -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() diff --git a/smithy-build/src/test/resources/software/amazon/smithy/build/exclude-prelude-shapes.json b/smithy-build/src/test/resources/software/amazon/smithy/build/exclude-prelude-shapes.json new file mode 100644 index 00000000000..c53d07a800b --- /dev/null +++ b/smithy-build/src/test/resources/software/amazon/smithy/build/exclude-prelude-shapes.json @@ -0,0 +1,8 @@ +{ + "version": "1.0", + "plugins": { + "model::withoutPrelude": { + "includePreludeShapes": false + } + } +} diff --git a/smithy-build/src/test/resources/software/amazon/smithy/build/include-prelude-shapes.json b/smithy-build/src/test/resources/software/amazon/smithy/build/include-prelude-shapes.json new file mode 100644 index 00000000000..7de2c4f95f2 --- /dev/null +++ b/smithy-build/src/test/resources/software/amazon/smithy/build/include-prelude-shapes.json @@ -0,0 +1,8 @@ +{ + "version": "1.0", + "plugins": { + "model::withPrelude": { + "includePreludeShapes": true + } + } +}