Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported schema type: fhirprimitiveextension #18

Open
trevorpfiz opened this issue Nov 29, 2023 · 4 comments
Open

Unsupported schema type: fhirprimitiveextension #18

trevorpfiz opened this issue Nov 29, 2023 · 4 comments

Comments

@trevorpfiz
Copy link

trevorpfiz commented Nov 29, 2023

The issue is coming from a FHIRPrimitiveExtension type. What are my options here? I am having the same problem with openapi-zod-client.

Reference:
fhir-extensions

Here is the OpenAPI file:
openapi.json

Error: Unsupported schema type: fhirprimitiveextension
    at getZodSchema (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:1357:9)
    at /home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:1332:24
    at Array.map (<anonymous>)
    at getZodSchema (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:1316:56)
    at getZodSchema (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:1117:16)
    at getZodiosEndpointDefinitionList (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:1679:26)
    at getZodClientTemplateContext (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:2212:16)
    at _callee$ (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:2453:20)
    at tryCatch (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:77:17)
    at Generator.<anonymous> (/home/spark/.local/share/pnpm/store/v3/tmp/dlx-27449/node_modules/.pnpm/[email protected]/node_modules/openapi-zod-client/dist/generateZodClientFromOpenAPI-3ae8a23b.cjs.dev.js:158:22)

Node.js v20.10.0
@astahmer
Copy link
Owner

astahmer commented Nov 29, 2023

looking at the JSON, it doesnt seem like it's supposed to generate anything, right ? in that case, you could parse/traverse the openapi JSON and remove any reference to that fhirprimitiveextension type before passing it to typed-openapi / openapi-zod-client

@trevorpfiz
Copy link
Author

Apparently there are loads of unsupported types throughout the openapi.json. Maybe most of them are not important as you said? My first time working with OpenAPI, so I don't know if this is a "bad" spec or if they all require some cleaning. Would it make sense to not have unsupported types error out and instead make them something like unknown or nullable or any?

I am using the Canvas Medical FHIR API: https://docs.canvasmedical.com/api/

My plan right now is to either manually clean the openapi.json, or attempt to convert their Postman Collections into OpenAPI which may give a better spec?

I'm a bit lost 😂

@trevorpfiz
Copy link
Author

trevorpfiz commented Nov 30, 2023

converting the Postman Collections into OpenAPI worked well, and I was able to generate a zod client! 🎉

I am supposed to manually validate like this right? No out-of-the-box runtime validation?

const patientsData = await api.get("/Patient", { query: {} });
const validatedData = get_SearchPatient.response.parse(patientsData);
return validatedData;

Can close this issue if you are happy with how Unsupported schema type is handled.

Thanks!

@astahmer
Copy link
Owner

astahmer commented Nov 30, 2023

glad that you found a solution !


I am supposed to manually validate like this right? No out-of-the-box runtime validation?

yes, my intention for this library was to be "headless", by that I mean that it only provides the primitives to build your own type-safe API client (without any runtime by default !)

in the fetcher (that you provides to the createApiClient), I think there's enough infos to make this automatic by retrieving the correct schema (if not I'm 100% open to adding what's needed):

 type Fetcher = (
        method: Method,
        url: string,
        parameters?: EndpointParameters | undefined,
      ) => Promise<Endpoint["response"]>;

as a lot of people have different needs, it's easier for me (in term of maintenance) to inverse the responsibility/control than having to integrate 100 different config options (like I did with openapi-zod-client) to try to fit in everyone's specific needs

that being said, if anyone comes up with a good default API client that validates etc by default, I'm fine with merging it in (as long as it's optional and that people can still create their own)


Can close this issue if you are happy with how Unsupported schema type is handled.

I think adding a callback to handle errors should make it easier to deal with, rather than having to pre-filter the openapi document (which I think it still a fine-ish solution)

I'll leave the issue open if anyone wants to send a PR for those issues mentioned above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants