SMILEY4 / ktor-swagger-ui

Kotlin Ktor plugin to generate OpenAPI and provide Swagger UI
Apache License 2.0
175 stars 33 forks source link

Problems to generate docs, schema o what else #22

Closed joseluisgs closed 1 year ago

joseluisgs commented 1 year ago

Hi I have the following problem when I call to a methods using Swagger UI

Curl

curl -X 'GET' \ 'http://localhost:6969/' \ -H 'accept: /*'

Request URL http://localhost:6969/*

Undocumented | Failed to fetch.Possible Reasons: CORS Network FailureURL scheme must be "http" or "https" for CORS request.

I don't have CORS configuration

I have the same problem with all endpoints an routes, this example is with a String

Here it is my conf

install(SwaggerUI) {
        swagger {
            swaggerUrl = "swagger-ui"
            forwardRoot = true
        }
        info {
            title = "Ktor Tenistas API REST"
            version = "latest"
            description = "Ejemplo de una API Rest usando Ktor y tecnologías Kotlin."
            contact {
                name = "Jose Luis González Sánchez"
                url = "https://github.com/joseluisgs"
            }
            license {
                name = "Creative Commons Attribution-ShareAlike 4.0 International License"
                url = "https://joseluisgs.dev/docs/license/"
            }
        }
        server {
            url = environment.config.property("server.baseUrl").getString()
            description = "Servidor de la API Rest usando Ktor y tecnologías Kotlin."
        }

        schemasInComponentSection = true
        examplesInComponentSection = true
        automaticTagGenerator = { url -> url.firstOrNull() }

    }

Could you help me?

joseluisgs commented 1 year ago

ok, solved!!! Please configure cors

install(CORS) { anyHost() // Permite cualquier host allowHeader(HttpHeaders.ContentType) }

joseluisgs commented 1 year ago

sorry again, I have the some problem Could you help me! CORS Network Failure URL scheme must be "http" or "https" for CORS request.

I don't know why I have problem with Chrome, using private tab to, but with Mozilla Dev I can use a GET petition to my Swagger

SMILEY4 commented 1 year ago

Hi, Guessing from your description, it's not related to the swagger-plugin, but maybe some chrome-config.

Some other things you could test: Can you successfully request the endpoints with e.g. curl or postman, or does this only affect requests by your browser - if so, check if there is some browser-config regarding CORS. Otherwise, you could also try to create a new empty sample ktor-project or a sample project with another webapp-framework/library and see if the same problem persists or if it only affects ktor.

joseluisgs commented 1 year ago

Oh, thank you so much!! It is strange, and probably it is a problem de Chrome chache or conf. Thank you so much!!!