简体   繁体   English

如何获取可能的 JSON Schema 格式值列表以在 REACT 应用程序中使用?

[英]How to get a list of possible JSON Schema format values to use in REACT application?

We are developing a REACT application that needs to get a list of the JSON schema standard built-in formats.我们正在开发一个需要获取 JSON 模式标准内置格式列表的 REACT 应用程序。 According to json-schema.org reference page the built-in formats are as follows:根据json-schema.org 参考页面,内置格式如下:

  • Dates and times日期和时间
  • Email addresses电子邮件地址
  • Hostnames主机名
  • IP Addresses IP 地址
  • etc.等等

I'd rather if I didn't have to hardcode those values in our application, so how can we retrieve a list of those possible values programmatically?我宁愿不必在我们的应用程序中对这些值进行硬编码,那么我们如何以编程方式检索这些可能值的列表呢?

[EDIT] [编辑]

A clarification, we are developing a JSON schema that sets "$schema": "http://json-schema.org/schema" .澄清一下,我们正在开发一个设置"$schema": "http://json-schema.org/schema"的 JSON 模式。 This is how the app would be able to identify that we are using the current JSON Schema specification.这就是应用程序能够识别我们正在使用当前 JSON 模式规范的方式。 From there we are looking for a way to load possible values for "format" so we can present it in the UI.从那里我们正在寻找一种方法来加载"format"的可能值,以便我们可以在 UI 中呈现它。

$schema indicates the version of the specification that the schema that declares it is using. $schema表示声明它的模式正在使用的规范版本。

Each version of the specification declares a (small) static set of available formats.规范的每个版本都声明了一组(小)静态可用格式。

It's not unreasonable to hardcode these sets into a lookup by $schema value.将这些集合硬编码到$schema值的查找中并非不合理。 There are only 4 or 5 (if you include draft 4) values for this keyword, unless you're writing your own meta-schemas.此关键字只有 4 或 5 个(如果您包括草稿 4)值,除非您正在编写自己的元模式。

I've hardcoded them into my JSON Schema library, JsonSchema.Net .我已将它们硬编码到我的 JSON Schema 库JsonSchema.Net中。


If you're looking for an automated way to find these values, you're going to have to scan the specification documents themselves.如果您正在寻找一种自动查找这些值的方法,您将不得不自己扫描规范文档。 They're not listed in the meta-schemas, which is what you get when you navigate to the URI (not a URL) find in $schema .它们没有列在元模式中,这是您在导航到$schema中找到的 URI(不是 URL)时得到的。 The meta-schema just requires that format 's value is a string.元模式只要求format的值是一个字符串。

The specification intentionally leaves this open-ended so that people can create their own custom formats.该规范有意让这个开放式的,以便人们可以创建自己的自定义格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM