Skip to content

Commit

Permalink
Configure integrations with isolated settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JordonPhillips committed Oct 24, 2023
1 parent c65088c commit 441bdd8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ default byte priority() {
* Configures the integration.
*
* <p>This provides access to both the parsed settings for the generator and
* an unparsed {@link ObjectNode} containing settings for all integrations.
* Integrations SHOULD put all of their settings inside a nested object so
* that they don't experience conflicts with other integrations.
* an unparsed {@link ObjectNode} containing settings for this particular
* integration.
*
* <p>The following {@code smithy-build.json} file contains an example of how
* this configuration will be set.
Expand All @@ -102,9 +101,9 @@ default byte priority() {
* }
* }</pre>
*
* <p>In this example, everything under the key {@code integrations} will be
* provided as the {@code rawSettings} value and the {@code my-integration} key
* represents the settings for a particular integration.
* <p>In this example, an integration whose {@link #name} is {@code my-integration}
* Would receive the extra settings from the key of the same name within the
* {@code integrations} node.
*
* <p>Integrations SHOULD use modeled traits as much as possible to drive
* configuration. This is intended for configuration that doesn't make sense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public void model(Model model) {
/**
* Sets the required settings object used for code generation.
*
* <p>{@link #integrationSettings} MUST also be set.
*
* @param settings Settings object.
*/
public void settings(S settings) {
Expand Down Expand Up @@ -205,7 +207,8 @@ public S settings(Class<S> settingsType, Node settingsNode) {
* }</pre>
*
* <p>In this example, the value of the {@code integrations} key is what must
* be passed to this method.
* be passed to this method. The value of the {@code my-integration} key will
* then be provided to an integration with the name {@code my-integration}.
*
* @param integrationSettings Settings used to configure integrations.
*/
Expand Down Expand Up @@ -411,7 +414,7 @@ private List<I> findIntegrations() {
List<I> integrations = SmithyIntegration.sort(integrationFinder.get());
integrations.forEach(i -> {
LOGGER.finest(() -> "Found integration " + i.getClass().getCanonicalName());
i.configure(settings, integrationSettings);
i.configure(settings, integrationSettings.getObjectMember(i.name()).orElse(Node.objectNode()));
});
return integrations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
public class CapturingIntegration implements TestIntegration {
public ObjectNode integrationSettings = Node.objectNode();

@Override
public String name() {
return "capturing-integration";
}

@Override
public void configure(TestSettings settings, ObjectNode integrationSettings) {
this.integrationSettings = integrationSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ public void testConfiguresIntegrations() {
.unwrap();

ObjectNode integrationSettings = Node.objectNode().withMember("spam", "eggs");
ObjectNode allIntegrationSettings = Node.objectNode()
.withMember("capturing-integration", integrationSettings);
ObjectNode settings = Node.objectNode()
.withMember("foo", "hi")
.withMember("integrations", integrationSettings);
.withMember("integrations", allIntegrationSettings);
runner.settings(TestSettings.class, settings);
runner.directedCodegen(testDirected);
runner.fileManifest(manifest);
Expand Down

0 comments on commit 441bdd8

Please sign in to comment.