如何限制在Jsonschema中应用补丁的操作?

发布于 2025-02-04 07:05:32 字数 777 浏览 2 评论 0原文

当前,我们有一个JSonschema的补丁端点,现在我们要限制应用程序时可以执行的操作。

补丁端点看起来像这样:

def patch(self, name, version):
  ...
  schema = Schema.get(name, version)
  serialized_schema = schema.patch_serialize()
  ...
  data = request.get_json()
  
  patched_schema = apply_patch(serialized_schema, data)
  serialized_data, errors = update_schema_serializer.load(
                patched_schema, partial=True)
  ...


数据示例:

[
  { "op": "replace", "path": "/config/notifications/", "value": "foo" },
  { "op": "add", "path": "/config/", "value": {} },
  { "op": "remove", "path": "/config/notifications/"}
]

在这里,我们只需要addremove替换操作。有什么方法可以仅适用这些操作,而不是复制,移动和test

Currently, we have have a patch endpoint for jsonschema and now we want to limit the operation that we can do while applying the patch.

The patch endpoint looks like this:

def patch(self, name, version):
  ...
  schema = Schema.get(name, version)
  serialized_schema = schema.patch_serialize()
  ...
  data = request.get_json()
  
  patched_schema = apply_patch(serialized_schema, data)
  serialized_data, errors = update_schema_serializer.load(
                patched_schema, partial=True)
  ...


data example:

[
  { "op": "replace", "path": "/config/notifications/", "value": "foo" },
  { "op": "add", "path": "/config/", "value": {} },
  { "op": "remove", "path": "/config/notifications/"}
]

Here we want to only have add, remove and replace operation. Is there any way to only apply patch for these operation and not for copy, move and test?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不气馁 2025-02-11 07:05:32

在您的模式定义中,将OP定义为仅具有您想要的选项的枚举

In your schema definition, define op as an enum with only the options that you want

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文