vendredi 6 août 2021

Swagger UI Access - Failed to fetch CORS, Network Failure, URL scheme must be "http" or "https" for CORS request

Swagger UI Access - Failed to fetch CORS, Network Failure, URL scheme must be "http" or "https" for CORS request.

I have my Laravel PHP application where API is hosted on https://site.example.com and I have Swagger UP API Doc hosted on https://api.example.com. when I try API on Swagger API it gives Failed to fetch Error error. Following is my swagger.json

{
"openapi": "3.0.0",
"info": {
    "title": "AustransLogistics API Documentation",
    "description": "AustransLogistics API description",
    "contact": {
        "email": "admin@admin.com"
    },
    "license": {
        "name": "Apache 2.0",
        "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
    },
    "version": "1.0.0"
},
"servers": [
    {
        "url": "https://www.austranslogistics.com.au/",
        "description": "API Server"
    }
],
"paths": {
    "/api/v1/get-quote": {
        "post": {
            "tags": [
                "GetQuote"
            ],
            "summary": "Get Quote",
            "description": "Returns Quote data",
            "operationId": "GetQuote",
            "parameters": [
                
                {
                    "name": "timepicker",
                    "in": "query",
                    "description": "Add Timepicker (hh:mm) this format",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                },
                {
                    "name": "insurable_value",
                    "in": "query",
                    "description": "Add Insurable_ Value",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                },
                {
                    "name": "declared_customs_value",
                    "in": "query",
                    "description": "Add Declared Customs Value",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }
            ],
            "responses": {
                "200": {
                    "description": "successful operation"
                },
                "400": {
                    "description": "Bad Request"
                },
                "401": {
                    "description": "Unauthenticated"
                },
                "403": {
                    "description": "Forbidden"
                }
            },
            "security": [
                {
                    "Bearer": []
                }
            ]
        }
    },


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/37qD466
via IFTTT

1 commentaire:

  1. This is because you didn't add cors in project.cs file, add the below code in project.cs file
    builder.Services.AddCors();
    app.UseCors(x => x
    .AllowAnyMethod()
    .AllowAnyHeader()
    .SetIsOriginAllowed(origin => true) // allow any origin
    .WithOrigins("https://localhost:7144") // Allow only this origin can also have multiple origins separated with comma
    .AllowCredentials()); // allow credentials

    RépondreSupprimer