Skip to content

Conversation

@jduff
Copy link
Contributor

@jduff jduff commented Apr 30, 2025

This PR refactors the schema inference so it isn't coupled to scraper.ts and can be imported and used in other codebases.

  • All code related to schema inference has been moved to src/infer-schema.ts
  • Logging and colourizing of output was removed from inferSchemaFromExamplePayload and put into the scraper.
  • Tests were added for inferSchemaFromExamplePayload and the function is now exported.
  • package.json was updated to add dependencies that inferSchemaFromExamplePayload needs.

},
"dependencies": {
"fast-glob": "^3.3.2"
"fast-glob": "^3.3.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved these dependencies that are needed by inferSchemaFromExamplePayload

if (unknownPaths.some(([pattern, paths]) => pattern.test(metadata.name) && paths.includes(fullPath))) {
// we know this path is always null, so don't error
} else {
errors.push({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is largely unchanged, except for this part and what is being returned. Instead of logging the errors and warnings here, we collect them and return it along with the schema.

await fs.writeFile(metadataFile, JSON.stringify(webhook, null, 2), "utf-8");

const schema = inferSchemaFromExamplePayload(webhook.response, webhook, version);
const { schema, warnings: warningCount, errors: errorMessages } = inferSchemaFromExamplePayload(webhook.response, webhook);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is mostly the same except with the removed code moving to infer-schema. This is the main change, instead of the console output happening inside inferSchemaFromExamplePayload it is moved here.

@jcao49 jcao49 requested review from airhorns and jcao49 May 6, 2025 19:30
Copy link
Contributor

@jcao49 jcao49 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙇‍♀️ thanks for this!!

@jcao49 jcao49 merged commit 1dfbe4e into gadget-inc:main May 12, 2025
@jcao49 jcao49 mentioned this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants