I checked my generated files again, and in this project I donβt seem to have the same issue.
My schema is OpenAPI 3.0.3 generated by drf-spectacular, and nullable string fields are represented with nullable: true.
For example:
playback_audio_file_path:type:stringnullable:true
is generated as:
playback_audio_file_path?:string|null;
I also checked the generated type file, and string | null appears correctly in many places.
There are some unknown types in my generated output, but they seem to come from different schema shapes, such as additionalProperties, items: {}, or empty schemas like:
processing_json:{}
So at least in my case, string | null itself is not being converted to unknown. πΏ
I wonder if the issue may depend on the OpenAPI schema format, for example OpenAPI 3.1 style:
type:-string-"null"
or maybe a specific combination of $ref, nullable, and the hey-api version difference. π€
Small update: I also tried the OpenAPI 3.1 style, and it seems to work fine on my side too.
So maybe the issue depends on another condition, such as an OpenAPI schema version older than 3.x, or an older hey-api version than @hey-api/openapi-ts@0.96.1.
At least with my current setup, both OpenAPI 3.0.3 nullable: true and OpenAPI 3.1 type: ["string", "null"] seem to generate string | null correctly. And if you can't generate correctly with same version, it may be a difference of setup config. π€
Thank you for your answers.
I'm rather using ElysiaJS as my backend framework. It have an openapi plugin that uses Scalar under the hood.
The current openapi version of the generated doc is 3.0.3 style
but there is no $ref in the document.
@hey-api/openapi-ts package is up to date (version 0.97.3)
Maybe i configured it wrong
That makes sense. In my case, the OpenAPI schema is generated by drf-spectacular, and it does include many $ref entries under components.schemas.
So I think this may be an important difference:
my case: drf-spectacular / Django generates shared schemas with $ref
your case: ElysiaJS / Scalar seems to generate inline schemas without $ref π€
I guess this is probably not controlled by hey-api itself. hey-api is the consumer of the OpenAPI document, while ElysiaJS / Scalar or drf-spectacular is the producer of the OpenAPI document.
No $ref does not automatically mean the schema is broken, but maybe the specific inline nullable shape generated by ElysiaJS is causing hey-api to fall back to unknown.
So my current guess is that this may be related to the OpenAPI output shape from ElysiaJS / Scalar, rather than the hey-api config itself.
Yes, it really helps.
I've found out that this feature is still experimental on Elysia framework.
I may have to find other ways to get a proper schema
Thank you very much!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for your comment and sharing this!
I checked my generated files again, and in this project I donβt seem to have the same issue.
My schema is OpenAPI 3.0.3 generated by drf-spectacular, and nullable string fields are represented with nullable: true.
For example:
is generated as:
I also checked the generated type file, and
string | nullappears correctly in many places.There are some
unknowntypes in my generated output, but they seem to come from different schema shapes, such asadditionalProperties,items: {}, or empty schemas like:So at least in my case,
string | nullitself is not being converted tounknown. πΏI wonder if the issue may depend on the OpenAPI schema format, for example OpenAPI 3.1 style:
or maybe a specific combination of $ref, nullable, and the hey-api version difference. π€
Small update: I also tried the OpenAPI 3.1 style, and it seems to work fine on my side too.
So maybe the issue depends on another condition, such as an OpenAPI schema version older than 3.x, or an older hey-api version than
@hey-api/openapi-ts@0.96.1.At least with my current setup, both OpenAPI 3.0.3
nullable: trueand OpenAPI 3.1type: ["string", "null"]seem to generatestring | nullcorrectly. And if you can't generate correctly with same version, it may be a difference of setup config. π€Thank you for your answers.
I'm rather using ElysiaJS as my backend framework. It have an openapi plugin that uses Scalar under the hood.
The current openapi version of the generated doc is 3.0.3 style
but there is no $ref in the document.
@hey-api/openapi-ts package is up to date (version 0.97.3)
Maybe i configured it wrong
That makes sense. In my case, the OpenAPI schema is generated by
drf-spectacular, and it does include many$refentries undercomponents.schemas.So I think this may be an important difference:
drf-spectacular/Djangogenerates shared schemas with$refElysiaJS/Scalarseems to generate inline schemas without$refπ€I guess this is probably not controlled by
hey-apiitself.hey-apiis the consumer of the OpenAPI document, whileElysiaJS/Scalarordrf-spectacularis the producer of the OpenAPI document.No
$refdoes not automatically mean the schema is broken, but maybe the specific inline nullable shape generated byElysiaJSis causinghey-apito fall back to unknown.So my current guess is that this may be related to the OpenAPI output shape from
ElysiaJS/Scalar, rather than thehey-apiconfig itself.Hope this helps a bit! πΊ
Yes, it really helps.
I've found out that this feature is still experimental on Elysia framework.
I may have to find other ways to get a proper schema
Thank you very much!