Swagger Schema: oneOf, anyOf, allOf valid at the same time? - schema

I'm just reading through the more advanced validators in the Schema definition of the Swagger specification:
{
"Schema":{
"type":"object",
"properties":{
"title":{
"type":"string"
},
"multipleOf":{
"type":"number",
"minimum":0,
"exclusiveMinimum":true
},
"maximum":{
"type":"number"
},
"exclusiveMaximum":{
"type":"boolean",
"default":false
},
"minimum":{
"type":"number"
},
"exclusiveMinimum":{
"type":"boolean",
"default":false
},
"maxLength":{
"type":"integer",
"minimum":0
},
"minLength":{
"type":"integer",
"minimum":0,
"default":0
},
"pattern":{
"type":"string",
"format":"regex"
},
"maxItems":{
"type":"integer",
"minimum":0
},
"minItems":{
"type":"integer",
"minimum":0,
"default":0
},
"uniqueItems":{
"type":"boolean",
"default":false
},
"maxProperties":{
"type":"integer",
"minimum":0
},
"minProperties":{
"type":"integer",
"minimum":0,
"default":0
},
"required":{
"type":"array",
"items":{
"type":"string"
},
"minItems":1,
"uniqueItems":true
},
"enum":{
"type":"array",
"items":{
},
"minItems":1,
"uniqueItems":true
},
"type":{
"type":"string",
"enum":[
"array",
"boolean",
"integer",
"number",
"object",
"string"
]
},
"not":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
}
]
},
"allOf":{
"type":"array",
"items":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
}
]
}
},
"oneOf":{
"type":"array",
"items":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
}
]
}
},
"anyOf":{
"type":"array",
"items":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
}
]
}
},
"items":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
}
]
},
"properties":{
"type":"object",
"additionalProperties":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
}
]
}
},
"additionalProperties":{
"oneOf":[
{
"$ref":"#/definitions/Schema"
},
{
"$ref":"#/definitions/Reference"
},
{
"type":"boolean"
}
],
"default":true
},
"description":{
"type":"string"
},
"format":{
"type":"string"
},
"default":{
},
"nullable":{
"type":"boolean",
"default":false
},
"discriminator":{
"$ref":"#/definitions/Discriminator"
},
"readOnly":{
"type":"boolean",
"default":false
},
"writeOnly":{
"type":"boolean",
"default":false
},
"example":{
},
"externalDocs":{
"$ref":"#/definitions/ExternalDocumentation"
},
"deprecated":{
"type":"boolean",
"default":false
},
"xml":{
"$ref":"#/definitions/XML"
}
},
"patternProperties":{
"^x-":{
}
},
"additionalProperties":false
}
}
The thing that I am thinking about is combinations of the anyOf, allOf, oneOf and not keywords. I have two questions.
The first question is: "can they be used in conjunction"? Like so:
{
"allOf" : [
{
"minItems" : 0
},
{
"maxItems" : 10
}
],
"anyOf" : [
{
"type" : "array",
"items" : {
"type" : "string"
}
},
{
"type" : "array",
"items" : {
"type" : "integer"
}
}
]
}
This example is, of course, needlessly complicated. But is it valid? Or can you only use one modifier but not the others?
The second question is, can anybody point me to a real-world example where one of these operators have been used in conjunction?

The thing that I am thinking about is combinations of the anyOf, allOf, oneOf and not keywords. I have two questions.
The first question is: "can they be used in conjunction"?
Yes, allOf, anyOf, oneOf and not can be used in conjunction. OpenAPI Specification follows the rules of JSON Schema here, and in JSON Schema adjacent keywords work as branches of an implicit allOf (source). So your example is equivalent to:
{
"allOf": [
{
"allOf": [
{
"minItems": 0
},
{
"maxItems": 10
}
]
},
{
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "array",
"items": {
"type": "integer"
}
}
]
}
]
}
That said, this example is too complex and can be simplified into:
{
"minItems": 0,
"maxItems": 10,
"type": "array",
"items": {
"oneOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
}
}

Related

Unomi use of UpdatePoperties event to enrich profil

We are tring to enrich a profil using UpdateProperties event.
Something wrong, it didn't work.
Step of our process :
Search of the profil :
Use of the prive API /profiles/search
So we find a profil and get the profilId "60de10fe-e6ff-11ec-8fea-0242ac120002" for next step.
Enrich profil :
Use of the API public /context.json to post the json
{
"sessionId": null,
"profileId": "60de10fe-e6ff-11ec-8fea-0242ac120002",
"events": [
{
"itemType": "event",
"scope": "myScope",
"eventType": "updateProperties",
"properties": {
"update": {
"properties.age": "24"
},
"add": {
"properties.kids" : "1"
}
}
}
]
}
Response :
{
"profileId": "60de10fe-e6ff-11ec-8fea-0242ac120002",
"sessionId": null,
"profileProperties": null,
"sessionProperties": null,
"profileSegments": null,
"profileScores": null,
"filteringResults": null,
"processedEvents": 1,
"personalizations": null,
"trackedConditions": [
{
"parameterValues": {
"operator": "and",
"subConditions": [
{
"parameterValues": {
"formId": "zoneLeadFormEvent"
},
"type": "formEventCondition"
}
]
},
"type": "booleanCondition"
},
{
"parameterValues": {
"formId": "testFormTracking",
"pagePath": "/tracker/"
},
"type": "formEventCondition"
},
{
"parameterValues": {
"formId": "searchForm"
},
"type": "formEventCondition"
},
{
"parameterValues": {
"formId": "advancedSearchForm"
},
"type": "formEventCondition"
}
],
"anonymousBrowsing": false,
"consents": {}
}
Validation of the profile changes
Get /cxs/profiles/60de10fe-e6ff-11ec-8fea-0242ac120002
So, the properties are not updated.
We use a rules the merge the profil on a custom identifier :
{
"metadata": {
"id": "update_with_custom_identifier",
"name": "UpdateWithCustomIdentifier",
"description": "Copy my properties to profile properties on update"
},
"condition": {
"parameterValues": {
"subConditions": [
{
"parameterValues": {
},
"type": "updatePropertiesEventCondition"
}
],
"operator": "and"
},
"type": "booleanCondition"
},
"actions": [
{
"parameterValues": {
"mergeProfilePropertyValue": "eventProperty::target.properties.myIdentifier",
"mergeProfilePropertyName": "mergeCustomIdentifier"
},
"type": "mergeProfilesOnPropertyAction"
},
{
"parameterValues": {
},
"type": "allEventToProfilePropertiesAction"
}
]
}
What's the good method ?
Thanks in advance

How to implement conditional nested properties with JSON Schema [duplicate]

This question already has an answer here:
Is there support in JSON Schema for deep object validation?
(1 answer)
Closed 1 year ago.
I have base json schema base.schema.json
{
"$id": "base.schema.json",
"type": "object",
"properties": {
"remote_os": {
"default": "Windows",
"enum": [
"Linux",
"Windows" ]
}
},
"required": ["remote_os"]
}
Now referenced the schema definition in another json
{
"$id": "update.schema.json",
"properties": {
"common_data": {
"$ref": "base.schema.json"
}
},
"allOf": [
{
"if": {
"properties": {
"common_data": {
"remote_os": {
"const": "Windows"
}
}
}
},
"then": {
"properties": {
"file": {
"pattern": "^(.*.)(exe)$"
}
}
}
},
{
"if": {
"properties": {
"common_data": {
"remote_os": {
"const": "Linux",
"required": [
"remote_os"
]
}
}
}
},
"then": {
"properties": {
"file": {
"pattern": "^(.*.)(bin)$"
}
}
}
}
]
}
Basically adding the if-else logic to make sure for remote_os=Linux file should ended up with .bin and remote_os=Windows file should ended up with .exe
Now I am trying to validate against below data
{
"common_data": {
"remote_os": "Linux"
},
"file": "abc.bin"
}
[<ValidationError: "'abc.bin' does not match '^(.*.)(exe)$'">]. Not sure what's wrong here
I think you are over complicating it - surly just if/then/else?
{
"if": {
"properties": { "common_data": "properties": { "remote_os": { "const": "Windows" } } }
},
"then": {
"properties": { "file": { "pattern": "^(.*.)(exe)$" } }
},
"else": {
"properties": { "file": { "pattern": "^(.*.)(bin)$" } }
}
}

Create a new Google Sheet with row or column groups

I'm trying to create a new spreadsheet using spreadsheets#create, with specified row groups.
In the API Explorer, I am entering in the JSON below. which corresponds to the following appearance:
No errors are flagged or returned when I execute the call, but when the sheet is created, the specified grouping is not created - only the values are set.
{ "properties": {
"title": "Test Spreadsheet",
"locale": "en"
},
"sheets": [
{ "properties": {"title": "Test1"},
"data": [
{
"startRow": 0,
"startColumn": 0,
"rowData": [
{ "values": [
{ "userEnteredValue": { "stringValue": "Top1" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "Top2" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2A" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2B" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2C" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "Top3" } }
]
}
]
}
],
"rowGroups": [
{ "range": {
"dimension": "ROWS",
"startIndex": 2,
"endIndex": 5
}
}
]
}
]
}
Even when I create the rowGroups JSON directly on the page, with its structured editor to make sure it is properly defined, the created spreadsheet still doesn't group the specified rows. I have triple-checked all my objects from the top down, and can't see what I am doing wrong.

How to insert mant-to-many object

I have two structures very similar to pests-owners, this is my structure:
{
"name": "Contratti",
"fields": {
"rischicontratti": {
"collection": "RischiContratti",
"via": "Contratti"
},
"intervento": {
"collection": "Interventi",
"via": "Contratto"
},
"Numero": {
"type": "string"
},
"Impresa": {
"object": "Imprese"
},
"Oggetto": {
"type": "string"
}
},
{
"name": "RischiContratti",
"fields": {
"Contratti": {
"object": "Contratti"
},
"Rischio": {
"object": "Rischi"
}
}
},
{
"name": "Rischi",
"fields": {
"rischicontratti": {
"collection": "RischiContratti",
"via": "Rischio"
},
"rischi_interventi": {
"collection": "rischi_interventi",
"via": "Rischio"
},
"Rischio": {
"type": "string"
}
}
When I'm inserting a Contratto I want to also insert all related Rischi. Is there a way to post all in one call? Or do I have to post first the Contratto and then loop each Rischi?

SWITCH in json schema (v5 proposal)

I'm newbie about npm ajv
I have a question:
How many "switch" in a object json?
example:
var schema = {
"type": "object",
"switch": [
{
"if": {
"properties": {
"powerLevel": {"constant": false}
}
},
"then": {
"required": ["disbelief"]
}
},
{
"then": {
"required": ["confidence"]
}
}
],
"switch": [
{
"if": {
"properties": {
"power": {"constant": false}
}
},
"then": {
"required": ["disb"]
}
},
{
"then": {
"required": ["conf"]
}
}
]
};
I test with schema above in this link
it's just check end switch.
please help me! thanks!
You cannot have two keywords switch in the same object.
In this particular instance you can merge the "cases" in one switch:
{
"type": "object",
"switch": [
{
"if": { "properties": { "powerLevel": {"constant": false} } },
"then": { "required": ["disbelief"] }
},
{
"if": { "properties": { "power": {"constant": false} } },
"then": { "required": ["disb"] }
},
{
"then": {
"oneOf": [
{ "required": ["confidence"] },
{ "required": ["conf"] }
]
}
}
]
}
In general case you can use keywords allOf, anyOf, oneOf to merge two schemas containing duplicate keywords between them.