Here are my body's model
{
"specs": [
{
"name": "test",
"id": "7dcf2db8-858e-4c00-bbde-e0c5c734770c"
}
]
}
trying to convert this last for uri module
body_format: json
body:
specs:
id: "id"
name: "name"
how to convert this last correctly ? switch to raw ?
specs is an array of dicts so the right syntax is:
body_format: json
body:
specs:
- id: "id"
name: "name"
Related
I am trying to build a workflow where in step1 I am running a cloud function which returns a Json Object in the form of python dictionary and I want the same to be inserted in Firestore using firestore connector. But I am getting the below error:
HTTP server responded with error code 400
in step "create_document", routine "main", line: 27
HTTP server responded with error code 400
in step "create_document", routine "main", line: 28
{
"body": {
"error": {
"code": 400,
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"field1\" at 'document.fields[0].value': Cannot find field.",
"field": "document.fields[0].value"
},
{
"description": "Invalid value at 'document.fields[1].value' (type.googleapis.com/google.firestore.v1.Value), 200",
"field": "document.fields[1].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Alt-Svc\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Cache-Control\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Content-Length\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Content-Type\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
},
{
"description": "Invalid JSON payload received. Unknown name \"Date\" at 'document.fields[2].value': Cannot find field.",
"field": "document.fields[2].value"
}
This is how my workflow looks like
main:
params: [args]
steps:
- step1:
call: http.get
args:
url: https://XXXXXXXXXXXXX.cloudfunctions.net/step1-workflow
query:
bucket_name: ${args.bucket_name}
blob_name: ${args.blob_name}
result: key_val
- step2:
assign:
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- collection: "a-dummy-collection"
- document: "new7-dummy-document"
- create_document:
call: googleapis.firestore.v1.projects.databases.documents.createDocument
args:
collectionId: ${collection}
parent: ${"projects/" + project_id + "/databases/(default)/documents"}
query:
documentId: ${document}
body:
fields: ${key_val}
result: inserted
if in place of ${key_val} I use simple json {"field1": {"stringValue": "str1"},"field2": {"integerValue": 10}} it works fine and data gets inserted in the Firestore but if I try to use the object from variable ${key_val} which is in the same structure as mentioned json it gives error.
Answer given in the comments: the ${key_val} result from the call to the cloud function is actually returning the whole response object, not just the body. That's why in the error messages, you were seeing things like content-type and other headers.
The solution here is to say that we want the body of that response with: ${key_val.body}.
I set up a basic model and controller connected to mysql database. Everything looks good and is working.
My Definition Model looks like this.
import { Entity, model, property } from '#loopback/repository';
#model({
settings: {
mysql: {
table: 'definition'
}
}
})
export class Definition extends Entity {
#property({
type: 'number',
id: true,
generated: true,
forceId: true,
required: false,
description: 'The unique identifier for a definition',
})
id: number;
#property({
type: 'string',
required: true,
})
name: string;
#property({
type: 'string',
required: true,
})
process_id: string;
constructor(data?: Partial<Definition>) {
super(data);
}
}
export interface DefinitionRelations {
// describe navigational properties here
}
export type DefinitionWithRelations = Definition & DefinitionRelations;
When I have it up and running and click on the explorer to test it out.
I click on "Try it out" for get /definitions and the only editable field that gets enabled is the filter field.
It is repopulated with a value like this...
{
"where": {},
"fields": {
"id": true,
"name": true,
"process_id": true
},
"offset": 0,
"limit": 0,
"skip": 0,
"order": [
"string"
]
}
I have to clear that to get it to work which is fine. When I run it with no filter it returns these results.
[
{
"id": 10,
"name": "Place Manual Payoff Order Process Config",
"process_id": "Process_PlaceManualPayoffOrderProcessConfig"
},
{
"id": 11,
"name": "test",
"process_id": "Test"
},
{
"id": 12,
"name": "test2",
"process_id": "test2"
}
]
I am trying to use the filter expression to only return ones with a specific process_id field. So I change the filter to look like this.
{
"where": {"process_id": "test2"}
}
And it still returns the same results.
[
{
"id": 10,
"name": "Place Manual Payoff Order Process Config",
"process_id": "Process_PlaceManualPayoffOrderProcessConfig"
},
{
"id": 11,
"name": "test",
"process_id": "Test"
},
{
"id": 12,
"name": "test2",
"process_id": "test2"
}
]
Do filters currently work in Loopback 4 or am I using them incorrectly?
EDIT: if I post the filters in the URL string they work. It seems as though the openapi ui isn't generating that part of the filter Into the URL string.
It seems as though the openapi ui isn't generating that part of the filter Into the URL string.
Yes, this a precise description.
OpenAPI Spec version 3.x does not specify how to serialize deeply-nested values to URL queries and swagger-js, the library powering swagger-ui (which powers LoopBack's REST API Explorer), silently ignores such values.
The issue has been reported and is being discussed here:
swagger-api/swagger-js#1385
OAI/OpenAPI-Specification#1706
AppSync appears to be loading the incorrect resolver template for some fields of nested objects. Also, it appears to only happen when the nested object has a field with the same name as a field on the parent object.
I've included an example below because I think that might be the best way to explain the issue. As you can see, the id fields for the nested objects are not being resolved correctly.
Each type, Task, User, List, and Tag, have a resolver for their id field because the data for each has a prefix on the id field. For example, Task.id has a resolver that returns $context.source.task_id and User.id has a resolver that returns $context.source.user_id. Same for List and Tag.
What appears to be happening is AppSync is loading the id resolver template for the parent type. You can see that this is the case for task.owner.id, where owner is a User but the id gets resolved as "$context.source.task_id". Same for task.list.id where list is a List. Again we can see this for task.tags[0].owner.id. owner is once again a User except this time the parent is a Tag so task.tags[0].owner.id is resolved as "$context.source.tag_id". These three example show that the problem is not with a particular type since User and List are behaving the same when they are nested in a Task. Also, we can see that the issue is not with Task since User is behaving similarly when nested in a Tag. Lastly, we can see that task.tags[1].owner.id actually behaves correctly. This indicates that the issue only presents itself on first execution.
At this point I strongly suspect this is a bug with AppSync however, I'm not 100% on that. Has anyone else experienced this issue? Am I doing something terribly wrong?
Example
Query
{
task(id: "task-123") {
id,
title,
owner {
id,
username,
},
list {
id,
name,
},
tags {
id,
name,
owner {
id,
username,
},
},
},
}
Result
{
"data": {
"task": {
"id": "task-123",
"title": "First Task",
"owner": {
"id": "$context.source.task_id",
"username": "tom"
},
"list": {
"id": "$context.source.task_id",
"name": "Inbox"
},
"tags": [
{
"id": "tag-123",
"name": "one",
"owner": {
"id": "$context.source.tag_id",
"username": "tom"
}
},
{
"id": "tag-234",
"name": "two",
"owner": {
"id": "user-123",
"username": "tom"
}
}
]
}
}
}
Task Schema
type Task {
id: ID!
title: String!
owner: User!
list: List
tags: [Tag]
}
User Schema
type User {
id: ID!
username: String!
}
List Schema
type List {
id: ID!
name: String!
}
Tag Schema
type Tag {
id: ID!
name: String!
owner: User!
}
Task Data
{
task_id: "task-123",
title: "First Task",
owner_id: "user-123",
list_id: "list-123",
tags: [
"tag-123",
"tag-234"
]
}
User Data
{
user_id: "user-123",
username: "tom"
}
List Data
{
list_id: "list-123",
name: "Inbox"
}
Tag Data
{
tag_id: "tag-123",
name: "one",
owner_id: "user-123"
}
{
tag_id: "tag-234",
name: "two",
owner_id: "user-123"
}
Example id resolver (User)
Request Mapping Template
{
"version": "2017-02-28",
"payload": "$context.source.user_id"
}
Response Mapping Template
$util.toJson($context.result)
The id resolvers for the other types are very similar
It may also be worth noting that I created different None Data Sources for each type, Task, User, List, and Tag. The id resolver for each type is using their respective None Data Source.
im using Ember Data 1.13.3. and i want to convert my old JSON format to new JSONAPI format using normalizeResponse in JSONAPISerializer.
for example i have my json coming from web service like
{
user: { id: 1, name: 'wecc', accounts: [1, 2] },
accounts: [
{ id: 1, email: 'wecc#sweden.se' },
{ id: 2, email: 'wecc#greece.gr' }
]
}
now in my JSONAPISerializer how can i get the JSONAPI format out of my old json. im getting old format. but i want that format converted automatically into JSONAPI. like below one
{
data: {
id: '1',
type: 'user',
attributes: {
name: 'wecc'
},
relationships: {
accounts: {
data: [
{ id: '1', type: 'account' },
{ id: '2', type: 'account' }
]
}
}
},
included: [{
id: '1',
type: 'account',
attributes: {
email: 'wecc#sweden.se'
}
}, {
id: '2',
type: 'account',
attributes: {
email: 'wecc#greece.gr'
}
}]
}
i found some help from ember itself.
http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_internal-format-change-to-json-api
they recommand to use normalizeResponse
It won't happen automatically. If you are also in control of your REST API I'd recommend normalizing the data on the server itself. Otherwise as you suggested it will have to happen within normalizeResponse, but with custom code written to match your data format.
Another solution is to keep using the RESTSerializer for now and wait until the JSON API specification gets a bit more popular. Tools will likely be released for most server frameworks to provide standard JSON API payloads in the coming months.
Our Web API returns Ember Data compatible objects with relationships defined like so:
{containers: [
{
id: "12345678",
name: "name",
items: [1, 2]
}
],
items: [
{
id: 1
name: "item 1"
},
{
id: 2
name: "item 2"
}
]
}
Notice that the item IDs are included in the container object, and that each related item is sideloaded in the same call. Is there any way to set up this kind of relationship with RestKit?