将 jsonschema 转换为 Django REST 序列化程序的工具?
tools to convert jsonschema into Django REST serializisers?
我写了一个 json-schema 来验证 POST 请求附带的 json 到我的 API。不,我需要反序列化这个 json。
当我开始构建嵌套的 serializers 结构时,我注意到过程非常相似。所以我的问题是:我已经写好的 json-schema 可以帮助反序列化过程吗?
[更新] 我在下面链接的博客 post 已经过时了。相反,我已经实现了一个结合使用 JSONSchema 验证和 DRF 的现代示例,您可以在这个答案中看到它 here.
在我偶然发现你的问题之前,我发现 this article 它演示了如何(以及可能何时)将 JSONSchema 与 Django REST Framework 一起使用。
Django Rest Framework integrates well with models to provide out of the box validation, and ModelSerializers allow futher fine-grained custom validation. However, if you’re not using a model as the resource of your endpoint then the code required for custom validation of complex data structure can get hairy.
If there is a heavily nested data structure then a serializer can be used that has a nested serializer, which also has a nested serializer, and so on – or a JSON schema and custom JSON parser can be employed.
Using a JSON schema generation tool also provides a quick win: generate the canonical “pattern” of valid JSON structure using data known to be of the correct structure. This post will go through doing this JSON schema validation using Django Rest Framework.
我写了一个 json-schema 来验证 POST 请求附带的 json 到我的 API。不,我需要反序列化这个 json。
当我开始构建嵌套的 serializers 结构时,我注意到过程非常相似。所以我的问题是:我已经写好的 json-schema 可以帮助反序列化过程吗?
[更新] 我在下面链接的博客 post 已经过时了。相反,我已经实现了一个结合使用 JSONSchema 验证和 DRF 的现代示例,您可以在这个答案中看到它 here.
在我偶然发现你的问题之前,我发现 this article 它演示了如何(以及可能何时)将 JSONSchema 与 Django REST Framework 一起使用。
Django Rest Framework integrates well with models to provide out of the box validation, and ModelSerializers allow futher fine-grained custom validation. However, if you’re not using a model as the resource of your endpoint then the code required for custom validation of complex data structure can get hairy.
If there is a heavily nested data structure then a serializer can be used that has a nested serializer, which also has a nested serializer, and so on – or a JSON schema and custom JSON parser can be employed.
Using a JSON schema generation tool also provides a quick win: generate the canonical “pattern” of valid JSON structure using data known to be of the correct structure. This post will go through doing this JSON schema validation using Django Rest Framework.