scalar / scalar

Beautiful API references from OpenAPI/Swagger files ✨
https://scalar.com/swagger-editor
MIT License
5.71k stars 174 forks source link

partial typebox schema missmatch #1613

Open K4leri opened 4 months ago

K4leri commented 4 months ago

What happens?

screenShot of the problem ![изображение](https://github.com/scalar/scalar/assets/65418952/a7034c1d-dba3-4766-ac86-20e1da449e0f)
    ...
    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

hanspagel commented 4 months ago

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 commented 4 months ago

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 ![изображение](https://github.com/scalar/scalar/assets/65418952/78aa209d-a969-4228-9adc-2650054bb8db) ![изображение](https://github.com/scalar/scalar/assets/65418952/ad6704ab-c62f-4f59-96f6-d22b0be49a47)
My code ```ts 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 commented 4 months ago

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 commented 4 months ago

Download OpenAPI Spec

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