Refs to # in a definition don't parse inJson.net schema - json.net

I have a schema that has a 'manager' property which is a user object:
{
"id": "foo.com/schemas/user",
"manager": {
"anyOf": [{
"$ref": "#/definitions/user"
}],
"title": "Manager"
}
The #/definitions/user schema is:
"definitions": {
"user": {
"$ref": "#"
}
}
This results in a "Error when resolving schema reference '#'. Path 'definitions.user'" error.
Addressing the user with "$ref": "#" from the manager property isn't an option as we are using the definition to help build the UI and need a common definition.
Edit: added the "id" property which was a critical omission in this.

This works:
{
"id": "http://foo.com/schemas/user",
"properties":{
"manager":{
"anyOf":[
{
"$ref":"#/definitions/user"
}
],
"title":"Manager"
}
},
"definitions":{
"user":{
"$ref":"#"
}
}
}
https://github.com/JamesNK/Newtonsoft.Json.Schema/issues/33
Edit: Added fixed "id" field with http:// qualification added.

Related

JSONPath exclude key in paths

Given a json like this:
{
"post": {
"operationId": "post-collection",
"responses": {
"201": {
"description": "Post something",
"content": {
"application/ld+json": {
"schema": {
"$ref": "./models/Mapping.jsonld.json"
}
},
"application/hal+json": {
"schema": {
"$ref": "./models/Mapping.jsonHal.json"
}
},
"application/vnd.api+json": {
"schema": {
"$ref": "./models/Mapping.vndApi.json" },
...
}
}
}
I want the content for all, BUT application/ld+json
I found a thread on how to do this based on the value: https://stackoverflow.com/a/29710922/1092632 but how would I exclude a key?
Basically what I am asking is the negative of this: $..content[application/ld+json]
Is this possible without any functions / programming? I used this for testing: https://jsonpath.com/
https://jsonpath.com/ uses JSONPath Plus
It provides #property shorthand selector within filters
$..content[?(#property != 'application/ld+json')]

How to retrieve firebase documents missing a field using runQuery and the IN operator?

This is my http POST requst body...
{
"structuredQuery": {
"select": {
"fields": [
{
"fieldPath": "name"
},
{
"fieldPath": "taxId"
},
{
"fieldPath": "mailingAddress"
}
]
},
"from": [
{
"collectionId": "orgs"
}
],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "orgId"
},
"op": "IN",
"value": {
"arrayValue": {
"values": [
{
"stringValue": ""
},
{
"nullValue": null
}
]
}
}
}
}
}
It fails to return orgs where the orgId field is completely missing from the document. It correctly includes orgs where the orgId field is present and equal to empty string. This is accessing a Cloud Firestore db.
Due to the way Firestore indexes data, it is not possible to query for documents for which a certain field "is completely missing from the document": the field needs to exist in order for the Firestore index to take it into account. More details on the indexing mechanism in the following official video.
You may store an empty value in this field, as you mention in your question.

How should a "write" request be structured for Firestore REST API (v1beta1)?

Based on the Google Discovery document, and RPC reference, it appears that the :write resource should be available for Firestore database interactions, but performing such a request to my (POST https://firestore.googleapis.com/v1beta1/projects/[my project]/databases/(default)/documents:write) results in:
[
{
"error": {
"code": 400,
"message": "Invalid value (Object), ",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid value (Object), "
}
]
}
]
}
}
]
Is this possible? A related SO answer alludes to this being available as a means of field transforms, the same reason I require this, but I cannot construct valid a JSON body to succeed in the request. Currently, variations on the following don't work as expected when trying a minimum successful response:
{
"writes": [
{
"update": {
"name": "projects/{projectId}/databases/[my project]/documents/exampleId",
"fields": {
"example": {
"integerValue": 100
},
"timestamp": {
"nullValue": null
}
},
"transform": {
"document": "projects/[my project]]/databases/(default)/documents/examples/exampleId",
"fieldTransforms": [
{
"fieldPath": "timestamp",
"setToServerValue": "REQUEST_TIME"
}
]
}
}
}
]
}
First of all, note that you should use the v1 version of the REST API, not the betas.
To create a document, you would use the createDocument method, while to update a document you would use the patch one.
For the document creation you should therefore make a POST HTTP Request to the following URL
https://firestore.googleapis.com/v1/projects/<your-project-id>/databases/(default)/documents/<the-desired-collection>
with the following Request body:
{
fields: {
example: {
integerValue: 100
}
}
}
You need to use documents:commit instead of documents:write
also the name field should be in this format:
"name": "projects/projectID/databases/(default)/documents/collectionName/DocumentId"
See this post.

Request probleme with Google Cloud Datastore and Filter

I'm currently doing some tests on google datastore, but I'm having a problem with my queries.
If I believe in the documentation https://cloud.google.com/datastore/docs/concepts/queries we can realize a filter on several columns with the instruction EQUALS.
But when testing, I get an error from the API.
While searching on Datastore's github, I found this reference: https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/304 which corresponds to my problem, except that for my case the query to the look good.
Here is the request sent:
{
{
"kind": [{
"name": "talk.message"
}],
"filter": {
"compositeFilter": {
"op": "AND",
"filters": [{
"propertyFilter": {
"property": {
"name": "Conversation"
},
"op": "EQUAL",
"value": {
"stringValue": "2f16c14f6939464ea687d316438ad4cb"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "LESS_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-15T10:43:31.474166300Z"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "GREATER_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-14T10:43:31.474175100Z"
}
}
}
]
}
}
}
}
And here is the answer from the API:
{Grpc.Core.RpcException: Status(
StatusCode=FailedPrecondition,
Detail="no matching index found. recommended index is:
- kind: talk.message
properties:
- name: Conversation
- name: CreatedOn"
)
According to the documentation, this should be good... but it's not !
What am I missing ?
Your query includes both an EQUALS (on Conversation) and a non-EQUALS filter (on CreatedOn), therefore you need a composite index to fulfil the query. So your query is valid, but it needs a composite index to be able to run the query.

How can I create a mapping for two types in ElasticSearch?

I would like to index user IDs and tag IDs.
I send a PUT request to https://ip//elasticsearch/myIndex
{
"mappings" : {
"users" : {
"properties" : {
"id" : {"type": "keyword" }
}
},
"tags" : {
"properties" : {
"id" : {"type": "keyword" }
}
}
}
}
However, I receive this response:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [myIndex] as the final mapping would have more than 1 type: [users, tags]"
}
],
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [myIndex] as the final mapping would have more than 1 type: [users, tags]"
},
"status": 400
}
How can I solve this error?
From Elastic 6.x you cannot have more than 1 mapping type. Use a single mapping type. Instead use custom type field. See this link and also this link.
As stated by #ben5556, you can only have one type per index in elasticsearch 6+. However, you can mimic multiple types per index by including your own "type" field.
{
"mappings" : {
"ids" : {
"properties" : {
"id" : {"type": "keyword" }
"type": {"type": "keyword" }
}
}
}
}
Then when you index a document, you include the "type":
{
"type": "user",
"id": "12345"
}
This will allow you to filter by type when querying the index (using a termsQuery). Which is all elasticsearch was really doing behind the scenes for you anyways back when it supported multiple types.

Resources