Skip to content

Commit

Permalink
Merge pull request #861 from libgraviton/feature/we-must-fail
Browse files Browse the repository at this point in the history
we must fail if schema cannot be generated
  • Loading branch information
narcoticfresh committed Mar 21, 2024
2 parents 3f8180c + 08dc5f5 commit c506e8e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
Expand Up @@ -296,48 +296,39 @@ protected function execute(InputInterface $input, OutputInterface $output)
$bundleDir = $input->getOption('srcDir').$namespace;
$bundleNamespace = str_replace('/', '\\', $namespace).'\\';

try {
$thisHash = sha1($templateHash.PATH_SEPARATOR.serialize($jsonDef));

$needsGeneration = true;
if (isset($existingBundles[$bundleDir])) {
if ($existingBundles[$bundleDir] == $thisHash) {
$needsGeneration = false;
}
unset($existingBundles[$bundleDir]);
}
$thisHash = sha1($templateHash.PATH_SEPARATOR.serialize($jsonDef));

if ($needsGeneration) {
$this->generateBundle($bundleNamespace, $bundleName, $input->getOption('srcDir'));
$this->generateGenerationHashFile($bundleDir, $thisHash);
$needsGeneration = true;
if (isset($existingBundles[$bundleDir])) {
if ($existingBundles[$bundleDir] == $thisHash) {
$needsGeneration = false;
}
unset($existingBundles[$bundleDir]);
}

$definedBundles[$bundleDir] = $jsonDef;

if ($needsGeneration) {
$this->generateResources(
$filesToWorkOn,
$jsonDef,
$bundleName,
$bundleDir,
$bundleNamespace
);

$output->writeln(
sprintf('<info>Generated "%s" from definition %s</info>', $bundleName, $jsonDef->getId())
);
} else {
$output->writeln(
sprintf('<info>Using pre-existing "%s"</info>', $bundleName)
);
}
} catch (\Exception $e) {
$output->writeln(
sprintf('<error>%s</error>', $e->getMessage())
if ($needsGeneration) {
$this->generateBundle($bundleNamespace, $bundleName, $input->getOption('srcDir'));
$this->generateGenerationHashFile($bundleDir, $thisHash);
}

$definedBundles[$bundleDir] = $jsonDef;

if ($needsGeneration) {
$this->generateResources(
$filesToWorkOn,
$jsonDef,
$bundleName,
$bundleDir,
$bundleNamespace
);

// remove failed bundle from list
array_pop($this->bundleBundleList);
$output->writeln(
sprintf('<info>Generated "%s" from definition %s</info>', $bundleName, $jsonDef->getId())
);
} else {
$output->writeln(
sprintf('<info>Using pre-existing "%s"</info>', $bundleName)
);
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/Graviton/GeneratorBundle/Generator/ResourceGenerator.php
Expand Up @@ -348,11 +348,19 @@ function ($synthField) {
$this->generateSerializer($parameters, $bundleDir, $document, $isSubResource);
}

$this->schemaGenerator->generateSchema(
$parameters,
$isSubResource,
$schemaFile
);
try {
$this->schemaGenerator->generateSchema(
$parameters,
$isSubResource,
$schemaFile
);
} catch (\Exception $e) {
throw new \Exception(
sprintf('Error generating schema for document "%s". Cannot continue.', $document),
0,
$e
);
}

if ($this->generateModel) {
$this->generateModel($parameters, $bundleDir, $document, $isSubResource);
Expand Down

0 comments on commit c506e8e

Please sign in to comment.