Im trying to build a dashboard of apis that are used within my company to centralize and give examples and documentation. The data that I need to display has / slashes in it and cant figure out how to step into it.
data.paths/api/IDCard??
I tried escaping the slashes, I tried converting the data, I tried using ./
'/' not sure what else to do
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "IDCardRequest"
},
"host": "fasoa-prd1.corp.wpsic.com",
"basePath": "/IDCardRequest",
"schemes": [
"https"
],
"paths": {
"/api/IDCard": {
"get": {
"tags": [
"IDCard"
],
"operationId": "IDCard_Get",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
},
"post": {
"tags": [
"IDCard"
]
}
}
}
}
keep getting undefined. I want the value for the specific key that I am referencing
You can reach property data.paths["/api/IDCard"] like this.
There is a sample here.
var value = {
"paths": {
"/api/IDCard": {
"get": {
"tags": [
"IDCard"
],
"operationId": "IDCard_Get",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
},
"post": {
"tags": [
"IDCard"
]
}
}
}
}
console.log(value.paths["/api/IDCard"].get.tags)
Assuming the above object is in data,Try accessing it as follows
dataInsideGet = data.paths["/api/IDCard"]["get"]
dataInsidePost = data.paths["/api/IDCard"]["post"]
console.log(dataInsideGet) // Your desired object
Whenever you have Object keys with special characters, you should be using the array notation to access the objects.
More about Property Accessors here
Hope it helps!
Related
I'm trying to make a data request from a URL based on the data provider's API specification.
My app is built using the Node.JS and NPM.
I'm subscribed to use the API and I've verified that all my identity credentials, policies and IAM keys that give me permission to access the API.
Could someone please help me define the correct value to place inside the 'Body' parameter of my API request based on the API specification provided by the URL.
Thanks!
My current request parameter code looks like below:
const request_parameter = {
DataSetId: "xxxxxac09b4xxxxxxxxxx",
RevisionId: "xxxxxxc8df94fxxxxxxx",
AssetId: "xxxxxxx2bde1fa3xxxxxxx",
Method: "POST",
Path: "/pxxx/graphql",
QueryStringParameters: {
param1: " ",
param2: " "
},
RequestHeaders: {
"Content-Type": "application/json"
},
Body: {\"body_param\":\"body_param_value\"} // FIX ME
};
The data provider's actual API specification looks like below:
{
"openapi": "3.0.1",
"info": {
"title": "image-services",
"description": "API Gateway for integration of Platform Services into AWS Data Exchange",
"version": "2022-03-03T20:04:18Z"
},
"servers": [
{
"url": ""
}
],
"paths": {
"/psdm/graphql": {
"post": {
"requestBody": {
"description": "GraphQL query for the Catalog in the form of:\n\n `{\n availablemetadatarecord(\n QUERYPARAMS\n ) { \n FIELDLIST\n } \n }`\n",
"content": {
"application/graphql": {
"schema": {
"$ref": "#/components/schemas/CatalogSearchRequest"
},
"examples": {
"Limit returned data": {
"description": "Limit the number of records in a response.\n\nIn your query, simply specify `limit: <int>` \n",
"value": "{\n availablemetadatarecord(\n limit: 10\n content: { catalogProperties: { vendor: { eq: \"EYE\" } } }\n ) {\n assignedId\n }\n}\n"
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CatalogSearchResponse"
}
}
}
}
},
"security": [
{
"sigv4": []
}
]
}
}
},
"components": {
"schemas": {
"CatalogSearchRequest": {
"title": "CatalogSearchRequest",
"type": "object"
},
"CatalogSearchResponse": {
"title": "Catalog Search Response",
"required": [
"data",
"paginationInfo"
],
"type": "object",
"properties": {
"paginationInfo": {
"type": "object",
"properties": {
"recordsInPage": {
"type": "integer"
},
"nextOffset": {
"type": "integer"
}
}
},
"data": {
"type": "object",
"properties": {
"availablemetadatarecord": {
"type": "array",
"description": "Records returned by query",
"items": {
"type": "object"
}
}
}
}
}
}
},
"securitySchemes": {
"sigv4": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "awsSigv4"
}
}
}
}
I tried to integrate cypress and slack. I'm able to get simple notifications such as pipeline status, alert, push or merge request. My requirement is to get notification like this.
Also I'm not able to integrate reportportal, I need to get more detailed for slack notification.
I tried to follow these instructions
My cypress.json file look like this.
"reporterOptions": {
"configFile": "reporterOpts.json",
"reporterEnabled": "spec, mocha-junit-reporter, #reportportal/agent-js-cypress, mochawesome",
"reportportalAgentJsCypressReporterOptions": {
"endpoint": "https://reportportal.mlsdevcloud.com/api/v1/",
"token": "445151-w6djb-ae48-awd86wd",
"launch": "no launch",
"project": "demo",
"description": "UAT",
"autoMerge": true
},
"mochaJunitReporterReporterOptions": {
"mochaFile": "cypress/results/results-[hash].xml"
}
},
"reports": [
{
"targets": [
{
"name": "slack",
"inputs": {
"url": "https://hooks.slack.com/services/T/secreatToken/"
}
}
],
"results": [
{
"type": "junit",
"files": ["cypress/results/results-[hash].xml"]
}
]
}
]
And this is suggested json file.
{
"reports": [
{
"targets": [
{
"name": "teams",
"inputs": {
"url": "<teams-incoming-webhook-url>"
},
"extensions": [
{
"name": "report-portal-analysis",
"inputs": {
"url": "<report-portal-base-url>",
"api_key": "<api-key>",
"project": "<project-id>",
"launch_id": "<launch-id>"
}
}
]
}
],
"results": [
{
"type": "testng",
"files": ["path/to/testng-results.xml"]
}
]
}
]
}
how to pass
"launch_id": ""
it is generated every time when build is triggered.
I am trying to "push" information inside the object based on certain conditions.
I need to insert/push/assign more information within the property "materials" but I am not sure how to do this.
This is the structure of my current object:
const MYOBJECT = {
"status": "Work",
"present": true,
"materials": [
{
"link1": {
"url": "www.google.com",
}
},
{
"driveFile": {
"driveFile": {
"id": "xyz123456fghtfsdag"
},
"shareMode": "VIEW"
}
},
],
"dueDate": {
"day": resource.date_day,
"month": resource.date_month,
"year": resource.date_year
},
}
I am trying to add/push, if a condition is met, the variables shown below ("additional1" & "additional2") inside the object property "materials" without replacing/deleting any other information within the object:
var additional1 = { "link2": { "url": "www.yahoo.com", } }
var additional2 = { "link3": { "url": "www.bing.com", } }
I am looking for the END result to look like this (assuming the "if statements" / conditions are met):
const MYOBJECT = {
"status": "Work",
"present": true,
"materials": [
{
"link1": {
"url": "www.google.com",
}
},
// Insert variable addition1
{
"link2": {
"url": "www.yahoo.com",
}
},
// Insert variable addition2
{
"link3": {
"url": "www.bing.com",
}
},
{
"driveFile": {
"driveFile": {
"id": "xyz123456fghtfsdag"
},
"shareMode": "VIEW"
}
},
],
"dueDate": {
"day": resource.date_day,
"month": resource.date_month,
"year": resource.date_year
},
}
materials is an array, so you can add new members there using the push() method.
The end result would look something like this:
if (conditionIsMet) {
MYOBJECT.materials.push(additional);
}
Please note, that the push() method adds element to the end of the array, so if you want your results to reside in the middle of the array (like you did in your example) you'll need to specify additional logic for this.
I've defined the security definitions.
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"in": "header",
"name": "Authorization"
}
},
And this is my path :
"/post/user": {
"get": {
"tags": [
"Authenticated User"
],
"summary": "All User's Posts",
"description": "",
"operationId": "user-posts",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "All user's posts.",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Post"
}
}
}
}
}
},
"security": {
"Bearer": []
}
}
},
This is how I initialize my swagger-ui-express :
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
When I tried to login and add the token to the Authorize option in the top right and executed the protected path, Swagger will be loading forever. Even Swagger is not hitting the endpoint because there is no log printed in the server console.
Do you have any idea about this?
I have created my external api on loopback, i tried to use the Model.find method and other query methods, it not working for me, what i get is just error message.
Below are the message i get
the error i get
After i check it might be my api result problem, because my object is inside another object.
my api output
Can some guide me how to solve it, can change the output result?
datasources.js
"consumer_model": {
"name": "consumer_model",
"connector": "rest",
"debug": "false",
"operations": [
{
"template": {
"method": "GET",
"url": "http://myurl.com/api/v1/consumers",
"headers": {
"accepts": "application/json",
"content-type": "application/json"
},
"query": {
"id": "{id}",
"firstname": "{firstname}"
},
"responsePath": "$.data"
},
"functions": {
"consumer": [
"id",
"firstname"
]
}
}
]
}
model-config.js
"consumers": {
"dataSource": "consumer_model",
"public": true
}
myconsumer.js
module.exports = function(consumers) {
};
myconsumer.json
{
"name": "consumers",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}