geut / openapi-box

Generate TypeBox schemas from your openapi.
MIT License
21 stars 4 forks source link

Unable to parse OpenAI schema #4

Closed humphd closed 2 months ago

humphd commented 2 months ago

I'm trying to create TypeBox types from the OpenAI OpenAPI schema, but it's failing without much info:

yq eval -o=json resources/openapi.yaml > output/openai.json 
openapi-box output/openai.json -o openai.js
✖ ',' expected. (412:26)
  410 |   response_format: T.Optional(T.Union(cache['69fde07c72b934b7c91a2c1808b4bc59'],{"default":"json"})),
  411 |   temperature: T.Optional(T.Number({"default":0})),
> 412 |   timestamp_granularities[]: T.Optional(T.Array(cache['1272a49c80b3dc8bc038af92e19f1d72'],{"default":["segment"]})),
      |                          ^
  413 | }
  414 | cache['ce56d7a02eda5fc5e1e6ae8f44b7df4d'] = {
  415 |   file: T.String({"format":"binary"}),

Is this an issue in the schema, generated code, or openapi-box?

humphd commented 2 months ago

For now I've forced it to work by renaming a bunch of things in the OpenAI YAML:

I'm not sure if there's a better approach, since these names are obviously going to be problematic in JS.

tinchoz49 commented 2 months ago

those names are problematic but if the SwaggerParser validate the schema and thinks it's ok it means that it should be a valid schema for us too. So, yeah, this was an openapi-box issue. Fixed now.

humphd commented 1 month ago

@tinchoz49 thanks for such a quick turn-around on this, really appreciated!

tinchoz49 commented 1 month ago

thank you for taking your time on reporting this!