Country -> State-> City with angular-schema-form-dynamic-select - angularjs

I am currently using angular-schema-form-dynamic-select and my requirement is to select states based on a country selected. I'm storing data in the db like this country -> state -> city. Can anyone Help me on this?
This is my form:
[
{
"key": "country",
"type": "strapselect",
"placeholder":"country",
"options": {
"httpGet": {
"url": "/countries"
},
"map": { "valueProperty": "readonlyProperties.id", "nameProperty":"name" }
}
},
{
"key": "state",
"type": "strapselect",
"placeholder":"state",
"options": {
"httpGet": {
"url": "/states"
},
"map": { "valueProperty": "readonlyProperties.id", "nameProperty":"name" }
}
},
{
"key": "city",
"type": "strapselect",
"placeholder":"city",
"options": {
"httpGet": {
"url": "/cities"
},
"map": { "valueProperty": "readonlyProperties.id", "nameProperty":"name" }
}
}
]

I think a feature like that would be indeed quite handy. Maybe you write something like this in the json string:
{
"type": "object",
"properties": {
"country": {
"type": "string",
"enumCallback": "getTitlesValues()"
}
}
}
And in your controller you would have that callback defined:
...
$scope.getTitlesValues = function () {
return ['India','Australia', 'Germany', 'Sweden']
}
...

I think a feature like that would be indeed quite handy.
Maybe you write something like this in the json string:
{
"type": "object",
"properties": {
"country": {
"type": "string",
"enumCallback": "getTitlesValues()"
}
}
}
And in your controller you would have that callback defined:
...
$scope.getTitlesValues = function () {
return ['India','Australia', 'Germany', 'Sweden']
}
...

Related

How to validate dynamic API response (Schema validation) in Postman

Hello there I have a API that sends dynamic responses and I want to validate the schema of that response.following is the response I am trying to validate.
{
"Data": [
{
"CustomerName": "BeautyProductions",
"Websites": {
"storeone": {
"Keyone":"testvalueone",
"Keytwo":"testvalue two"
}
}
}
]
}
But the thing is the number of websites increases sometimes like following
{
"Data": [
{
"CustomerName": "BeautyProductions",
"Websites": {
"storeone": {
"Keyone":"testvalueone",
"Keytwo":"testvalue two"
},
"storetwo": {
"Keyone":"testvaluestoretwo",
"Keytwo":"testvaluestoretwonow"
}
}
}
]
}
I tried to validate schema as following
var schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Data": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"CustomerName": {
"type": "string"
},
"Websites": {
"type": "object",
"properties": {
"storeone": {
"type": "object",
"properties": {
"Keyone": {
"type": "string"
},
"Keytwo": {
"type": "string"
}
},
"required": [
"Keyone",
"Keytwo"
]
}
},
"required": [
"storeone"
]
}
},
"required": [
"CustomerName",
"Websites"
]
}
]
}
},
"required": [
"Data"
]
}
var json = pm.response.json()
pm.test('shcema is valid', function(){
pm.expect(tv4.validate(json, schema)).to.be.true;
})
But it fails when the number of website count is increasing. SO, I would liketo know how I can validate this?
Thankyou
I don't know if the "stored" field is required, but you can use the "additionalProperties". The "additionalProperties" field allows you to specify a schema for properties in the object that are not explicitly defined in the properties field.
Please try below schema if it works:
var schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Data": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"CustomerName": {
"type": "string"
},
"Websites": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"Keyone": {
"type": "string"
},
"Keytwo": {
"type": "string"
}
},
"required": [
"Keyone",
"Keytwo"
]
}
}
},
"required": [
"CustomerName",
"Websites"
]
}
]
}
},
"required": [
"Data"
]
}

ElasticSearch mapping for dynamic fields

I have an index with the name 'dev-steps',
mapping for this index:
{
"dev-steps": {
"mappings": {
"steps": {
"properties": {
"cId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"data": {
"properties": {
"ui034": {
"type": "long"
},
"ksms5": {
"type": "long"
},
"ui0tg": {
"type": "long"
},
"vcw5d": {
"type": "long"
}
}
},
"uId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
I see a problem, any time when I add new value to the field 'data', that add a new property to the mapping; how I can create a dynamic mapping?
You can achieve this by adding a dynamic template to your index mapping (Elasticsearch Reference: Dynamic templates).
Thinking I found an answer to my question
Too many fields bad for elasticsearch index?
and sure I found in elasticsearch docs
https://www.elastic.co/blog/found-beginner-troubleshooting#keyvalue-woes

json schema - Parent array(array of object) items have an inner array (array of primitive) with given values

Please feel free to update fitting title for this question.
I am trying to achieve something like this. An input JSON/data JSON must have an OWNER and a CHARGE_TO Account, but these don't have to be on the same Account (I.e. one Account can be OWNER, another can be CHARGE_TO) and must not contain account with any other roles.
NOTE: Need to define JSON schema which should be simple to maintain. i.e. Should be easy to add a new role in the condition. My valid and invalid JSONs are,
*************************** VALID JSON1 *********************************
{
"user": [
{
"name": "user1",
"roles": ["OWNER"]
},
{
"name": "user2",
"roles": ["ANY_OTHER_ROLE"]
},
{
"name": "user3",
"roles": ["CHARGE_TO"]
}]
}
*************************** VALID JSON2 *********************************
{
"user": [
{
"name": "user1",
"roles": ["OWNER", "CHARGE_TO"]
},
{
"name": "user2",
"roles": ["ANY_OTHER_ROLE"]
}]
}
*************************** INVALID JSON *********************************
{
"user": [
{
"name": "user1",
"roles": ["OWNER"]
},
{
"name": "user2",
"roles": ["ANY_OTHER_ROLE"]
}]
}
A JSON is valid if it has a user with roles ("OWNER" & "CHARGE_TO") or if users with roles (user1 - "OWNER", user3-"CHARGE_TO", other users with any other role).
Below is JSON schema I tried (draft_07). THIS IS NOT A WORKING SCHEMA.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Complex inner array",
"type": "object",
"properties": {
"user": {
"type": "array",
"contains": {
"type": "object",
"properties": {
"name": { "type": "string" },
"orderRoles": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
}
},
"oneOf": [
{ "properties": { "roles": { "enum": ["OWNER", "CHARGE_TO"] }}},
{ "properties": { "roles": { "enum": ["OWNER"] }}},
{ "properties": { "roles": { "enum": ["CHARGE_TO"] }}}
]
},
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"orderRoles": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
}
}
}
}
}
}
Below is my working schema. This is not an elegant solution as schema becomes huge if a new role ("ADMIN") is added, i.e. schema condition would An input JSON/data JSON must have an OWNER, ADMIN and a CHARGE_TO Account, but these don't have to be on the same Account (I.e. one Account can be OWNER, one Account can be ADMIN & another can be CHARGE_TO) and must not contain account with any other roles. Please feel free to improve this. Thanks.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Complex inner array",
"type": "object",
"allOf": [
{
"properties": {
"account": {
"type": "array",
"contains": {
"type": "object",
"properties": {
"roles": {
"type": "array",
"minItems": 1,
"contains": { "enum": ["OWNER"] }
}
}
}
}
}
},
{
"properties": {
"account": {
"type": "array",
"contains": {
"type": "object",
"properties": {
"roles": {
"type": "array",
"minItems": 1,
"contains": { "enum": ["CHARGE_TO"] }
}
}
}
}
}
},
{
"properties": {
"account": {
"type": "array",
"items": {
"type": "object",
"properties": {
"roles": {
"type": "array",
"minItems": 1,
"items":{
"enum": ["CHARGE_TO", "OWNER"]
}
}
}
}
}
}
}
]
}
You need to isolate the part of the schema that checks for a specific role. Then you can just combine them with allOf. There's as little duplication as possible and you can easily add another constraint.
{
"type": "object",
"properties": {
"user": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"roles": {
"type": "array",
"items": { "type": "string" }
}
}
},
"allOf": [
{ "$ref": "#/definitions/require-role-owner" },
{ "$ref": "#/definitions/require-role-charge-to" }
]
}
},
"definitions": {
"require-role-owner": {
"contains": {
"properties": {
"roles": {
"contains": { "const": "OWNER" },
"allOf": [{ "$ref": "#/definitions/not-other-role" }]
}
}
}
},
"require-role-charge-to": {
"contains": {
"properties": {
"roles": {
"contains": { "const": "CHARGE_TO" },
"allOf": [{ "$ref": "#/definitions/not-other-role" }]
}
}
}
},
"not-other-role": {
"items": { "enum": ["OWNER", "CHARGE_TO"] }
}
}
}

Google Datastore Use Select Query by ID using API in GAS

I wish the Google API documentation was a little more newbie-proof.
I've worked my way through Selecting all entities, Updating an entity, inserting, and deleting. Now I would like to start selecting specific entities by criteria. The API https://datastore.googleapis.com/v1/projects/project-id-5200707080506492774:runQuery is for this purpose, and if I provide the payload of "query: {}" I get all entities. I can also filter by Kind. But I cannot figure out how to filter by a property. I try to get an entity by name with this JSON stringified payload:
var payload =
{
"query": {
"kind": [
{
"name": "Test"
}
],
"filter": {
"propertyFilter": {
"property": {
"name": "id"
},
"op": "EQUAL",
"value": {
"stringValue": "5634472569470976"
}
}
}
}
}
But I get the 200 results batch:
{
"batch": {
"entityResultType": "FULL",
"endCursor": "CgA=",
"moreResults": "NO_MORE_RESULTS"
}
}
AKA: Nothing was found.
Could someone enlighten me with regards to how to select by the entity's name/id or other field of data?
EDIT:
Here is the file structure of my entities. They are organized under the kind Test:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5634472569470976"
}
]
},
"properties": {
"test": {
"stringValue": "Hi it is me"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1
MDY0OTI3NzRyEQsSBFRlc3QYgICAgN6QgQoMGAAgAA==",
"version": "1503343869436000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5639445604728832"
}
]
},
"properties": {
"test": {
"stringValue": "testtesttest"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLyhggoMGAAgAA==",
"version": "1503343008992000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5649391675244544"
}
]
},
"properties": {
"test": {
"stringValue": "testtest"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgPjChAoMGAAgAA==",
"version": "1503342946693000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5659313586569216"
}
]
},
"properties": {
"test": {
"stringValue": "testtesttest"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgNrjhgoMGAAgAA==",
"version": "1503343059530000"
},
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5715999101812736"
}
]
},
"properties": {
"test": {
"stringValue": "hello world"
}
}
},
"cursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"version": "1503343819165000"
}
],
"endCursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"moreResults": "NO_MORE_RESULTS"
}
}
Edit:
I completed a filter query to check against my test field, as requested, and got the below 200 response:
{
"batch": {
"entityResultType": "FULL",
"entityResults": [
{
"entity": {
"key": {
"partitionId": {
"projectId": "project-id-5200707080506492774"
},
"path": [
{
"kind": "Test",
"id": "5715999101812736"
}
]
},
"properties": {
"test": {
"stringValue": "hello world"
}
}
},
"cursor":
"CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA
1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"version": "1503343819165000"
}
],
"endCursor": "CjsSNWogc35wcm9qZWN0LWlkLTUyMDA3MDcwODA1MDY0OTI3NzRyEQsSBFRlc3QYgICAgLzVkwoMGAAgAA==",
"moreResults": "NO_MORE_RESULTS"
}
}
At least in the ndb python datastore library id is not allowed as a property name. Which might be the reason your query is not working (as you expect) either.
After all you don't see any property named id within the properties structures of your entities, it is actually part of the key -> path structure.
Just to confirm, try using a valid property (i.e. one listed inside properties), for example:
"filter": {
"propertyFilter": {
"property": {
"name": "test"
},
"op": "EQUAL",
"value": {
"stringValue": "hello world"
}
}
}
If you have the entity key ids you don't need to perform queries to get the entities (you might not even be allowed to do that inside transactions), you can directly pull the entities by keys, using the projects.lookup method. I think something along these lines:
{
"keys": [
{
"path": [
{
"kind": "Test",
"id": "5634472569470976"
}
]
}
],
}

ElasticSearch-Kibana : filter array by key

I have data with one parameter which is an array. I know that objects in array are not well supported in Kibana, however I would like to know if there is a way to filter that array with only one value for the key. I mean :
This is a json for exemple :
{
"_index": "index",
"_type": "data",
"_id": "8",
"_version": 2,
"_score": 1,
"_source": {
"envelope": {
"version": "0.0.1",
"submitter": "VF12RBU1D53087510",
"MetaData": {
"SpecificMetaData": [
{
"key": "key1",
"value": "94"
},
{
"key": "key2",
"value": "0"
}
]
}
}
}
}
And I would like to only have the data which contains key1 in my SpecificMetaData array in order to plot them. For now, when I plot SpecificMetaData.value it takes all the values of the array (value of key1 and key2) and doesn't propose SpecificMetaData.value1 and SpecificMetaData.value2.
If you need more information, tell me. Thank you.
you may need to map your data to mappings so as SpecificMetaData should act as nested_type and inner_hits of nested filter can supply you with objects which have key1.
PUT envelope_index
{
"mappings": {
"document_type": {
"properties": {
"envelope": {
"type": "object",
"properties": {
"version": {
"type": "text"
},
"submitter": {
"type": "text"
},
"MetaData": {
"type": "object",
"properties": {
"SpecificMetaData": {
"type": "nested"
}
}
}
}
}
}
}
}
}
POST envelope_index/document_type
{
"envelope": {
"version": "0.0.1",
"submitter": "VF12RBU1D53087510",
"MetaData": {
"SpecificMetaData": [{
"key": "key1",
"value": "94"
},
{
"key": "key2",
"value": "0"
}
]
}
}
}
POST envelope_index/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"inner_hits": {},
"path": "envelope.MetaData.SpecificMetaData",
"query": {
"bool": {
"must": [
{
"term": {
"envelope.MetaData.SpecificMetaData.key": {
"value": "key1"
}
}
}
]
}
}
}
}
]
}
}
}

Resources