xddq / schema2typebox

Creating TypeBox code from JSON schemas
MIT License
66 stars 15 forks source link

Throws unsupported schema error on seemingly valid schema from Schema.org #29

Closed mjp0 closed 1 year ago

mjp0 commented 1 year ago

Library version: 0.31.17

JSON schema version: 2020-12

I won't contribute to fix the issue ❌

The current behavior

Fails with Error: Unsupported schema. Did not match any type of the parsers. Schema was: {"description":"The day of the week between Thursday and Saturday.","const":"Friday"}

The expected behavior

Should convert to Typebox schema.

Why does it happen? What/How to fix the issue?

No idea.

Content of minimal json schema file which causes the problem

Click to expand/collapse ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "schema:DayOfWeek", "title": "DayOfWeek", "description": "The day of the week, e.g. used to specify to which day the opening hours of an OpeningHoursSpecification refer.\n\nOriginally, URLs from [GoodRelations](http://purl.org/goodrelations/v1) were used (for [[Monday]], [[Tuesday]], [[Wednesday]], [[Thursday]], [[Friday]], [[Saturday]], [[Sunday]] plus a special entry for [[PublicHolidays]]); these have now been integrated directly into schema.org.\n ", "type": "string", "oneOf": [ { "description": "The day of the week between Thursday and Saturday.", "const": "Friday" }, { "description": "The day of the week between Sunday and Tuesday.", "const": "Monday" }, { "description": "This stands for any day that is a public holiday; it is a placeholder for all official public holidays in some particular location. While not technically a \"day of the week\", it can be used with [[OpeningHoursSpecification]]. In the context of an opening hours specification it can be used to indicate opening hours on public holidays, overriding general opening hours for the day of the week on which a public holiday occurs.", "const": "PublicHolidays" }, { "description": "The day of the week between Friday and Sunday.", "const": "Saturday" }, { "description": "The day of the week between Saturday and Monday.", "const": "Sunday" }, { "description": "The day of the week between Wednesday and Friday.", "const": "Thursday" }, { "description": "The day of the week between Monday and Wednesday.", "const": "Tuesday" }, { "description": "The day of the week between Tuesday and Thursday.", "const": "Wednesday" } ] } ```
xddq commented 1 year ago

Hey @mjp0, thanks for raising the issue! Fixed and released in the new version 1.6.2.

I checked schema.org but did not understand how to download the json schema for a given entitity. Could you tell me how to do that? E.g. how did you get the dayOfWeek schema for https://schema.org/DayOfWeek ?

Could think about adding more "integration tests" based on some schemas there.

mjp0 commented 1 year ago

Sorry for the late reply. I used schema-org-json-schemas package to download the schemas.