Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get zod2md to split objects in to their own tables #475

Open
NathanFlurry opened this issue Jul 21, 2024 — with Linear · 2 comments
Open

Get zod2md to split objects in to their own tables #475

NathanFlurry opened this issue Jul 21, 2024 — with Linear · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

Copy link
Member

Currently, all objects are nested in auto-generated docs:

image.png

These should be split in to tables like this:

image.png

This is likely a bug in zod2md.

@NathanFlurry NathanFlurry added the documentation Improvements or additions to documentation label Jul 21, 2024 — with Linear
Copy link

linear bot commented Jul 21, 2024

Copy link

greptile-apps bot commented Jul 21, 2024

To resolve the issue of splitting objects into their own tables in the auto-generated docs, follow these steps:

  1. Update generate.ts:

    • Locate the generateModuleConfig and generateProjectConfig functions.
    • Modify the schemaToTypeScript function to handle nested objects by generating separate tables for each nested object.
  2. Modify schemaToTypeScript function:

    • In the schemaToTypeScript function, add logic to detect nested objects and generate separate tables for them.
    • Example modification:
      async function schemaToTypeScript(schema: any, name: string): Promise<string> {
        const sourceCode = convertSerializedSchemaToTypeScript(schema, { name });
      
        // Detect nested objects and generate separate tables
        const nestedTables = Object.entries(schema.properties).map(([key, value]) => {
          if (value.type === 'object') {
            return `### ${key}

\ ${convertSerializedSchemaToTypeScript(value, { name: key })} \\
`;
}
return '';
}).join('\n');

   // Append nested tables to the main schema
   const fullSourceCode = `${sourceCode}\n${nestedTables}`;

   // Format the code
   const cmd = new Deno.Command("deno", {
     args: [
       "run",
       "-A",
       "--no-config",
       "npm:[email protected]",
       "fmt",
       "--stdin",
       "tsx",
       "--config",
       resolve(Deno.cwd(), "docs/_internal/scripts/.dprint.json"),
     ],
     stdin: "piped",
     stdout: "piped",
     stderr: "inherit",
   });

   const process = cmd.spawn();

   const writter = process.stdin.getWriter();
   await writter.write(new TextEncoder().encode(`${fullSourceCode}\n`));
   await writter.ready;
   await writter.close();

   const raw = await process.output();
   const formatted = new TextDecoder().decode(raw.stdout);
   return formatted;
 }
 ```
  1. Regenerate Documentation:
    • Run the generate.ts script to regenerate the documentation with the updated schema handling.

References

/tests/basic/deno.json
/docs-old/KNOWN_ISSUES.md
/docs/mint.template.json
/tests/basic
/docs/engine/design
/docs/_internal/scripts/generate.ts
/docs-old/TIPS.md
/docs-old/CONVENTIONS.md
/.github/workflows/opengb.yml
/docs/_internal
/docs/modules/currency/scripts/get_balance.mdx
/docs/_internal/scripts
/src/migrate/generate.ts
/docs/engine
/docs-old
/tests
/docs/concepts/cli.mdx
/docs/mint.json
/src/artifacts/build_schema.ts
/release-please-config.json
/docs/_internal/templates/script.mdx
/src/artifacts
/docs/concepts/quickstart.mdx
/src/cli
/docs/engine/design/prisma.mdx

About Greptile

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

Ask Greptile · Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants