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

fix: generate types schemas not in reticular structure #307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

C-ra-ZY
Copy link
Contributor

@C-ra-ZY C-ra-ZY commented Sep 2, 2024

see issue here: #306
and you can verify the fix by add a 'test.ts' at the root path of project, and fill the file below content, and run with
tsx test.ts:

import { generateZodClientFromOpenAPI } from "./lib/src";

import { fileURLToPath } from "url";
import path from "path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
(async () => {
    await generateZodClientFromOpenAPI({
        openApiDoc: getDoc() as Parameters<typeof generateZodClientFromOpenAPI>["0"]["openApiDoc"],
        distPath: path.resolve(__dirname, "gac.ts"),
        options: {
            shouldExportAllSchemas: false,
            withDefaultValues: false,
            shouldExportAllTypes: true,
            withImplicitRequiredProps: false,
        },
    });
})();

function getDoc() {
    return {
        openapi: "3.0.0",
        info: {
            title: "Demo API",
            description: "This is a demo API for demonstration purposes.",
            version: "1.0",
            contact: {
                name: "Demo Team",
                email: "[email protected]",
            },
        },
        servers: [
            {
                url: "http://demo-api/v1",
            },
        ],
        paths: {
            "/issuedto/{issuedTo}": {
                get: {
                    summary: "Get demo access information",
                    parameters: [
                        {
                            name: "issuedTo",
                            in: "path",
                            required: true,
                            description: "The unique key to identify the demo entity (e.g., demo ID)",
                            schema: {
                                type: "string",
                            },
                        },
                    ],
                    responses: {
                        "200": {
                            description: "OK",
                            content: {
                                "application/json": {
                                    schema: {
                                        type: "array",
                                        items: {
                                            $ref: "#/components/schemas/DemoInformation",
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            },
        },
        components: {
            schemas: {
                DemoInformation: {
                    title: "DemoInformation",
                    type: "object",
                    example: {
                        issuedTo: "demo-12345",
                        token: "demo-token-abc123",
                        expirationDate: 1672531199000,
                        group: "demoGroup",
                        identityId: "demo-id-12345",
                    },
                    properties: {
                        issuedTo: {
                            type: "string",
                        },
                        token: {
                            type: "string",
                        },
                        expirationDate: {
                            type: "string",
                        },
                        group: {
                            type: "string",
                        },
                        identityId: {
                            type: "string",
                            format: "uuid",
                        },
                    },
                    required: ["issuedTo", "token", "expirationDate", "group", "identityId"],
                },
            },
        },
    };
}

Copy link

vercel bot commented Sep 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
openapi-zod-client-rim4 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 2, 2024 8:42am

@C-ra-ZY
Copy link
Contributor Author

C-ra-ZY commented Sep 2, 2024

Please be aware of that, there is no substantial change in *.test.ts, all of the changes releated to test is about entities's order exchange or single-quote=>quote.

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.

1 participant