在我的 json 模式中,我定义了这样的“颜色”
{
"colors": {
"type":"string",
"pattern": "AliceBlue|AntiqueWhite|Aqua|Aquamarine|Azure|Beige|Bisque|Black|BlanchedAlmond|Blue|BlueViolet|Brown|BurlyWood|CadetBlue|Chartreuse|Chocolate|Coral|CornflowerBlue|Cornsilk|Crimson|Cyan|DarkBlue|DarkCyan|DarkGoldenRod|DarkGray|DarkGrey|DarkGreen|DarkKhaki|DarkMagenta|DarkOliveGreen|DarkOrange|DarkOrchid|DarkRed|DarkSalmon|DarkSeaGreen|DarkSlateBlue|DarkSlateGray|DarkSlateGrey|DarkTurquoise|DarkViolet|DeepPink|DeepSkyBlue|DimGray|DimGrey|DodgerBlue|FireBrick|FloralWhite|ForestGreen|Fuchsia|Gainsboro|GhostWhite|Gold|Gray|Grey|Green|GreenYellow|HoneyDew|HotPink|IndianRed|Indigo|Ivory|Khaki|Lavender|LavenderBlush|LawnGreen|LemonChiffon|LightBlue|LightCoral|LightCyan|LightGoldenRodYellow|LightGray|LightGrey|LightGreen|LightPink|LightSalmon|LightSeaGreen|LightSkyBlue|LightSlateGray|LightSlateGrey|LightSteelBlue|LightYellow|Lime|LimeGreen|Linen|Magenta|Maroon|MediumAquaMarine|MediumBlue|MediumOrchid|MediumPurple|MediumSeaGreen|MediumSlateBlue|MediumSpringGreen|MediumTurquoise|MediumVioletRed|MidnightBlue|MintCream|MistyRose|Moccasin|NavajoWhite|Navy|OldLace|Olive|OliveDrab|Orange|OrangeRed|Orchid|PaleGoldenRod|PaleGreen|PaleTurquoise|PaleVioletRed|PapayaWhip|PeachPuff|Peru|Pink|Plum|PowderBlue|Purple|RebeccaPurple|Red|RosyBrown|RoyalBlue|SaddleBrown|Salmon|SandyBrown|SeaGreen|SeaShell|Sienna|Silver|SkyBlue|SlateBlue|SlateGray|SlateGrey|Snow|SpringGreen|SteelBlue|Tan|Teal|Thistle|Tomato|Turquoise|Violet|Wheat|White|WhiteSmoke|Yellow|YellowGreen"
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能让这个模式不区分大小写?
谢谢
我正在编写一个json模式来验证由exe生成的json输出.模式有点复杂,我定义了一些在属性中引用的"定义"("$ ref":"#/ definitions/...)在这里使用定义更为重要,因为我有一个定义是递归的情况.
我的架构现在运行良好,它正确验证了我的json输出.
现在,我正在尝试使用每个属性的"description"关键字正确记录架构.为了开发模式,我使用了一个以图形方式表示模式的编辑器(XMLSpy).这是非常有用的,但我面对一个奇怪的行为,我不知道它是编辑器中的问题,还是我不理解.
这是一个json模式的最小例子来解释我的问题:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"sourcePath": {
"$ref": "#/definitions/Path",
"description": "Here the description where I expected to set it"
},
"targetPath": {
"$ref": "#/definitions/Path",
"description": "Here another description where I expected to set it to that property of the same kind but whith a different use."
}
},
"additionalProperties": false,
"definitions": {
"Path": {
"description": "Here the descriptiond where it is set by the software",
"type": "object",
"properties": {
"aUsefulProperty": {
"type": …Run Code Online (Sandbox Code Playgroud)我正在使用 json-schema-validator2.2.6 库来根据 json 模式验证我的 json。问题是它提供了与我无关的通用错误消息。我想向用户发送自定义消息或代码。
我们有没有这样的选择:
"properties": {
"myKey": {
"type": "string"
**"errorMessage" : "My error message"**
},
}
Run Code Online (Sandbox Code Playgroud)
或者我可以提供自定义错误消息的任何其他方式?
我想验证JSON以使两个字段中的一个变为manadatory.
假设我们有两个字段(电子邮件地址和电话号码).我想确保记录有效需要两个字段之一.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "ExampleID-0212",
"title": "objectExamples",
"description": "Demo",
"type": "object",
"properties": {
"RecordObject": {
"type": "object",
"properties": {
"emailAddress": {
"type": "string"
},
"PhoneNumber": {
"type": "number"
}
}
}
},
"required": [
"RecordObject"
]
}
Run Code Online (Sandbox Code Playgroud) 我有外地身份。
如果用户将作业设置为草稿状态,我不想要求描述字段 - 但我确实希望有一个默认的空字符串。
如果用户正在发布作业,那么我希望需要描述。
我无法弄清楚如何在“oneOf -草案”数组中设置描述的默认值。
这是我的架构
{
"schema": "http://json-schema.org/draft-04/schema#",
"$id": "http://company.com/schemas/job-update.json#",
"title": "Job",
"description": "Update job",
"type": "object",
"properties": {
"title": {
"type": "string",
"minLength": 2
},
"description": {
"type": "string"
// Can't set default here - as it will apply for the publish status.
},
"status": {
"enum": ["draft", "published", "onhold"],
"default": "draft"
}
},
"oneOf": [
{
"description": "Draft jobs do not require any validation",
"properties": {
"status": { "enum": ["draft"]}
},
"required": …Run Code Online (Sandbox Code Playgroud) 假设我有架构和 JSON:
JSON 架构:
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [ "countries" ],
"definitions": {
"europeDef": {
"type": "object",
"required": ["type"],
"properties": { "type": {"const": "europe"} }
},
"asiaDef": {
"type": "object",
"required": ["type"],
"properties": { "type": {"const": "asia"} }
}
},
"properties": {
"countries": {
"type": "array",
"items": {
"oneOf":[
{ "$ref": "#/definitions/europeDef" },
{ "$ref": "#/definitions/asiaDef"}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
JSON:
const data = {
"countries":[
{"type": "asia1"},
{"type": "europe1"}
]
}
Run Code Online (Sandbox Code Playgroud)
const isValid …Run Code Online (Sandbox Code Playgroud) 我们可以强制类型对象的空属性如下:
{
"description": "voice mail record",
"type": "object",
"additionalProperties": false,
"properties": {}
}
Run Code Online (Sandbox Code Playgroud)
为解释在这里.
现在我要验证属性哪个
执行非空虚(第4点)是我无法猜测的.这与执行空虚有些相反,如上例所示.我当前的json架构摘录如下所示:
"attribute":
{
"type": "object",
"additionalProperties": { "type": ["string","number","integer"] }
}
Run Code Online (Sandbox Code Playgroud)
但上面并没有强制执行非空虚.我怎么能做到这一点?
我是初学者,我对JSON Hyper-Schema有疑问.
Hyper-Schema中链接的目的是什么?如何验证它们?
我正在使用 Json 架构来验证 json 对象。我正确地收到错误消息。但它看起来更像是开发人员友好的错误消息。有什么方法可以自定义错误消息,以便我可以使其更加用户友好。我浏览了很多论坛,但没有找到解决方案。
下面是我使用的代码:
string Json = @"{'Sheet1':[{'Location':'#$','First Name':11,'Last Name':'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA','Amount':'A','Date of Birth':'8522/85/25'}]}";
string JSONSchemaValidator = @"{'$schema':'http://json-schema.org/draft-04/schema#','title':'JSON Validation Schema','type':'object','additionalProperties':true,'properties':{'Sheet1':{'type':'array','items':{'type':'object','additionalProperties':true,'properties':{'Location':{'type':['number','string','null'],'pattern':'^[a-zA-Z0-9\\-\\s]+$','maxLength':15},'First Name':{'type':['string','null'],'maxLength':20,'pattern':'^[a-zA-Z\\-\\s]+$'},'Last Name':{'type':['string','null'],'maxLength':10,'pattern':'^[a-zA-Z\\-\\s]+$'},'Amount':{'type':['number','null'],'minimum':-999999999.99,'maximum':999999999.99,'exclusiveMaximum':true,'multipleOf':0.01},'Date of Birth':{'type':['string','null'],'format':'date-time'}}}}}}";
JSchema schema = JSchema.Parse(JSONSchemaValidator);
JObject person = JObject.Parse(Json);
IList<string> iJSONSchemaValidatorErrorList;
bool valid = person.IsValid(schema, out iJSONSchemaValidatorErrorList);
if (iJSONSchemaValidatorErrorList != null && iJSONSchemaValidatorErrorList.Count > 0)
{
foreach (string error in iJSONSchemaValidatorErrorList)
{
Console.WriteLine(error);
}
}
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
以下是我收到的错误消息:
1. String '#$' does not match regex pattern '^[a-zA-Z0-9\-\s]+$'. Path 'Sheet1[0].Location', line 1, position 27.
2. Invalid type. Expected String, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 AWS SAM 将请求验证器资源链接到 SAM 模板中的无服务器 API。我已经创建了请求验证器并在其 RestApiId 中引用了 API,但验证器没有被设置为 AWS 控制台中的 API 默认验证器选项。
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Discription for the template
Globals:
Function:
Timeout: 30
Resources:
MyAPI:
Type: AWS::Serverless::Api
Properties:
Name: MyAPI
StageName: prod
Auth:
DefaultAuthorizer: MyAuthorizer
Authorizers:
MyAuthorizer:
FunctionPayloadType: REQUEST
FunctionArn: here goes the function Arn
Identity:
Context:
- identity.sourceIp
ReauthorizeEvery: 60
Models:
RequestModel:
$schema: 'http://json-schema.org/draft-04/mySchema#'
type: object
properties:
Format:
type: string
Name:
type: string
minLength: 3
Id:
type: string
required:
- Format
- Id
RequestValidator: …Run Code Online (Sandbox Code Playgroud) amazon-web-services json-schema-validator aws-api-gateway aws-sam