-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
SDK Schema Generator #19867
base: main
Are you sure you want to change the base?
SDK Schema Generator #19867
Conversation
🦋 Changeset detectedLatest commit: abba3ea The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
… into sdk-ts-generator
… into sdk-ts-generator
@rijkvanzanten Should this package be licensed as MIT or BSL? 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having a sdk-schema-generator
package, lets take this opportunity to standardize the schema generation for all formats. I'd much rather have a single schema-generator
package that uses registrable plugins for typescript
/ graphql
/ openapi
🤩
I have my concerns around exporting the type with a dependency that may or may not exist: import { DirectusUsers } from '@directus/sdk'; Especially seeing that type is locked to the |
There are already multiple "generic typescript types" generators in our ecosystem which don't work 1 on 1 in the SDK. I'd rather have a generator for which i can confidently claim that the output will actually work with the SDK without manual intervention/correction.
Permissions are indeed problematic considering the required endpoints and services to build this Schema have hardcoded admin permission guards preventing users from getting non-admin schemas I could however probably narrow the schema down to specific permissions after the complete schema has been generated. |
Can you elaborate on how you envision this? Not directly sure how "plugins" figure in, do want them all moved into a single package of "plugins" or want to abstract each generator into a separate package that plug into something else 🤔 |
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
I'm hoping we can do a similar thing to the storage location adapters or data abstraction drivers where we have a singular entry point that you pass the schema object and the language, and it'll use the plugin for that language to get the output 🤔 |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@br41nslug Hey thanks for replying. |
Please do elaborate? I am not explicitly mapping unknown types at all i think
|
Specifically I mean the mapping here, on line 11: https://github.com/directus/directus/blob/d9955dfb6559987ca6372d130f086d8eb285df1c/packages/sdk-schema-generator/src/constants.ts#L11C6-L11C6 Wouldn't a BTW please let me know if this discussion belongs somewhere else. Don't wanna crowd your PR, with unneeded discussion, but wasn't sure where else to ask these questions 🙂 |
Discord is generally the place for more casual chat. Using directus/sdk/src/types/output.ts Line 110 in d9955df
|
Just curious, how would you use such a generated |
the code here does its job but needs organizing i guess. having a specification called |
@muratgozel Ignoring the naming, and specific locations, yes thats an approach. Not sure how that question relates to this PR tho as it's not deadlocked on implementation details but rather a conceptional/vision conflict. |
okay, thanks for the clarification |
Description
fixes #18121
This PR introduces a TypeScript type generator to automatically build a schema based on your existing instance to be used with the SDK.
This includes both a new endpoint and a CLI tool that use the same logic for generating the types.
Endpoint
Implemented as endpoint for easy access to generate the SDK Schema for your instance.
Options
This endpoint supports the following query parameters:
download
will download the file instead of rendering in the browserExample:
&download=my-schema.ts
naming
will transform the collection namesOptions:
database
,camelcase
,pascalcase
(default: database)root_name
will set the name of the root schema typeExample:
&root_name=MyBetterName
(default: MySchema)CLI
Implemented as CLI for easy integration into projects and workflows.
Options
This endpoint supports the following query parameters:
file
will write to file instead of rendering in the cliExample:
--file src/my-schema.ts
naming
will transform the collection namesOptions:
database
,camelcase
,pascalcase
(default: database)Example:
--naming pascalcase
root_name
will set the name of the root schema typeExample:
--root-name=MyBetterName
(default: MySchema)Example Output