How to define a property that can be string or null in OpenAPI (Swagger) without declaring it in schema? - flask-sqlalchemy

I am currently making a flask-sqlalchemy microservice and i am facing a problem with regards the acceptance of null value in OAS 3.0.0
for example
this is my request body
"Target": [
{"_id": 1, "score": null}
]
}
but when I tried to post it this is the error
{
"detail": "{'Target': [{'_id': 1, 'score': None}]} is not valid under any of the given schemas",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}
it does only accept null if I set on the schema for example
properties:
_id:
type: string
score:
type: integer
nullable: true
but when I used another data except score it doesn't allow null value
example
"Target": [
{"_id": 1, "newdata": null}
]
}
can we make it nullable even it does not declared in the schema?

Related

Having issues reusing a stored variable in Graphql query in Karate framework

I have an issue with the variable usage. Tried different options(storing variable differently, declaring, using text for defining the query, storing the query as a variable).
Still have the below error:
"errors": [
{
"message": "invalid input syntax for type uuid: \"#(queueID)\"",
"locations": [
{
"line": 1,
"column": 11
}
],
"path": [
"deleteQueue"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"name": "SequelizeDatabaseError",
"parent": {
"length": 109,
"name": "error",
"severity": "ERROR",
"code": "22P02",
"position": "34",
"file": "uuid.c",
"line": "137",
"routine": "string_to_uuid",
"sql": "DELETE FROM \"Queue\" WHERE \"id\" = '#(queueID)'"
This are my Gherkin steps:
Given request { query: 'mutation {createQueue(input: {name: "BDD-delete" }) {id} }'}
When method POST
Then status 200
And match response.data.createQueue.name == "BDD-delete"
* def queueID = response.data.createQueue.id
* print queueID
Given request { query: 'mutation {deleteQueue (id:"#(queueID)")} '}
And this is the output, when I print the queueID:
13:14:16.745 [main] INFO com.intuit.karate - [print] 758c0524-b18d-41f6-96aa-9db5eb8a7ac8
Tried using variable for the query
Given text payload =
"""
mutation {
createQueue(input: {name: "BDD-delete" })
{id, name}
}
"""
And the same tried for the deleteQueue
Feels like the issue is related with str and uuid. I must pass a uuid between the brackets in "#(queueID)"
First read this to get a sense of why this is happening: https://github.com/karatelabs/karate#rules-for-embedded-expressions
So try this:
Given request `{ query: 'mutation {deleteQueue (id:"${queueID}")} '}`
The good thing is that Karate supports JS-style placeholder replacement in strings within back-ticks.
Also refer: https://stackoverflow.com/a/69349118/143475

Facebook ads custom audience Data is missing or does not match schema error

i was building a integration with the facebook ads audience API, and according the documentation the request must be created like this:
POST - https://graph.facebook.com/v15.0/<MY_CUSTOM_AUDIENCE_ID>/users?access_token=<MY_ACCESS_TOKEN>
{
"session":{
"session_id":1,
"batch_seq":1,
"last_batch_flag":true,
"estimated_num_total":1
},
"payload":{
"schema":[
"FN"
],
"data":
[
"8b1ebea129cee0d2ca86be6706cd2dfcf79aaaea259fd0c311bdbf2a192be148"
]
}
}
Using the previus example a received a error 400:
{
"error": {
"message": "(#100) Data is missing or does not match schema",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AqrLd9uIw0D4BBFtHF33bdU"
}
}
For do this i used this documentation https://developers.facebook.com/docs/marketing-api/audiences/guides/custom-audiences#hash
Anyone has use this before?
Your schema field type is array but array use form multi-key qualification.
Change it to string: schema: 'FN'
In docs you can see all formats.
This payload with multi keys work for me:
{
"session": {
"session_id": 123,
"batch_seq": 1,
"last_batch_flag": true
},
"payload": {
"schema": [
"EMAIL",
"PHONE",
"FN"
],
"data": [
["EMAIL_HASH", "PHONE_HASH", "FN_HASH"]
]
}
}

karate API how to capture a response value to pass as request to another API [duplicate]

This question already has an answer here:
KarateDSL Parsing a value from a response and adding to next scenario payload not working
(1 answer)
Closed 1 year ago.
Capture the response field from one API call and send that as an input parameter to another API call
Given url petStoreUrl
And request { "id": 1, "category": {"id": 0 ,"name": "golden doodle" },"name": "scooby", "photoUrls": ["string"], "tags": [{ "id": 0,"name": "scooby"}],"status": "available" }
When method post
{ "id": 9199424981609294382, "category": { "id": 0, "name": "golden doodle" }, "name": "scooby1", "photoUrls": [ "string" ], "tags": [ { "id": 0, "name": "scooby" } ], "status": "available" }
i want to send the response id "id": 9199424981609294382 from the above call as an input parameter to this get request
path/id
You really need to read the documentation. The "hello world" example itself shows you how to do this.
Given path response.id
When method get
Read this section carefully: https://github.com/intuit/karate#url

How to create a bug using zoho API via postman?

I am working on Zoho API. Using postman I want to create/issue a bug in the system. For this, I am looking into Zoho Bug API. For creating a bug below are the request parameters list in the link.
Create a Bug
POST /portal/[PORTALID]/projects/[PROJECTID]/bugs/
Creates a bug.
Request Parameters
title* String Name of the bug.
description String Description of the bug.
assignee Long Assignee for the bug.
flag String Bug flag must be Internal or External.
classification_id Long Classification ID of the project.
milestone_id Long Milestone ID of the project.
due_date String [MM-DD-YYYY] Due date of the bug.
module_id Long Module ID of the project.
severity_id Long Severity ID of the project.
reproducible_id Long Reproducible ID of the project.
affectedmile_id Long Milestone ID of the project.
bug_followers Long Follower ID of the user.
uploaddoc File The maximum size to upload a file is 128 MB.
Custom Fields
CHAR1 - CHAR12 String Any text type of custom fields with string or picklist values.
LONG1 - LONG4 Long Numeric type of custom field.
DATE1 - DATE4 String [MM -DD-YYYY] Bug custom field in date format.
Sample Response
Status: 201 Created
Content Type: application/json;charset=utf-8
{
"bugs": [{
"id": 170876000001851001,
"key": "543",
"project": {
"id": 170876000000147021
},
"flag": "Internal",
"title": "UI issue in Status text box",
"reporter_id": "2060758",
"reported_person": "Patricia Boyle",
"created_time": "05-27-2014 08:38 AM",
"created_time_long": 1401188920000,
"assignee_name": "Not Assigned",
"classification": {
"id": 170876000000133041,
"type": "Feature(New)"
},
"severity": {
"id": 170876000000065005,
"type": "Major"
},
"status": {
"id": 170876000001077429,
"type": "known limitation"
},
"closed": false,
"reproducible": {
"id": 170876000000133005,
"type": "Always"
},
"module": {
"id": 170876000000494013,
"name": "ERP Phase I"
},
"link": {
"self": {
"url": "https://projectsapi.zoho.com/restapi/portal/2063927/projects/
170876000000147021/bugs/170876000001851001/"
},
"timesheet": {
"url": "https://projectsapi.zoho.com/restapi/portal/2063927/projects/
170876000000147021/bugs/170876000001851001/logs/"
}
}
}]
}
What I am doing
My request param
https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/bugs/
Key
`Authorization: myKey`
`Content Type: application/json`
In body
[{
"title": "My First Bug",
"description" :"This is my first bug",
"assignee" : "engr.usman" ,
"flag": "internal",
"classification_id": "1139168000000297069",
"milestone_id": "",
"due_date": "02-15-2018",
"module_id" : "1139168000000019372",
"severity_id" : "1139168000000007003",
"reproducible_id" : "1139168000000017069",
"status_id" :"1139168000000007045",
"resolution": "",
"affectedmile_id" : "",
"customfields": [
{
"column_name": "LONG1",
"label_name": "MSN#",
"value": "2999000190"
},
{
"column_name": "CHAR1",
"label_name": "Circle-Division-SubDivision",
"value": "Hyderabad - Latifabad - Tando Jam"
},
{
"column_name": "CHAR3",
"label_name": "LCD Indication",
"value": "S7"
},
{
"column_name": "CHAR2",
"label_name": "Reference #",
"value": "28371430034961U"
}
],
"uploaddoc" : [""]
}]
Response
{
"error": {
"code": 6831,
"message": "Input Parameter Missing"
}
}
Update 1
So just for testing it again. I have tried to send only mandatory and by default fields.
[{
"title": "My First Bug",
"flag": "internal",
"classification_id": "1139168000000297069",
"module_id" : "1139168000000019372",
"severity_id" : "1139168000000007003",
"customfields": [
{
"column_name": "CHAR2",
"label_name": "Reference #",
"value": "28371430034961U"
}
]
}]
But again I am getting same error Input Parameter Missing
I don't know why this error is generating. As there is no method of sending a request in the link.
Any help would be highly appreciated.

How to define a boolean field in MongoDB BSON document?

I'm trying to add boolean status field to a document on MongoLabs but I get a syntax error on that particular field when I try to save.
The type specifier seems 8 sees good according to the docs, but I can't find any examples on defining a boolean field within a document.
I managed to pin down the error to the status field, as the document saves without this field added.
Can anyone advise on the correct BSON syntax for the boolean field?
This is the boolean field I've added:
"status": {
{"$type": 8 } : true
}
And the complete document for reference:
{
"_id": {
"$oid": "565c4a37e4b0ed4652848949"
},
"email": "jd#outlook.com",
"products": [
{
"productId": "0121",
"price": 12.5,
"description": "A generic muffin"
},
{
"productId": "0122",
"price": 13.5,
"description": "A generic coffee"
},
{
"productId": "0123",
"price": 14.5,
"description": "A generic tea"
}
],
"date": {
"$date": "2014-03-03T03:45:00.000Z"
},
"status": {
{"$type": 8 } : true
}
}
If you wondering how to define a Boolean in a model class of node.js. If you are using MongoDB.
shopOpenStatus: {
type:Boolean,
default:"false",
required:true
}
It took me 10 min to discover this.
In case anyone else had the same issue. The data stored on MongoLabs is JSON, which is then converted to BSON locally using the driver.
The correct format below is as follows:
{
"status": true
}