sukovanej / effect-http

Declarative HTTP API library for effect-ts
https://sukovanej.github.io/effect-http
MIT License
220 stars 16 forks source link

Swagger Example generation for Dates in Schema #521

Closed DwieDave closed 2 months ago

DwieDave commented 2 months ago

Hey, I've noticed that when using a Schema.Date in a struct the example in Swagger doesn't produce usable date-strings: instead they produce "string".

Is it possible to get it to work like with S.UUID ?

Reproduction

const testSchema = S.struct({
  id: S.UUID,
  date: S.Date
})

This is what Swagger shows with the given Schema set as requestBody:

grafik

Which of course leads to an error when trying to execute in Swagger:

grafik

Question

Is it possible to get the current date as an iso string for the swagger documentation by setting some annotations in Schema for example? Or is this not possible at the moment?


Packages: "@effect/platform": "^0.48.27", "@effect/platform-node": "^0.45.29", "effect": "^2.4.18", "effect-http": "^0.60.7", "effect-http-node": "^0.8.8",

sukovanej commented 2 months ago

Should be doable. Thanks for the report. I'm out of country for a week and not sure I'll get to it quickly. If you don't want to wait and feel like investigating on your own, the solution will be probably in the schema-openapi package.

DwieDave commented 2 months ago

Hi thanks for the reply! I've created a PR in the schema-openapi which now returns a current Date as default randomExample for a Date Schema. Sadly this doesn't fix the issue mentioned above for me. I've updated to the latest version that includes the schema-openapi version with the fix but the random value is still just "string". Do you have another hint where this issue could be located so I can take a look?

sukovanej commented 2 months ago

The example is generated by the OpenAPI itself and once I added the format field it started recommending a string with a date inside. Please try with the latest version.

DwieDave commented 2 months ago

Ah, I see. That definetly fixes the issue! Thank you!