Skip to content

Commit

Permalink
fix: move validate schema to template renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch authored and alharris-at committed Feb 25, 2022
1 parent 7e26b20 commit 459f5ff
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@ export class ReactIndexStudioTemplateRenderer extends StudioTemplateRenderer<
);
}) as ExportDeclaration[];
}

// no-op
validateSchema() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
handleCodegenErrors,
ComponentMetadata,
computeComponentMetadata,
validateComponentSchema,
} from '@aws-amplify/codegen-ui';
import { EOL } from 'os';
import ts, {
Expand Down Expand Up @@ -1178,5 +1179,9 @@ export abstract class ReactStudioTemplateRenderer extends StudioTemplateRenderer
mapSyntheticPropsForComponent(this.component);
}

validateSchema(component: StudioComponent) {
validateComponentSchema(component);
}

abstract renderJsx(component: StudioComponent): JsxElement | JsxFragment | JsxSelfClosingElement;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<

constructor(theme: StudioTheme, renderConfig: ReactRenderConfig) {
super(theme, new ReactOutputManager(), renderConfig);
validateThemeSchema(theme);
this.renderConfig = {
...defaultRenderConfig,
...renderConfig,
Expand Down Expand Up @@ -194,4 +193,8 @@ export class ReactThemeStudioTemplateRenderer extends StudioTemplateRenderer<
),
);
}

validateSchema(theme: StudioTheme) {
validateThemeSchema(theme);
}
}
2 changes: 2 additions & 0 deletions packages/codegen-ui/lib/__tests__/__utils__/mock-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export class MockTemplateRenderer extends StudioTemplateRenderer<
renderComponentToFilesystem: jest.fn(),
};
}

validateSchema() {}
}
5 changes: 0 additions & 5 deletions packages/codegen-ui/lib/common-component-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
import { StudioComponent, StudioComponentChild, WrappedComponentProperties } from './types';
import { StudioNode } from './studio-node';
import { validateComponentSchema } from './validation-helper';

/**
* Shared class for rendering components.
Expand All @@ -27,10 +26,6 @@ export abstract class CommonComponentRenderer<TPropIn> {
protected node: StudioNode;

constructor(protected component: StudioComponent | StudioComponentChild, protected parent?: StudioNode) {
// Run schema validation on the top-level component.
if (this.parent === undefined) {
validateComponentSchema(this.component as StudioComponent);
}
const flattenedProps = Object.entries(component.properties).map((prop) => {
return [prop[0], prop[1]];
});
Expand Down
6 changes: 5 additions & 1 deletion packages/codegen-ui/lib/studio-template-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export abstract class StudioTemplateRenderer<
protected component: TStudioType,
protected outputManager: TOutputManager,
protected renderConfig: FrameworkRenderConfig,
) {}
) {
this.validateSchema(component);
}

/**
* Renders the entire first order component. It returns the
Expand All @@ -50,4 +52,6 @@ export abstract class StudioTemplateRenderer<
return (fileName: string) => (outputPath: string) =>
this.outputManager.writeComponent(componentContent, path.join(outputPath, fileName));
}

protected abstract validateSchema(component: TStudioType): void;
}

0 comments on commit 459f5ff

Please sign in to comment.