Why is there "no response from server" in Swagger UI? - swagger-ui

My API calls work correctly in Postman. But when I send requests from Swagger UI, it shows "no response from server" for all requests:
Response Body
no content
Response Code
0
Response Headers
{
"error": "no response from server"
}
What can the problem be and how to fix it?
The browser console shows these errors:
Failed to load resource: net::ERR_CONNECTION_REFUSED
Uncaught TypeError: Cannot read property 'length' of undefined
at showStatus (index.js:24)
at showErrorStatus (index.js:24)
at error (index.js:607) at spec-converter.js:533
at Request.callback (index.js:24)
at Request.crossDomainError (index.js:24)
at XMLHttpRequest.xhr.onreadystatechange (index.js:24)

net::ERR_CONNECTION_REFUSED sounds like you need to enable CORS on your localhost, so that it sends the Access-Control-Allow-Origin: * header in responses. How you do this depends on the server you use. More info here:
https://enable-cors.org/server.html
https://github.com/swagger-api/swagger-ui/#cors-support
You may also need to allow OPTIONS pre-flight requests.

Swagger returns 0 response code due to the Reference Looping in your serializer response.
Ignore the reference looping while getting the serializer response back.
If you are using Web API, use the following code
services.AddMvc()
.AddJsonOptions(opt =>
{
opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});

remove schemes from swagger config json file(in my case tsoa.json) and restart the server. It worked for me.
{
"readme": "https://github.com/lukeautry/tsoa/blob/HEAD/tsoa.json",
"swagger": {
"outputDirectory": "./dist/src",
"entryFile": "./src/server.ts",
"basePath": "/",
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"basic": {
"type": "basic"
}
}
},
"routes": {
"basePath": "/",
"entryFile": "./src/server.ts",
"routesDir": "./src",
"authenticationModule": "./src/security/Authentication"
}
}

In my case there was a problem with https. In swagger config the http scheme was "disabled" (not available). I had it like this:
GlobalConfiguration.Configuration.EnableSwagger(c => { c.Schemes(new[] { "https" }); });
And I had to change it to make it work in debug on localhost:
GlobalConfiguration.Configuration.EnableSwagger(c => { c.Schemes(new[] { "https", "http" }); });
The first snippet worked on production with enabled https but id didn't work while debugging in Visual Studio in default config.

In my case I was sending very simple text response e.g. "Resource not found" in the body and set Content-Type to "application/json". Depends on version Swagger has a hard time deserializing simple text to json, so im my case changing Content-Type to "text/plain" did the trick.

Related

slack send message [ERROR] missing required field: channel

I am trying to test sending message to channel via bot (App, to be exact.)
My query in Postman:
https://slack.com/api/chat.postMessage/ (there is token in headers)
and body
{"channel":"XXX","text":"I hope the tour went well, Mr. Wonka."}
But as result
{
"ok": false,
"error": "invalid_arguments",
"response_metadata": {
"messages": [
"[ERROR] missing required field: channel"
]
}
}
I had the same issue and my problem was that I was doing GET instead of POST. Now it works for me.
Please check your content-type header. It should be "application/json" instead of "plain/text"
I had to set
content-type: "application/json; charset=utf-8"
The charset mattered.
For myself, I was getting this because I was calling
POST https://slack.com/api/chat.postMessage/
The issue is in the last /. So the correct call is:
POST https://slack.com/api/chat.postMessage
EXTRA:
Here are my headers:
{
'Content-Type': 'application/json',
'charset': 'utf-8',
'Authorization': 'Bearer {YOUR_BOT_TOKEN_INSIDE_WITHOUT_CURLY_BRACKETS}'
}
and my body (make sure to put the # before the name of the channel).
{
'test': 'YOUR_TEXT_MESSAGE_IN_HERE',
'channel': '#{YOUR_CHANNEL_NAME_WITHOUT_CURLY_BRACKETS}'
}

Authentication fails on google home (oauth2)

I'm trying to connect to google home using OAuth2.0 mechanism. However, hitting with an issue where I'm not able to retrieve success message.
The failing request is - https://oauthintegrations.googleapis.com/v1/token:getForService
with the response payload as redirectState. I know about redirect but what is redirectState? I tried to search a bit over this one, but failed.
Any help would be appreciated.
Note:I have followed all the necessary steps mentioned in doc, I can receive authorisation code, but not able to make token request to desired endpoint.
The docs are https://developers.google.com/actions/identity/oauth2-code-flow and https://developers.google.com/actions/identity/account-linking.
In configuration settings we have Linking type as Oauth -> Authorization Code.
In dialog flow in Integration -> Integration Settings we have checked in for 'Sign in required' for Default Welcome Intent and have the firebase function as
app.intent('Default Welcome Intent', (conv) => {
conv.ask(new SignIn());
});
according to https://developers.google.com/actions/identity/account-linking document and I am currently using API version V2.
After the auth code is received as mentioned it does not call token url, we receive this screen :
Bad response from IdP in Auth Code Exchange & what is redirect_state
The https://gala-demo.appspot.com/app#redirect_state=XXX&state=yyy&service=abc when inspected fails at https://oauthintegrations.googleapis.com/v1/token:getForService as mentioned by #rajesh with status code 400, but when this request is made through postman it return the response. Here is the body and response for the request.
Body :
{
"credential" : {
"redirectState": "XXX"
},
"scopes": [],
"gdiState": "APP_AUTH",
"serviceId": "tapclicks-integration-adac2_dev"
}
RESPONSE :
{
"serviceInfo": {
"authUrl": "https://-domain-/authorization",
"name": "tapclicks dashboard",
"logoUrl": "https://placeholder.com/",
"clientId": "zdqexVMaVvxIMQ7Frjwa",
"tokenUrl": "https://-domian-/token_url",
"privacyPolicyUrl": "https://placeholder.com/",
"tosUrl": "https://placeholder.com/",
"id": "tapclicks-integration-adac2_dev"
},
"completionInfo": {
"appauthInfo": {
"appauthRedirectUrl": "https://-domain-/authorization?response_type=code&client_id=zdqexVMaVvxIMQ7Frjwa&redirect_uri=https://oauth-redirect.googleusercontent.com/r/tapclicks-integration-adac2&scope=gmail&state=yyy",
"appauthRedirectState": "abcxxx"
},
"oauthAuthorizationUrl": "https://-domain-/authorization?response_type=code&client_id=zdqexVMaVvxIMQ7Frjwa&redirect_uri=https://oauth-redirect.googleusercontent.com/r/tapclicks-integration-adac2&scope=gmail&state=yyy"
},
"gdiState": "APP_AUTH",
"header": {}
}
Can you please tell if i might be making any configuration mistake or any other info you need.
Authorization Url : https://kprb95tye7.execute-api.us-east-1.amazonaws.com/authorization/
Token Url : https://9343j46f16.execute-api.us-east-1.amazonaws.com/token_url/
Thanks

HTTP POST request with JSON payload from react app returns net::ERR_SSL_PROTOCOL_ERROR(chrome)

I have a react app that makes API call to the endpoint http://localhost:3020/schema/filter. Following is the payload that I am passing with the POST request.
let filterParams = {
"filter": {
"and": [{
"field": "name",
"operator": "LIKE",
"value": "Core"
}, {
"field": "created_at",
"operator": "GREATER_THAN",
"value": "05/26/2017"
}, {
"field": "created_at",
"operator": "LESS_THAN",
"value": "07/02/2017"
}]
}
}
let response = await apiService.post('https://localhost:3020/schema/filter', filterParams)
API SERVER is rails app with puma server.
Server console responds with
2017-07-04 12:04:05 +0545: HTTP parse error, malformed request ():
#<Puma::HttpParserError: Invalid HTTP format, parsing fails.
API SERVER is configured to respond to the JSON payload. Whenever I try to POST request with the payload , the browser responds with
OPTIONS https://localhost:3020/schema/filter net::ERR_SSL_PROTOCOL_ERROR in the browser console in chrome.
Similarly, safari console returns
Fetch API cannot load https://localhost:3020/schema/filter. An SSL error has occurred and a secure connection to the server cannot be made.
Seems like I am having trouble with SSL or certificates. I tried deleting browser caches, cookies and certificate itself. Still no luck.
Any help is appreciated.
This is an error because your service is posting to https://localhost but your rails server is MOST LIKELY not running with https.
If your react app, you should do something like:
var apiBase = process.env === 'PRODUCTION' ?
'https://www.productionapp.com/' : 'http://localhost:3000/'
let response = await apiService.post(apiBase + '/schema/filter', filterParams)

Simple swagger specification, to retrieve an html web page

I'm new to swagger, and I'm trying to make a very simple specification, with only a get method in order to retrieve a web page, this is the code:
{
"swagger": "2.0",
"info": {
"title": "example",
"description": "Sample api to retrieve a web page.",
"version": "0.1"
},
"host":"example.org", #"localhost:8080",
"schemes": [
"https"
],
"paths": {
"/":{
"get":{
"summary":"Return the web page.",
"description":"",
"produces":["text/html"],
"responses":{
"200":{
"description":"OK",
},
"400":{
"description":"Bad request"
},
"404":{
"description":"Not Found"
}
}
}
}
}
}
I'm using the swagger online editor.
Unfortunately when I execute the request, it did not return the web page and no one of the status code that I have implemented in the specification, it return me in the detail section the error:
TypeError: Failed to fetch
Someone can tell me where I'm wrong?
Thank you.
For the "Try it out" button to work in the Swagger online editor, your API endpoints must be CORS-enabled. That is, your server (example.org or localhost:8080) must be configured to return certain response headers that would allow editor.swagger.io to make cross-domain requests to your server. This is explained in more details here:
https://github.com/swagger-api/swagger-ui#cors-support
The way to configure CORS depends on the server/framework used to host the app. This page has instructions for some common web servers:
https://enable-cors.org/server.html

How to POST JSON request in cross domain in sencha touch

I have got following URL
https://development.avalara.net/1.0/tax/get
and would like to POST following JSON request body
{
"DocDate": "2011-05-11",
"CustomerCode": "CUST1",
"Addresses":
[
{
"AddressCode": "1",
"Line1": "435 Ericksen Avenue Northeast",
"Line2": "#250",
"PostalCode": "98110"
}
]
}
which then will give JSON response
{
"DocCode": "78b28084-8d9a-477c-9f26-afab1c0c3877",
"DocDate": "2011-05-11",
"Timestamp": "2011-05-11 04:26:41",
"TotalAmount": 10,
"TotalDiscount": 0,
"TotalExemption": 0,
"TotalTaxable": 10,
"TotalTax": 0.86,
“TotalTaxCalculated”: 0.86,
"TaxDate": "2011-05-11",
.......
}
I have tried to use
Ext.Ajax.request
but get error
Origin http://localhost is not allowed by Access-Control-Allow-Origin.
which might be due to having different domain.
So, then i tried to use JSONP
Ext.data.JsonP.request
(
{
url: 'https://development.avalara.net/1.0/tax/get',
callbackName: 'test',
method: 'POST',
jsonData: '{"DocDate": "2011-05-11", "CustomerCode": "CUST1", "Addresses": [ { "AddressCode": "1", "Line1": "435 Ericksen Avenue Northeast","Line2": "#250", "PostalCode": "98110" } ] }' ,
success: function(response) {
//do some successful stuff
Ext.Msg.alert(response);
},
failure: function(response) {
//complain
Ext.Msg.alert('fail');
}
});
But URL 404(Not Found) error is encountered and request method is GET instead of POST.
Can anyone help me how POST request body(JSON) and obtaind JSON response from different domain?
Thanks in advance
You have four options:
Use CORS. development.avalara.net would need to setup CORS on the server and allow the domain that the Sencha page is running on.
Reverse Proxy requests through a server on the domain that the Sencha page is running on:
Sencha page (mydomain.com) ---> Web Server (mydomain.com) ---> development.avalara.net
Sencha page (mydomain.com) <--- Web Server (mydomain.com) <--- development.avalara.net
You could also POST the form as a regular form post action, or POST the form inside a hidden iframe.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.Basic-cfg-standardSubmit
Run the Sencha app inside phonegap/cordova which does not block cross-domain requests.
You cannot do JSON-P with POST requests, JSON-P only supports GET requests. Your options are:
Use a GET request with JSON-P
Move the server functionality to the same server your ST app is running
Use something like Cordova and Whitelist the server you want to use for your AJAX POST requests, then use Ext.Ajax.request.

Resources