swagger UI unable to process swagger.json that redoc is able to - swagger-ui

I have the following simple swagger.json file. This is generated using go-swagger annotations for a golang service. I am able to get the UI page running with redoc.
I want to display it with swagger-ui but I cannot get it to work. It shows an error in console on the page load that says
Uncaught TypeError: Cannot create property 'definitions' on string 'swagger.json'(…)
window.swaggerUi = new SwaggerUi({
spec: "swagger.json",
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
log("Loaded UI")
},
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none",
jsonEditor: false,
defaultModelRendering: 'schema',
showRequestHeaders: false
});
window.swaggerUi.load();
Not sure why that is happening
The redoc page displays as follows
This is the swagger file
{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"swagger": "2.0",
"info": {
"description": "the purpose of this service is to do a health check",
"title": "Health Check API.",
"termsOfService": "TOS",
"contact": {
"name": "Backend",
"email": "Backend#company.com"
},
"license": {
"name": "Company Licence"
},
"version": "0.0.1"
},
"host": "host.com",
"basePath": "/",
"paths": {
"/health": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"summary": "Health check route.",
"operationId": "health",
"responses": {}
}
}
},
"definitions": {}
}

From SwaggerUI docs, it seems that it expects
A JSON object describing the OpenAPI Specification
as a value of spec parameter.
You should use url if you want to provide it with url:
window.swaggerUi = new SwaggerUi({
url: "swagger.json", // <----------------- change to url here
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function(swaggerApi, swaggerUi){
log("Loaded UI")
},
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none",
jsonEditor: false,
defaultModelRendering: 'schema',
showRequestHeaders: false
});
window.swaggerUi.load();

Related

KRAKEND [JWTValidator] Unable to validate the token: should have a JSON content type for JWKS endpoint

I get the following error while evaluating krakend on MacOS with latest from brew...
[KRAKEND] 2022/09/20 - 11:51:32.488 ▶ ERROR [ENDPOINT: /geo/v1/countries][JWTValidator] Unable to validate the token: should have a JSON content type for JWKS endpoint
My JWKS from keycloak running on AWS does seem to set the Content-Type properly so I do not understand the issue...
{
"$schema": "https://www.krakend.io/schema/v3.json",
"version": 3,
"name": "KrakenD - API Gateway",
"extra_config": {
"security/cors": {
"allow_origins": [
"*"
],
"expose_headers": [
"Content-Length",
"Content-Type"
],
"max_age": "12h",
"allow_methods": [
"GET",
"HEAD"
]
},
"telemetry/logging": {
"level": "DEBUG",
"prefix": "[KRAKEND]",
"syslog": false,
"stdout": true
}
},
"timeout": "3000ms",
"cache_ttl": "300s",
"output_encoding": "json",
"endpoints": [
{
"endpoint": "/geo/v1/countries",
"method": "GET",
"backend": [
{
"url_pattern": "/geo/v1/countries",
"is_collection": true,
"sd": "static",
"method": "GET",
"host": [
"https://api.sophware.com"
],
"disable_host_sanitize": false
}
],
"extra_config": {
"qos/ratelimit/router": {
"max_rate": 0,
"client_max_rate": 10,
"strategy": "header",
"key": "Authorization"
},
"auth/validator": {
"alg": "RS256",
"jwk_url": "https://auth.sophware.com/realms/sophware/protocol/openid-connect/certs",
"issuer": "https://auth.sophware.com/realms/sophware",
"operation_debug": true,
"cache": true
}
}
},
{
"endpoint": "/geo/v1/features",
"method": "GET",
"backend": [
{
"url_pattern": "/geo/v1/features",
"is_collection": true,
"sd": "static",
"method": "GET",
"host": [
"https://api.sophware.com"
],
"disable_host_sanitize": false
}
],
"extra_config": {
"qos/ratelimit/router": {
"max_rate": 0,
"client_max_rate": 5,
"strategy": "ip"
}
}
}
]
}
The error might be misleading because the JWT validation does not have a specific message when there are connectivity errors, but if you are sure the content is well-formed JSON, then the problem is mostly reaching the JWK URL.

How to make multipart/form-data multiples propreties required in swagger

Swagger execution works but it displays "unvalid" for multiple required propreties.
this is the error message:
{"messages":["attribute paths.'/smile_video'(post).requestBody.content.'multipart/form-data'.schema.required is not of type `array`"],"schemaValidationMessages":[{"level":"error","domain":"validation","keyword":"oneOf","message":"instance failed to match exactly one schema (matched 0 out of 2)","schema":{"loadingURI":"#","pointer":"/definitions/Operation/properties/requestBody"},"instance":{"pointer":"/paths/~1smile_video/post/requestBody"}}]}
This is the request body definition:
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"required": [
"video",
"encodings"
],
"properties": {
"video": {
"type": "string",
"format": "binary",
"description": "Upload video file"
},
"encodings": {
"type": "string",
"format": "binary",
"description": "Upload video file "
}
}
}
}
}
}
This is the swagger screenshot
The solution is to disable validation by adding validatorUrl : false
const ui = SwaggerUIBundle({
url: "***",
dom_id: '#swagger-ui',
deepLinking: true,
validatorUrl : false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
]
});

Handling user interaction - Click Button message is not like documented

I'm experimenting ways to allow users to interact with my app through Slack.
So far, I was able to create a Home App, so that when the user clicks on the app it displays a neat page, with formatted text, images, and some action buttons (built with Block Kit).
What I am not being able to do is handling the user interactions, specifically when the user clicks one of the buttons. I got Slack to invoke my app's API, but the message I receive is absolutely nothing to do with the documentation.
On Slack, I set up Interactivity & Shortcuts, sending all requests to https://slack-interaction-sample.xpto.com/slack/v1/actions.
I then send a message to Slack, using Block Kit, containing a simple button:
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*JT*\nBackend Developer # ${ currentTime }`
},
"accessory": {
"type": "image",
"image_url": "https://i.pinimg.com/474x/fb/b5/b6/fbb5b6798f31538f2497e7ceb2b52674.jpg",
"alt_text": "JT"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Do Stuff",
"emoji": true
},
"style": "primary",
"value": "doStuff"
}
]
}
]
This message is correctly displayed on Slack. When I click the button, Slacks sends a request to the configured URL and, on my nodejs instance, the following code is executed:
app.post("/slack/v1/actions", function(req, res) {
console.log("**********************************************************");
console.log("/slack/v1/actions");
console.log("**********************************************************");
console.log("Request: %s",req);
res.status(200);
res.json({});
console.log("**********************************************************");
});
According to Slack's documentation (https://api.slack.com/interactivity/handling), I should be getting a payload parameter with something like this:
[
{
"action_id": "action-id-0",
"block_id": "/RXP",
"text": {
"type": "plain_text",
"text": "Ask",
"emoji": true
},
"value": "approve",
"style": "primary",
"type": "button",
"action_ts": "1588254893.249857"
}
]
Instead, what I get is this:
IncomingMessage {
_readableState: [ReadableState],
readable: true,
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
socket: [Socket],
connection: [Socket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: false,
headers: [Object],
rawHeaders: [Array],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '/slack/v1/actions',
method: 'POST',
statusCode: null,
statusMessage: null,
client: [Socket],
_consuming: false,
_dumped: false,
next: [Function: next],
baseUrl: '',
originalUrl: '/slack/v1/actions',
_parsedUrl: [Url],
params: {},
query: {},
res: [ServerResponse],
body: {},
route: [Route],
[Symbol(kCapture)]: false
}:
´´´
Any ideas on what I am doing wrong?
Thank you!

swagger file content is not updating in aws apigateway

I am working on swagger file, To create the authorizer in aws apigateway.But that time I 'll mention some function and api in swagger file.But it not effecting in the Apigateway.Once I deleted the stack,It will effect the APIgateway.If any changes is did that not effecting the APIgateway.Below I mentioning the template.yml file and swagger file.Please anyone will help to solve this issue.
template.yml file
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: TestApi
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://devdeliforcemumbailambda/swagger-json-testapi.json
DriverDeleteF:
Type: AWS::Serverless::Function
Properties:
FunctionName: driver_delete_fun
Handler: index.handler
Runtime: nodejs8.10
CodeUri: build/authorizer.zip
Events:
GetApi:
Type: Api
Properties:
Path: /driver
Method: delete
swagger file content
{
"swagger": "2.0",
"info": {
"title": "demo"
},
"host": "rl0cg75uff.execute-api.ap-south-1.amazonaws.com",
"basePath": "/Prod",
"schemes": [
"https"
],
"paths": {
"/driver": {
"delete": {
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "200 response",
"schema": {
"$ref": "#/definitions/Empty"
}
}
},
"security": [
{
"CognitoAuth": []
}
],
"x-amazon-apigateway-integration": {
"uri": "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-south-1:539977196287:function:driver_delete_fun/invocations",
"responses": {
"default": {
"statusCode": "200"
}
},
"passthroughBehavio r": "when_no_match",
"httpMethod": "POST",
"contentHandling": "CONVERT_TO_TEXT",
"type": "aws"
}
}
},
},
"securityDefinitions": {
"CognitoAuth": {
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "cognito_user_pools",
"x-amazon-apigateway-authorizer": {
"providerARNs": [
"arn:aws:cognito-idp:ap-south-1:539977196287:userpool/ap-south-1_6j7axGXVm"
],
"type": "cognito_user_pools"
}
},
"lambdaAuth":{
"type": "apiKey",
"name": "Authorization",
"in": "header",
"x-amazon-apigateway-authtype": "custom",
"x-amazon-apigateway-authorizer": {
"authorizerUri": "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-south-1:539977196287:function:my-service-dev-hello/invocations",
"authorizerResultTtlInSeconds":1,
"identitySource": "method.request.header.Authorization",
"type": "request"
}
}
},
"definitions": {
"Empty": {
"type": "object",
"title": "Empty Schema"
}
}
}
Cloudformation does not compare the contents of your s3 object when you specify an S3 uri in DefinitionUri. You can instead specify a relative local path and have cloudformation cli upload it for you just as it usually does with function code. Cloudformation will then use your file hash in the s3 object key, hence having different DefinitionUri and CodeUri everytime they contain changes.
Therefore, instead of having these:
DefinitionUri: s3://devdeliforcemumbailambda/swagger-json-testapi.json
CodeUri: build/authorizer.zip
do this:
DefinitionUri: ./swagger-json-testapi.json
CodeUri: ./authorizer-code-directory
What I wrote is applicable to the following: (up to date docs here)
BodyS3Location property for the AWS::ApiGateway::RestApi resource
Code property for the AWS::Lambda::Function resource
CodeUri property for the AWS::Serverless::Function resource
DefinitionUri property for the AWS::Serverless::Api resource
SourceBundle property for the AWS::ElasticBeanstalk::ApplicationVersion resource
TemplateURL property for the AWS::CloudFormation::Stack resource
Deploy your stack as follows:
aws cloudformation package --template-file template.yaml --s3-bucket devdeliforcemumbailambda --output-template-file packaged-template.yaml
aws cloudformation deploy --capabilities CAPABILITY_NAMED_IAM --stack-name test-swagger --template-file packaged-template.yaml

API Call 'tabs.captureVisibleTab' is not supported in Edge

I'm using Edge on Windows 10 v1703, build 15063.296.
The documentation (https://learn.microsoft.com/en-us/microsoft-edge/extensions/api-support/supported-apis) states, that the API tabs.captureVisibleTab is available.
But when I use it in the background script, I'm getting the following error:
API Call 'tabs.captureVisibleTab' is not supported in Edge.
The code is:
browser.tabs.captureVisibleTab(currentTab.windowId, {format: "png"}, function (data) {});
Am I missing something?
UPDATE:
this is my manifest file (ported from Chrome):
{
"author": "Evgeny Suslikov",
"background": {
"page": "background.html",
"persistent": true
},
"browser_action": {
"default_icon": {
"19": "images/sss_19.png"
},
"default_title": "FireShot - Capture page",
"default_popup": "fsPopup.html"
},
"commands": {
"last-used-action": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y"
},
"description": "__MSG_options_label_last_action_hotkey__"
}
},
"default_locale": "en",
"description": "__MSG_application_description__",
"icons": {
"16": "images/sss_16.png",
"32": "images/sss_32.png",
"48": "images/sss_48.png",
"128": "images/sss_128.png"
},
"Key": "B5SSrXXpDZAoT8SQ4vAzNeTQ1tBC2Z24nx+hHZXfykmVYfMy5aOwPkf0Hbt7SXlKbprwV0GwrYgCwIDAQAB",
"manifest_version": 2,
"name": "__MSG_application_title__",
"offline_enabled": true,
"optional_permissions": [
"tabs",
"<all_urls>",
"downloads"
],
"options_page": "fsOptions.html",
"permissions": [
"activeTab",
"tabs",
"contextMenus",
"nativeMessaging"
],
"short_name": "FireShot",
"version": "0.98.92",
"web_accessible_resources": [
"images/*.gif"
],
"-ms-preload": {
"backgroundScript": "backgroundScriptsAPIBridge.js",
"contentScript": "contentScriptsAPIBridge.js"
},
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["scripts/fsUtils.js", "scripts/fsSelection.js", "scripts/fsLinks.js", "scripts/fsContent.js"]
}]
}
In my fsBackground.js page I do the call:
browser.tabs.captureVisibleTab(windowId, {format: "png"}, function (data) {});
I get the following error: click to see screenshot...
That function is supported starting from Edge 15. On previous versions it was still unsupported, even though the documentation said differently.
Make sure to download the latest version of Microsoft Edge Extension Toolkit and to regenerate the bridge files with it.
You can look at the generated backgroundScriptsAPIBridge.js file to see what's changed.
Previous versions (unsupported):
captureVisibleTab(windowId, options, callback) {
bridgeLog.LogUnavailbleApi("tabs.captureVisibleTab");
}
New version (supported):
captureVisibleTab(windowId, options, callback) {
bridgeLog.DoActionAndLog(() => {
myBrowser.tabs.captureVisibleTab.apply(null, arguments);
}, "tabs.captureVisibleTab");
}

Resources