Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown response type #631

Closed
apis3445 opened this issue Mar 2, 2018 · 29 comments
Closed

Unknown response type #631

apis3445 opened this issue Mar 2, 2018 · 29 comments

Comments

@apis3445
Copy link

apis3445 commented Mar 2, 2018

I have a .NET core app I update to the last versión 2.2.0 but the swagger doesn't work, correctly the post login in the response show
Unknown response type

https://www.screencast.com/t/yb8UNne4
This is the previous versión
https://www.screencast.com/t/GMiG1RLK
I can't authorize too I try to set the bearer and token with the Word bearer token or token but doesn't works

@domaindrivendev
Copy link
Owner

Does the curl request that it's generating look correct? What happens when you run that directly from the command line?

Regarding the bearer token - you need to provide a security requirement as per the swagger spec. Read through the comments in #603

@apis3445
Copy link
Author

apis3445 commented Mar 2, 2018

the curls is correct If I try with postman works perfectly the last version all works fine

@bklooste
Copy link

bklooste commented Mar 9, 2018

Same problem juts upgraded from 1.x

works from browser url and curl. Its a simple get with no params.

In the UI

Response body
Unknown response type

Response headers
Server: nginx/1.13.4
Date: Fri, 09 Mar 2018 01:24:43 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache, no-store, max-age=0
Pragma: no-cache
Expires: -1
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Request-Context: appId=cid-v1:dd8e84f8-b600-4121-808f-0666727522b9

It hits it correctly eg
dbug: Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor[2]
Selected output formatter 'Microsoft.AspNetCore.Mvc.Formatters.JsonOutputFormatter' and content type 'application/json' to write the response.

Is the default ; charset causing an issue ?

@LunkwillAndFook
Copy link

I am seeing the same behavior in my app regarding the response type showing Unknown Response Type.

@domaindrivendev
Copy link
Owner

I’m not seeing this behavior in any of my sample apps. Could the folks on this thread help me find a repro, perhaps by starting from a blank project?

@blyles
Copy link

blyles commented Mar 9, 2018 via email

@cosmin-ciuc
Copy link

I'm having the same issue. With version 1.0.0 of Swashbuckle.AspnetCore everything works fine. I think it is a problem in the Swagger UI.

@BrightSoul
Copy link

BrightSoul commented Mar 9, 2018

Same issue here with v2.2.0. Content-Type of the response is application/json; charset=utf-8, I wonder if that ; charset=utf-8 is the source of confusion.

EDIT: nope, still happening even if I explicitly set a Content-Type of application/json. This very simple action still results in an "Unknown response type" error.

[HttpGet]
public IActionResult Get() {
  return Content("{\"result\": true}", "application/json");
}

@bklooste
Copy link

bklooste commented Mar 10, 2018

I suspect we are all adding oauth2 ... I rolled back ui to 1.2 and left everything else at 2.* and its fine. So definitely the ui package.

@domaindrivendev
Copy link
Owner

This is clearly an issue that needs to be addressed but unfortunately I can’t repro. It would be very helpful if someone could create complete repro steps, starting with a blank app. That will definitely help me get to a resolution sooner

@ChaosEngine
Copy link
Contributor

ChaosEngine commented Mar 10, 2018

I got the same behavior, but only on MS Edge browser (16.xxx). IE11 and Firefox work ok.
Tested on the basic demo.

@BrightSoul
Copy link

BrightSoul commented Mar 10, 2018

Indeed, the problem seems to be related to the Edge browser. I'm using Edge 15.x. It works fine on Chrome.
Here's a repro, it's a very simple project. Nothing really special about it.
https://github.com/BrightSoul/Swashbuckle-Issue-631-Repro

I've used the .NET Core SDK v2.0.3 for this, even though the 2.1-preview1 is installed in my system.
I've noticed Kestrel is returning this chunked response when I invoke the /api/values endpoint.

HTTP/1.1 200 OK
Date: Sat, 10 Mar 2018 08:48:27 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked

13
["value1","value2"]
0

Please note the 13 and 0 are normal, since this is a chunked response. I wonder if they're the culprit?

@blyles
Copy link

blyles commented Mar 10, 2018 via email

@blyles
Copy link

blyles commented Mar 13, 2018

Response encoded? Does that matter? I can't get time to put the repro together to help but hoping the one that BrightSoul put down.

I can confirm though it works differently between IE/Edge and Chrome.

@apis3445
Copy link
Author

Yes I test on chrome and firefox, and internet explorer 11 works, in edge doesn't work

@blyles
Copy link

blyles commented Mar 13, 2018

http://petstore.swagger.io/#/pet/addPet

Can anyone try this under edge? I don't think this is an issue with swashbuckle, i ran edge on the swagger.io site and it fails with unknown response.

<meta http-equiv="x-ua-compatible" content="IE=edge">

Is missing from 3.12 and is in the older revisions of swagger.

@BrightSoul
Copy link

Confirmed. I see the 'Unknown response type' error on petstore.swagger.io as well.

I don't think this is an issue with swashbuckle

Now that you mention it, I see a similar issue opened in the Swagger UI repository.
swagger-api/swagger-ui#3533
It seems to be related to a bug in Edge.

@blyles
Copy link

blyles commented Mar 13, 2018

There was another issue; I've lost the link now, that they removed the meta tag in 3.x. I assume that's all it is to fix it again. Until they sort out 3533 properly... doesn't seem it was done.

Found the link : swagger-api/swagger-ui#1355

@blyles
Copy link

blyles commented Mar 13, 2018

swagger-api/swagger-editor#1371 has a workaround fix, either @domaindrivendev can input or everyone has a way to work around me thinks.

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9370062/

Looks like it'll be fixed in edge... eventually, i think i'm linking this properly.

@domaindrivendev
Copy link
Owner

I’m happy to bake this into the embedded version in SB. If I do, can folks on this thread test it out (via builds of master on myget.org). With this help, especially around cross-browser regression testing, I can get an official release out sooner.

@domaindrivendev
Copy link
Owner

I’ll post here when the preview is available

@blyles
Copy link

blyles commented Mar 13, 2018

I just tested a custom index.html in my local with the override, works.

     app.UseSwagger();
	        app.UseSwaggerUI(c =>
	        {
		        c.SwaggerEndpoint("/swagger/v1/swagger.json", "Security.API V1");
                c.IndexStream = () => GetType().GetTypeInfo().Assembly
                    .GetManifestResourceStream("Security.API.CustomSwagger.html"); 
            });

And i dropped the script tag in that was in the link above.

<meta charset="UTF-8">
    <title>%(DocumentTitle)</title>
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="./swagger-ui.css">
    <link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
    <link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
    <script>
        if(window.navigator.userAgent.indexOf("Edge") > -1) {
            console.log("Removing native Edge fetch implementation");
            window.fetch = undefined;
        }
    </script>

I can get some time to test your myget hopefully sometime .. :)

@blyles
Copy link

blyles commented Mar 13, 2018

JakeChampion/fetch#407

@domaindrivendev
Copy link
Owner

The preview is now available at https://myget.org/feed/domaindrivendev/package/nuget/Swashbuckle.AspNetCore.

Looks good for me so will close issue but please test and let me know. If I get 1 or 2 confirmations I’ll release an official nuget

@BrightSoul
Copy link

Thumbs up, it's now working for me.

@rangab
Copy link

rangab commented Mar 29, 2018

@domaindrivendev did you release this? I can not install the v2.4 from above and its not available in official nuget site

@tylerje
Copy link

tylerje commented Mar 29, 2018

Me too. Really need a fix.

@LGinC
Copy link

LGinC commented Mar 31, 2018

don't use Microsoft Edge and you'll find a new world 23333333

@elguesmi
Copy link

elguesmi commented May 24, 2018

Hello

with the new version of swagger the authorization does not working in the swagger documentation page but when we use curl or postman all things workes fine so the problem was in the swagger does not put the new field in the header

you can use this code to solve this problem

` public class BasicAuthFilter : IDocumentFilter
{
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
var securityRequirements = new Dictionary<string, IEnumerable>()
{
{ "bearer", new string[] { } }
};
swaggerDoc.Security = new[] { securityRequirements };
}
}
//in startup file
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.0", new Info { Title = "Demo App API", Version = "v1.0" });
c.AddSecurityDefinition("bearer", new ApiKeyScheme
{
Description = "JWT Authorization header using the Bearer scheme. Example: "Authorization: bearer {token}"",
Name = "Authorization",
In = "header",
Type = "apiKey"
});

            c.DocumentFilter<BasicAuthFilter>();
        });

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests