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

partial typebox schema missmatch #1613

Open
K4leri opened this issue May 4, 2024 · 4 comments
Open

partial typebox schema missmatch #1613

K4leri opened this issue May 4, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@K4leri
Copy link

K4leri commented May 4, 2024

What happens?

screenShot of the problem

изображение

    ...
    repeat: t.Partial(
        t.Object({
            repeatDays: t.Array(t.Number({ integer: true, minimum: 1, maximum: 7 },), {minItems: 1, maxItems: 7, description: 'all numbers should be Ascending order cause it can influnce on repeat_at time'}),
            daysHash: t.String({format: 'hex', pattern: '^[0-9a-f]{1,2}$'}),
            repeat_at: t.Array(t.Array(t.Array(t.String({format: 'time'}))), {minItems: 1, maxItems: 7}),
            price: t.Array(t.Array(t.Integer({minimum: 0, maximum: 9999999})), {minItems: 1, maxItems: 7})
        }),
        t.Array(
            t.Object({
                start_time: t.String({ pattern: '^\\d{2}:\\d{2}:\\d{2}$' }),
                end_time: t.Optional(t.String({ pattern: '^\\d{2}:\\d{2}:\\d{2}$' })),
                price: t.Number({ integer: true, minimum: 0, maximum: 9999999 }),
                discount: t.Union([
                    t.Object({
                        discount: t.Number({ integer: true, minimum: 0, maximum: 100 }),
                        type: t.String({pattern: '^persent$', default: 0, description: 'some int as persent discount'})
                    }),
                    t.Object({
                        discount: t.Number({ integer: true, minimum: 0, maximum: 9999999 }),
                        type: t.String({pattern: '^price$', default: 0, description: 'some int as price discount'})
                    }),
                ]) 
            })
        )
    ),
});
...
"@elysiajs/swagger": "^1.0.5",
"elysia": "^1.0.16",

repeat is a part of ScheduleSchema value and ScheduleSchema is a part of schedule: t.Array(ScheduleSchema)

Got missmatch schema. Partial doesnt work ? something very strange i see in documentation. But in code snippets with request there is values that user can take.

I dont see daysHash, repeat_at, price values from the first partial part.
And i dont see any of the values from the second possible partial part.

What did you expect to happen?

Would like to see some values here
изображение

How can we reproduce the issue?

schema above

Swagger/OpenAPI Example

No response

@K4leri K4leri added the bug Something isn't working label May 4, 2024
@K4leri K4leri changed the title typebox schema missmatch partial typebox schema missmatch May 4, 2024
@hanspagel
Copy link
Member

hanspagel commented May 4, 2024

Thanks for reporting! Any chance you can share the OpenAPI specification that is generated? That would make it so much easier to reproduce and fix the issue. 🙏

@K4leri
Copy link
Author

K4leri commented May 5, 2024

I hope u are asking about this. If not, correct me pls. I will provide exactly what u want to get.

But as u can see its not the problem of scalar visualisation of docs. Its the problem of openAPI. The first screenshot is schema. The second one is Example Value.

Click to view photos

изображение
изображение

My code
const ScheduleSchema = t.Object({
    start_date: t.String({ pattern: '^\\d{4}-\\d{2}-\\d{2}$' }),
    end_date: t.Optional(t.String({ pattern: '^\\d{4}-\\d{2}-\\d{2}$' })),
    repeat: t.Partial(
        t.Object({
            repeatDays: t.Array(t.Number({ integer: true, minimum: 1, maximum: 7 },), {minItems: 1, maxItems: 7, description: 'all numbers should be Ascending order cause it can influnce on repeat_at time'}),
            daysHash: t.String({format: 'hex', pattern: '^[0-9a-f]{1,2}$'}),
            repeat_at: t.Array(t.Array(t.Array(t.String({format: 'time'}))), {minItems: 1, maxItems: 7}),
            price: t.Array(t.Array(t.Integer({minimum: 0, maximum: 9999999})), {minItems: 1, maxItems: 7})
        }),
        t.Array(
            t.Object({
                start_time: t.String({ pattern: '^\\d{2}:\\d{2}:\\d{2}$' }),
                end_time: t.Optional(t.String({ pattern: '^\\d{2}:\\d{2}:\\d{2}$' })),
                price: t.Number({ integer: true, minimum: 0, maximum: 9999999 }),
                discount: t.Union([
                    t.Object({
                        discount: t.Number({ integer: true, minimum: 0, maximum: 100 }),
                        type: t.String({pattern: '^persent$', default: 0, description: 'some int as persent discount'})
                    }),
                    t.Object({
                        discount: t.Number({ integer: true, minimum: 0, maximum: 9999999 }),
                        type: t.String({pattern: '^price$', default: 0, description: 'some int as price discount'})
                    }),
                ]) 
            })
        )
    ),
});


export const ActivityParamsSchema = t.Object({
    ...
    schedule: t.Array(ScheduleSchema, {description: 'can contain as schedule as time_slots at same time'}),
    ...
});

@hanspagel
Copy link
Member

hanspagel commented May 6, 2024

Kind of! But the rendered reference has a "Download OpenAPI Spec" link in the header. Can you use that to download the OpenAPI specification and share it here?

Maybe this is wrong already, then we need to take a look at @elysia/swagger or - if it’s right - we can swiftly fix the issue here. 👍

Screenshot 2024-05-06 at 13 29 33

@K4leri
Copy link
Author

K4leri commented May 6, 2024

Download OpenAPI Spec

I delete all other endpoints for security reasons.
spec.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants