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

Generate JSON schema from serializable type #1115

Open
rnett opened this issue Oct 4, 2020 · 4 comments
Open

Generate JSON schema from serializable type #1115

rnett opened this issue Oct 4, 2020 · 4 comments
Labels

Comments

@rnett
Copy link

rnett commented Oct 4, 2020

What is your use-case and why do you need this feature?

I'd like a way to generate a JSON schema from a (serializable) type. It would likely share an implementation with #34 and more general serializer traversal.

The biggest use case, imo, is for documentation, in particular of api endpoints that receive JSON data, especially for something like OpenAPI/Swagger. There's also tools out there (like json-schema-to-typescript that take JSON schema as input to generate data classes for other languages.

Describe the solution you'd like

Ideally, I'd like some kind of generic serializer traversal in serialization with format specific uses like this or #34 in their respective format artifacts,

@rnett rnett added the feature label Oct 4, 2020
@sandwwraith
Copy link
Member

Schema builders are neither the goal for 1.0 neither for particular future release. However, we provide (experimental) functionality for introspecting serializable classes that can be used to build the schema. Using this data, a json schema can be easily built. Introspection mechanism is available via SerialDescriptor. You can find an example of usage in tests: https://github.com/Kotlin/kotlinx.serialization/blob/master/core/commonTest/src/kotlinx/serialization/SerialDescriptorSpecificationTest.kt#L39

@sschuberth
Copy link
Contributor

FYI, there is https://github.com/Ricky12Awesome/json-schema-serialization which might become handy.

@werner77
Copy link

See the PR I just created for Spring Doc Open API: springdoc/springdoc-openapi#1514

This will integrate with a Spring server using swagger for generation of an Open API schema.

@aSemy
Copy link
Contributor

aSemy commented Oct 15, 2022

I've written a library that will generate TypeScript from Kotlinx Serialization classes.

https://github.com/adamko-dev/kotlinx-serialization-typescript-generator

I think the generated TypeScript could be used to generate a JsonSchema using another library https://github.com/YousefED/typescript-json-schema https://github.com/vega/ts-json-schema-generator

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

No branches or pull requests

5 participants