Nested objects in JSON response - json

I am defining my swagger file as below:
{
"swagger": "2.0",
"info": {
"title": "PSD2 Account API Specification",
"description": "PSD2 Account Swagger API Specification",
"version": "1.0.0"
},
"schemes": [
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"securityDefinitions": {
"basicAuth": {
"type": "basic"
}
},
"security": [
{
"basicAuth": []
}
],
"paths": {
"/accounts/{id}/transactionhistory": {
"get": {
"tags": [
"Accounts"
],
"summary": "Get transaction history",
"operationId": "GetTransactionHistory",
"produces": [
"application/json"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "fromDate",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "toDate",
"in": "query",
"required": false,
"type": "string",
"format": "date"
},
{
"name": "sumOrDetail",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "noOfEntries",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "toTime",
"in": "query",
"required": false,
"type": "string"
}
],
"responses": {
"200": {
"$ref": "#/definitions/200TransactionHistory"
}
}
}
}
},
"definitions": {
"200TransactionHistory": {
"type": "object",
"properties": {
"amount": {
"type": "string",
"maxLength": 25
},
"txnCodeDesc": {
"type": "string"
},
"accountDesc": {
"type": "string"
},
"txnCurrency": {
"type": "string",
"maxLength": 3
},
"accountIBAN": {
"type": "string"
},
"valueDate": {
"type": "string",
"format": "date"
},
"transactionCode": {
"type": "object",
"properties": {
"code": {
"type": "string",
"maxLength": 3
},
"subcode": {
"type": "string",
"maxLength": 3
}
}
},
"executionEndTime": {
"type": "string"
},
"stmtEntryId": {
"type": "string",
"maxLength": 90
},
"accountId": {
"type": "string"
},
"transReference": {
"type": "string",
"maxLength": 60
},
"exchangeRate": {
"type": "string",
"maxLength": 11
},
"remittanceInformation": {
"type": "string",
"maxLength": 65
},
"payeeCustomer": {
"type": "string"
},
"closeBalance": {
"type": "string"
},
"bookingDate": {
"type": "string",
"format": "date"
},
"currency": {
"type": "string",
"maxLength": 3
},
"id": {
"type": "string"
},
"txnCurrencyAmount": {
"type": "string",
"maxLength": 25
},
"payeeAccount": {
"type": "string"
},
"openBalance": {
"type": "string"
}
}
}
}
}
There is a simple GET request and I want in the response to have the following format:
"transactionCode": {
"code": "thisIsTheCode",
"SubsubCode": "thisIsTheSubCode"
}
As you can see in the response definition this is how I nest my objects:
"transactionCode": {
"type": "object",
"properties": {
"code": {
"type": "string",
"maxLength": 3
},
"subcode": {
"type": "string",
"maxLength": 3
}
}
}
When I am testing my request from Postman, I am getting the following error message:
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: {"header":{"audit":{"T24_time":107,"parse_time":0},"page_start":0,"page_token":"5fc34084-2496-41f0-a968-084b3b519c88","total_size":0,"page_size":50},"body":}; line: 1, column: 158]
Can anyone tell what I am doing wrong? Is this something wrong in the way I am nesting the objects in the response?

Related

array not required returns the message: "1 item required; only 0 were given" in the json schema

I configured the json schema and it looked like this:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"organisationId": {
"type": "string"
},
"clientId": {
"type": "string"
},
"issuer": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"createdDate": {
"type": "string",
"format": "date-time"
},
"lastModifiedDate": {
"type": "string",
"format": "date-time"
},
"consentId": {
"type": "string"
},
"internalStatus": {
"type": "string",
"enum": [
"AUTHORISED",
"AWAITING_AUTHORISATION",
"REJECTED",
"TIMEOUT_EXPIRED",
"OVERDUE",
"REVOKED"
]
},
"permissions": {
"type": "array",
"items": [
{
"type": "string"
}
]
},
"approverType": {
"type": "string",
"enum": [
"AND",
"OR"
]
},
"status": {
"type": "string",
"enum": [
"AUTHORISED",
"AWAITING_AUTHORISATION",
"REJECTED",
"REVOKED",
"CONSUMED"
]
},
"statusUpdateDateTime": {
"type": "string",
"format": "date-time"
},
"expirationDateTime": {
"type": "string",
"format": "date-time"
},
"resourceGroups": {
"uniqueItems": true,
"oneOf": [
{
"type": "array"
},
{
"type": "null"
}
],
"items": [
{
"type": "object",
"properties": {
"resourceGroupId": {
"type": "integer"
},
"permissions": {
"type": "array",
"items": [
{
"type": "string"
}
]
},
"resources": {
"type": "array",
"uniqueItems": true,
"items": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"AVAILABLE",
"UNAVAILABLE",
"TEMPORARY_UNAVAILABLE",
"PENDING_AUTHORISATION"
]
},
"additionalInfos": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
]
},
"type": {
"type": "string",
"enum": [
"CUSTOMERS_PERSONAL_IDENTIFICATIONS",
"CUSTOMERS_PERSONAL_QUALIFICATION",
"CUSTOMERS_PERSONAL_ADITTIONALINFO",
"CUSTOMERS_BUSINESS_IDENTIFICATIONS",
"CUSTOMERS_BUSINESS_QUALIFICATION",
"CUSTOMERS_BUSINESS_ADITTIONALINFO",
"CAPITALIZATION_TITLES",
"PENSION",
"DAMAGES_AND_PEOPLE_PATRIMONIAL",
"DAMAGES_AND_PEOPLE_AERONAUTICAL",
"DAMAGES_AND_PEOPLE_NAUTICAL",
"DAMAGES_AND_PEOPLE_NUCLEAR",
"DAMAGES_AND_PEOPLE_OIL",
"DAMAGES_AND_PEOPLE_RESPONSABILITY",
"DAMAGES_AND_PEOPLE_TRANSPORT",
"DAMAGES_AND_PEOPLE_FINANCIAL_RISKS",
"DAMAGES_AND_PEOPLE_RURAL",
"DAMAGES_AND_PEOPLE_AUTO",
"DAMAGES_AND_PEOPLE_HOUSING",
"DAMAGES_AND_PEOPLE_PEOPLE",
"DAMAGES_AND_PEOPLE_ACCEPTANCE_AND_BRANCHES_ABROAD"
]
},
"hidden": {
"type": "boolean"
},
"resourceId": {
"type": "string"
}
}
}
]
},
"additionalInfos": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
]
},
"type": {
"type": "string",
"enum": [
"ACCOUNT",
"CREDIT_CARD_ACCOUNT",
"LOAN",
"INVOICE_FINANCING",
"UNARRANGED_ACCOUNT_OVERDRAFT",
"FINANCING",
"RESOURCE",
"CUSTOMER"
]
}
},
"required": [
"permissions",
"type"
]
}
]
},
"approvers": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"AUTHORISED",
"AWAITING_AUTHORISATION",
"REJECTED",
"REVOKED",
"CONSUMED"
]
},
"approverId": {
"type": "string"
}
},
"required": [
"approverId"
]
}
]
},
"loggedUser": {
"type": "object",
"properties": {
"document": {
"type": "object",
"properties": {
"identification": {
"type": "string"
},
"rel": {
"type": "string"
}
},
"required": [
"identification",
"rel"
]
}
},
"required": [
"document"
]
},
"businessEntity": {
"type": "object",
"properties": {
"document": {
"type": "object",
"properties": {
"identification": {
"type": "string"
},
"rel": {
"type": "string"
}
},
"required": [
"identification",
"rel"
]
}
},
"required": [
"document"
]
}
},
"required": [
"organisationId",
"clientId",
"consentId",
"permissions",
"approverType",
"status",
"statusUpdateDateTime",
"expirationDateTime",
"loggedUser"
]
},
"links": {
"type": "object",
"properties": {
"self": {
"type": "string"
},
"first": {
"type": "string"
},
"prev": {
"type": "string"
},
"next": {
"type": "string"
},
"last": {
"type": "string"
}
},
"required": [
"self"
]
},
"meta": {
"type": "object",
"properties": {
"totalRecords": {
"type": "integer"
},
"totalPages": {
"type": "integer"
}
},
"required": [
"totalRecords",
"totalPages"
]
}
}
}
Note that the "resources" array is not required, it is not mandatory.
However... when I run my test and it returns an empty array in "resources":
"resourceGroupId":1,
"permissions":[
"CUSTOMERS_PERSONAL_QUALIFICATION_READ",
"CUSTOMERS_PERSONAL_IDENTIFICATIONS_READ"
],
"resources":[],
"type":"CUSTOMER"
}
I get the following message:
"#/data/resourceGroups/0/resources: failed schema #/properties/data/properties/resourceGroups/items/0/properties/resources: 1 item required; only 0 were supplied."
I don't understand how 1 item is required if the array is not required.
and still have( "uniqueItems": true
)
which in theory would accept a [] in the return, according to the Json schema documentation.
I've tried passing minItems=0 and many other things and nothing has worked.
This looks like a combination of a bug in the validator you are using and an incorrect usage of items. The good news is that when you use items correctly, the bug will probably not apply.
The items keyword has two forms: one that takes a single schema and the other that takes an array of schemas. The form must people need most of the time is the single schema form.
{
"type": "array",
"items": { "type": "string" }
}
This schemas asserts that every item in the array is a string.
{
"type": "array",
"items": [
{ "type": "string" },
{ "type": "number" }
]
}
This schema asserts that the first item in the array is a string and the second is a number. However, it should not require that those items are present or assert anything on the rest of the items in the array. So, the bug is that your validator seems to require those values when it shouldn't.
But, that bug shouldn't affect you because you I'm sure you really meant to use the single schema version of items that validates all the items in the array against the schema. Just remove the [ and ] and your schema should work as you expected.

Editing json content with azure logic app

I want to create a logic app which replaces the value of resourcename inside an alert json structure received by a logic app. The alarm structure is as follows:
{
"schemaId": "AzureMonitorMetricAlert",
"data": {
"version": "2.0",
"properties": null,
"status": "Deactivated",
"context": {
"timestamp": "2021-08-21T01:43:09.2000007Z",
"id": "/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/microsoft.insights/metricAlerts/teste%20-%20vpnp2s%20count",
"name": "teste - vpnp2s count",
"description": "",
"conditionType": "SingleResourceMultipleMetricCriteria",
"severity": "3",
"condition": {
"windowSize": "PT1M",
"allOf": [
{
"metricName": "P2SConnectionCount",
"metricNamespace": "Microsoft.Network/p2sVpnGateways",
"operator": "GreaterThanOrEqual",
"threshold": "1",
"timeAggregation": "Total",
"dimensions": [],
"metricValue": 0,
"webTestName": null
}
]
},
"subscriptionId": "<subscription_id>",
"resourceGroupName": "<my_resource_group>",
"resourceName": "some_resource_name",
"resourceType": "Microsoft.Network/p2sVpnGateways",
"resourceId": "/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/Microsoft.Network/p2sVpnGateways/<p2svpngatewayid>",
"portalLink": "https://portal.azure.com/#resource/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/Microsoft.Network/p2sVpnGateways/<theresourceid>"
}
}
}
I've been trying all sorts of mix with 'set variable', 'initialize variable', 'compose' blocks, but still no luck. Anyone has a clue?
Based on the above requirement i have created the logic app which replaces the resource name using HTTP request & replace actions.
Below is the code view of my logic app :
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"ConversionToString": {
"inputs": {
"variables": [
{
"name": "StringConversion",
"type": "string",
"value": "#{json(string(triggerBody()))}"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"FInalJsonOutput": {
"inputs": {
"variables": [
{
"name": "JsonOutput",
"type": "object",
"value": "#json(variables('replaceResouceName'))"
}
]
},
"runAfter": {
"ReplaceResourceName": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"ReplaceResourceName": {
"inputs": {
"variables": [
{
"name": "replaceResouceName",
"type": "string",
"value": "#{replace(variables('StringConversion'),'some_resource_name','newresource')}"
}
]
},
"runAfter": {
"ConversionToString": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"data": {
"properties": {
"context": {
"properties": {
"condition": {
"properties": {
"allOf": {
"items": {
"properties": {
"dimensions": {
"type": "array"
},
"metricName": {
"type": "string"
},
"metricNamespace": {
"type": "string"
},
"metricValue": {
"type": "integer"
},
"operator": {
"type": "string"
},
"threshold": {
"type": "string"
},
"timeAggregation": {
"type": "string"
},
"webTestName": {}
},
"required": [
"metricName",
"metricNamespace",
"operator",
"threshold",
"timeAggregation",
"dimensions",
"metricValue",
"webTestName"
],
"type": "object"
},
"type": "array"
},
"windowSize": {
"type": "string"
}
},
"type": "object"
},
"conditionType": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"portalLink": {
"type": "string"
},
"resourceGroupName": {
"type": "string"
},
"resourceId": {
"type": "string"
},
"resourceName": {
"type": "string"
},
"resourceType": {
"type": "string"
},
"severity": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"timestamp": {
"type": "string"
}
},
"type": "object"
},
"properties": {},
"status": {
"type": "string"
},
"version": {
"type": "string"
}
},
"type": "object"
},
"schemaId": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Here is the sample output for reference post running the above logic app

JSONSchema (draft 7) not validating child definitions for arrays

I'm getting very confused as to why my JSONSchema will not validate my data as expected.
I've appended my JSONShema and Example Date below.
The schema validates the first layer of the nested data structure (the Organisation) without issue, but fails to validate the second layer (User) and below.
Can anybody point me in the right direction as to what I'm doing wrong?
Much appreciated!
JSONSchema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://myorg/json/schemas/report-schedule.json",
"type": "array",
"items": {
"$ref": "#/definitions/Organisation"
},
"definitions": {
"Organisation": {
"type": "object",
"required": [
"organisationId",
"organisationName",
"users"
],
"properties": {
"organisationId": {
"type": "string",
"minLength": 1
},
"organisationName": {
"type": "string",
"minLength": 1
},
"users": {
"type": "array",
"items": {
"ref": "#/definitions/User"
}
}
}
},
"User": {
"type": "object",
"required": [
"name",
"email",
"reports"
],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"email": {
"type": "string",
"format": "email"
},
"reports": {
"type": "array",
"items": {
"ref": "#/definitions/Report"
}
}
}
},
"Report": {
"type": "object",
"required": [
"reportType",
"reportWeekEndDay",
"sendDay",
"sendHour",
"locations",
"widgets"
],
"properties": {
"reportType": {
"type": "string",
"enum": [
"org-weekly"
]
},
"reportWeekEndDay": {
"type": "integer",
"maximum": 6,
"minimum": 0
},
"sendDay": {
"type": "integer",
"maximum": 6,
"minimum": 0
},
"sendHour": {
"type": "integer",
"maximum": 23,
"minimum": 0
},
"locations": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
}
},
"widgets": {
"$ref": "#/definitions/Widgets"
}
}
},
"Widgets": {
"type": "array",
"title": "Widgets within a report",
"items": {
"$ref": "#/definitions/Widget"
}
},
"Widget": {
"type": "object",
"required": [
"widgetType",
"metrics",
"comparisonType"
],
"properties": {
"widgetType": {
"type": "string",
"enum": [
"table-individual-locations",
"table-all-locations"
]
},
"comparisonType": {
"type": "string",
"enum": [
"week-on-week",
"3-and-1-month-weekly-avg"
]
},
"metrics": {
"$ref": "#/definitions/Metrics"
}
}
},
"Metrics": {
"type": "array",
"title": "The Available Metrics",
"items": {
"oneOf": [
{
"$ref": "#/definitions/FootFallAndMovement"
},
{
"$ref": "#/definitions/Engagement"
},
{
"$ref": "#/definitions/Occupancy"
},
{
"$ref": "#/definitions/SalesDataTransactions"
},
{
"$ref": "#/definitions/SalesDataConversion"
}
]
}
},
"FootFallAndMovement": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "FootFallAndMovement"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff"
],
"properties": {
"excludeStaff": {
"type": "boolean"
}
}
}
}
},
"Engagement": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "Engagement"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff",
"contexts"
],
"properties": {
"additionalFilters": {
"type": "object",
"required": [
"ignoreLingerUnder"
],
"properties": {
"ignoreLingerUnder": {
"type": "integer",
"minimum": 1
}
}
},
"excludeStaff": {
"type": "boolean"
},
"contexts": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"const": "taxonomy"
},
"value": {
"type": "string",
"minLength": 1
}
}
}
}
}
}
},
"Occupancy": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "Occupancy"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff",
"contexts"
],
"properties": {
"excludeStaff": {
"type": "boolean"
},
"contexts": {
"type": "object",
"required": [
"type",
"value"
],
"properties": {
"type": {
"type": "string",
"const": "taxonomy"
},
"value": {
"type": "string",
"minLength": 1
}
}
}
}
}
}
},
"SalesDataTransactions": {
"type": "object",
"required": [
"title",
"type",
"endpoint"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "SalesDataTransactions"
},
"endpoint": {
"type": "string",
"minLength": 1
}
}
},
"SalesDataConversion": {
"type": "object",
"required": [
"title",
"type",
"endpoint",
"queryParams"
],
"properties": {
"title": {
"type": "string",
"minLength": 1
},
"type": {
"type": "string",
"const": "SalesDataConversion"
},
"endpoint": {
"type": "string",
"minLength": 1
},
"queryParams": {
"type": "object",
"required": [
"excludeStaff"
],
"properties": {
"excludeStaff": {
"type": "boolean"
}
}
}
}
}
}
}
Example Data
[
{
"organisationName": "a",
"organisationId": "a",
"users": [
{
"nameWITHERROR": "a"/*e.g. name should be required*/,
"email": "rob#test.com",
"reports": [
{
"reportType": "org-weekly1"/*e.g. this should be an enum*/,
"reportWeekEndDay": 6,
"sendDay": 6,
"sendHour": 6,
"locations": [
"abc",
"bcd"
],
"widgets": [
{
"widgetType": "table-all-locations",
"comparisonType": "3-and-1-month-weekly-avg",
"metrics": [
{
"title": "test",
"type": "FootFallAndMovement1"/*e.g. this enum should fail*/,
"endpoint": "/test",
"queryParams": {
"excludeStaff": true
}
},
{
"title": "test",
"type": "Engagement",
"endpoint": "/test",
"queryParams": {
"excludeStaff": true,
"contexts": {
"type": "taxonomy",
"value": "tests"
}
}
},
{
"title": "test",
"type": "Occupancy",
"endpoint": "/test",
"queryParams": {
"excludeStaff": true,
"contexts": {
"type": "taxonomy",
"value": "tests"
}
}
},
{
"title": "test",
"type": "SalesDataTransactions",
"endpoint": "/test"
},
{
"title": "test",
"type": "SalesDataConversion",
"endpoint": "/test",
"queryParams": {
"excludeStaff": true
}
}
]
}
]
}
]
}
]
}
]
Opening your JSON schema in JSONBuddy shows me immediately that you have used "ref" at /definitions/Organisation/properties/users/items/ref. So there is no validation because the definition is not found.

if-then-else in JSON schema for multiple fields

How can I make few fields as "required" based on condition?
For example; in below case if status==Failed then i want only four fields as required ("orgId",
"subunitId",
"fundOutType",
"status")
but any other value of status will change the required field list: ("transactionId",
"orgId",
"subunitId",
"fundOutType",
"fundOutAmount",
"status")
My below solution is not working. Please help.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"versionId": "1.0",
"javaInterfaces": [
"java.io.Serializable"
],
"type": "object",
"properties": {
"transactionId": {
"type": "string"
},
"orgId": {
"type": "string"
},
"subunitId": {
"type": "string"
},
"fundOutType": {
"type": "string"
},
"fundOutAmount": {
"type": "string"
},
"status": {
"type": "string"
},
"lang": {
"type": "string"
},
"transactionCreatedDateTime": {
"type": "integer",
"format": "date-time"
},
"userId": {
"type": "string"
}
},
"if": {
"properties": {
"status": {
"const": "Failed"
}
},
"required": [ "status" ]
},
"then": {
"required": [
"orgId",
"subunitId",
"fundOutType",
"status"
]
},
"else": {
"required": [
"transactionId",
"orgId",
"subunitId",
"fundOutType",
"fundOutAmount",
"status"
]
}
}
You can use the oneOf clause instead of the if/else:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"versionId": "1.0",
"javaInterfaces": [
"java.io.Serializable"
],
"type": "object",
"properties": {
"transactionId": {
"type": "string"
},
"orgId": {
"type": "string"
},
"subunitId": {
"type": "string"
},
"fundOutType": {
"type": "string"
},
"fundOutAmount": {
"type": "string"
},
"status": {
"type": "string"
},
"lang": {
"type": "string"
},
"transactionCreatedDateTime": {
"type": "integer",
"format": "date-time"
},
"userId": {
"type": "string"
}
},
"oneOf": [
{
"properties": {
"status": {
"const": "Failed"
}
},
"required": [
"orgId",
"subunitId",
"fundOutType",
"status"
]
},
{
"required": [
"transactionId",
"orgId",
"subunitId",
"fundOutType",
"fundOutAmount",
"status"
]
}
]
}
See documentation https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1

Swagger - Invalid JSON errors

I'm just starting with Swagger UI and I'm trying to understand how it works.
So far I've entered some JSON (manually) and this is the result:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "PhakeApps API",
"contact": {
"name": "PhakeApps API team",
"url": "http://phakeapps.com/"
},
"license": {
"name": "Creative Commons 4.0 International",
"url": "http://creativecommons.org/licenses/by/4.0/"
}
},
"host": "api.phakeapps.com",
"basePath": "/v1",
"schemes": [
"http"
],
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"paths": {
"/places/search": {
"post": {
"tags": [
"Places"
],
"description": "Search for (a) place(s) <br /><br /> <b>id</b> - The ID of the request. <br /> <b>api_key</b> - API Key for the platform the request is sent. <i>Currently, not required.</i> <br /> <b>Params</b> - Required. <i>See model & model schema.</i>",
"operationId": "PlacesSearch",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"parameters": [
{
"name": "request",
"in": "body",
"paramType": "body",
"description": "Object containing the <u>id</u>, <u>api_key</u> and certain <u>params</u>.",
"required": true,
"schema": {
"$ref": "#/definitions/Search"
}
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/PlacesResult"
}
},
"403": {
"description": "Validation error or Server Failure",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"PlacesResult": {
"required": [
"data",
"id",
"code"
],
"properties": {
"data": {
"$ref": "#/definitions/Places"
},
"id": {
"type": "integer",
"format": "int32"
},
"code": {
"type": "integer",
"format": "int32"
}
}
},
"Places": {
"required": [
"places"
],
"properties": {
"places": {
"$ref": "#/definitions/Place"
}
}
},
"City": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"Neighbourhood": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"Cuisine": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"Place": {
"required": [
"id",
"name",
"city",
"neighbourhood",
"address",
"cuisine",
"price",
"photos_cnt",
"lat",
"lng",
"is_fav"
],
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"city": {
"type": "array",
"items": {
"$ref": "#/definitions/City"
}
},
"neighbourhood": {
"type": "array",
"items": {
"$ref": "#/definitions/Neighbourhood"
}
},
"address": {
"type": "string"
},
"cuisine": {
"type": "array",
"items": {
"$ref": "#/definitions/Cuisine"
}
},
"price": {
"type": "integer",
"format": "int32"
},
"photos_cnt": {
"type": "integer",
"format": "int32"
},
"lat": {
"type": "double"
},
"lng": {
"type": "double"
},
"is_fav": {
"type": "boolean"
}
}
},
"Search": {
"required": [
"id",
"api_key",
"params"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"api_key": {
"type": "string"
},
"params": {
"$ref": "#/definitions/SearchParams"
}
}
},
"SearchParams": {
"required": [
"user_id",
"city_id",
"people",
"dt",
"locale"
],
"properties": {
"user_id": {
"type": "string",
"default": "956dda4c21c72e48f5f17a7cd783a0f7"
},
"city_id": {
"type": "string",
"default": "4ec4b3e6098c9d23c925b0c2451eb06a"
},
"people": {
"type": "integer",
"format": "int32",
"minimum": 1,
"default": 2
},
"dt": {
"type": "integer",
"format": "int32",
"default": "1427742000"
},
"locale": {
"type": "string",
"default": "bg"
},
"place_id": {
"type": "string",
"default": "0"
},
"neighborhood_id": {
"type": "string",
"default": "0"
},
"cuisine_id": {
"type": "string",
"default": "0"
},
"kids_place": {
"type": "boolean",
"default": false
},
"price": {
"type": "integer",
"format": "int64",
"default": 1
},
"outdoors": {
"type": "boolean",
"default": false
}
}
},
"Error": {
"required": [
"code",
"data"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"data": {
"type": "array",
"items": {
"type": "array"
}
}
}
}
}
}
However, swagger's validator says it's not valid. The error I get is this
[
{
"level": "error",
"domain": "validation",
"keyword": "anyOf",
"message": "instance failed to match at least one required schema among 2",
"schema": {
"loadingURI": "http://json-schema.org/draft-04/schema#",
"pointer": "/properties/type"
},
"instance": {
"pointer": "/definitions/Place/properties/lat/type"
}
}
]
Note that it works as expected (so far). It displays the data (models and models' structure) properly. Make requests and retrieves responses. Yet the validator says it's not valid. (The yellow badge saying 'Invalid', not the red one that says 'Error').
What am I missing?
Your spec is indeed not valid. In your Place definition, you use "type": "double" to describe the type of the lat (and also lng) property, but such a type does not exist.
If you want to describe a numeric value of 'double' size, you should change the definition as follows:
"lng": {
"type": "number",
"format": "double"
}
Do that everywhere you use the double type, and it should resolve that issue.