66package software .amazon .smithy .docgen .core ;
77
88
9+ import java .util .ArrayList ;
10+ import java .util .List ;
11+ import java .util .Optional ;
912import java .util .logging .Logger ;
1013import software .amazon .smithy .build .PluginContext ;
1114import software .amazon .smithy .build .SmithyBuildPlugin ;
1215import software .amazon .smithy .codegen .core .directed .CodegenDirector ;
16+ import software .amazon .smithy .docgen .core .validation .DocValidationEventDecorator ;
1317import software .amazon .smithy .docgen .core .writers .DocWriter ;
18+ import software .amazon .smithy .linters .InputOutputStructureReuseValidator ;
19+ import software .amazon .smithy .model .Model ;
20+ import software .amazon .smithy .model .validation .ValidatedResult ;
21+ import software .amazon .smithy .model .validation .ValidationEvent ;
22+ import software .amazon .smithy .model .validation .ValidationEventDecorator ;
23+ import software .amazon .smithy .model .validation .suppressions .ModelBasedEventDecorator ;
1424import software .amazon .smithy .utils .SmithyInternalApi ;
1525
1626/**
@@ -29,20 +39,44 @@ public String getName() {
2939 @ Override
3040 public void execute (PluginContext pluginContext ) {
3141 LOGGER .fine ("Beginning documentation generation." );
32- DocSettings docSettings = DocSettings .from (pluginContext .getSettings ());
42+ DocSettings settings = DocSettings .from (pluginContext .getSettings ());
3343
3444 CodegenDirector <DocWriter , DocIntegration , DocGenerationContext , DocSettings > runner
3545 = new CodegenDirector <>();
3646
3747 runner .directedCodegen (new DirectedDocGen ());
3848 runner .integrationClass (DocIntegration .class );
3949 runner .fileManifest (pluginContext .getFileManifest ());
40- runner .model (pluginContext .getModel ());
41- runner .settings (docSettings );
42- runner .service (docSettings .service ());
50+ runner .model (getValidatedModel ( pluginContext .getModel ()). unwrap ());
51+ runner .settings (settings );
52+ runner .service (settings .service ());
4353 runner .performDefaultCodegenTransforms ();
44- runner .createDedicatedInputsAndOutputs ();
4554 runner .run ();
4655 LOGGER .fine ("Finished documentation generation." );
4756 }
57+
58+ private ValidatedResult <Model > getValidatedModel (Model model ) {
59+ // This decorator will add context for why these are particularly important for docs.
60+ ValidationEventDecorator eventDecorator = new DocValidationEventDecorator ();
61+
62+ // This will discover and apply suppressions from the model.
63+ Optional <ValidationEventDecorator > modelDecorator = new ModelBasedEventDecorator ()
64+ .createDecorator (model ).getResult ();
65+ if (modelDecorator .isPresent ()) {
66+ eventDecorator = ValidationEventDecorator .compose (List .of (modelDecorator .get (), eventDecorator ));
67+ }
68+
69+ var events = new ArrayList <ValidationEvent >();
70+ for (var event : validate (model )) {
71+ if (eventDecorator .canDecorate (event )) {
72+ event = eventDecorator .decorate (event );
73+ }
74+ events .add (event );
75+ }
76+ return new ValidatedResult <>(model , events );
77+ }
78+
79+ private List <ValidationEvent > validate (Model model ) {
80+ return new InputOutputStructureReuseValidator ().validate (model );
81+ }
4882}
0 commit comments