Swagger interface - "TypeError: Failed to fetch" with a valid response

I just removed the latest version of Swagger from the Git repository (3.0.19) using: https://github.com/swagger-api/swagger-ui.git and updated my API to use the new version.

git describe --tags for confirmation and my version now: v3.0.19-6-gaab1403

I am having the problem described here in which my answer is 403 (I see this in the inspector in the browser), and although I have the answer to 403 error, I still get the message TypeError: Failed to fetch.

enter image description here

enter image description here

Here is a snippet of my definition regarding answer 403:

                    "403": {
                    "description": "Forbidden",
                    "headers": {
                        "Access-Control-Allow-Origin": {
                            "type": "string"
                        }
                    }
                },

, , , , CORS, , , , ( 403).

- , ?

: 401 .

enter image description here

400 , :

enter image description here

+11
5

, ;

Swagger, , , AWS API Gateway.

AWS API Gateway API, . , , Swagger Access-Control-Allow-Origin:* (-) HTTP.

AWS, ( ):

https://forums.aws.amazon.com/thread.jspa?messageID=728839

Swagger UI : https://github.com/swagger-api/swagger-ui/issues/3403

/

. ( 2):

https://forums.aws.amazon.com/thread.jspa?messageID=728839

+9

( AWS). ( CORS) . , .

OpenAPI , HTTP://: 9090/. , : " http://0.0.0.0:9090/ ". , swagger http://localhost: 9090/ openapi TypeError: Failed to fetch for TypeError: Failed to fetch in results. " Access to fetch at 'http://localhost:9090/vr/variation' from origin 'http://0.0.0.0:9090'. curl ; , curl , , .

(Connexion Python openapi.)

+3

, - , 8000 , , . , .

:

app.use( (request, response, next) => {
    response.header("Access-Control-Allow-Origin", "*");
    response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});

CORS npm. https://www.npmjs.com/package/cors

+1

: - API, Asp.net Core

API Swagger. API, Asp.net Core, Apache Swagger Apache. CORS (Cross Orgin Request).

I have to modify my API code to allow a CORS request using the following code: - Declare in the Startup.cs file that has the class "StartupShutdownHandler"

private readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

Added code section in ConfigureServices method.

var str = ConfigurationHandler.GetSection<string>(StringConstants.AppSettingsKeys.CORSWhitelistedURL);
        if (!string.IsNullOrEmpty(str))
        {
            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                builder =>
                {
                    builder.WithOrigins(str);
            });
            });
        }

Added a line of code in the configuration method.

 app.UseCors(MyAllowSpecificOrigins);

Enable Cross-Query (CORS) link in ASP.NET Core

+1
source

Install Cors in your API. See the link below: https://www.npmjs.com/package/cors#usage.

0
source

Source: https://habr.com/ru/post/1678264/


All Articles