papsign / Ktor-OpenAPI-Generator

Ktor OpenAPI/Swagger 3 Generator
Apache License 2.0
241 stars 42 forks source link

SecurityModel not serialized properly. #79

Closed leeaaron629 closed 3 years ago

leeaaron629 commented 3 years ago

Hi

I've gotten the JWTAuth working, but it doesn't work with the generated Swagger. This is how it's currently being generated:

{ "security": [ {} ] }

If, I modified the Swagger by adding:

{
  "security": [
    {
      "apiV1": [
        "abc"
      ]
    }
  ]
}

It works!

Also, it's generating an extra "name" field that Swagger Editor does not like.

{
  "securitySchemes": {
    "apiV1": {
      "bearerFormat": "JWT",
      "scheme": "bearer",
      "type": "http",
      "name": "apiV1"
    }
  }
}

I've made a PR to demonstrate the problem: https://github.com/papsign/Ktor-OpenAPI-Generator/pull/78

Here's the full JSON object for the path:

{"/v1":{"get":{"parameters":[{"allowEmptyValue":false,"deprecated":false,"description":"dummy query param","explode":false,"in":"query","name":"dummyQueryParam","required":false,"schema":{"nullable":false,"type":"string"},"style":"form"}],"responses":{"200":{"content":{"application/json":{"example":"OK","schema":{"nullable":false,"type":"string"}}},"description":"OK"}},"security":[{"apiV1":["abc"]},{"apiV2":[]}],"summary":"Health Check Endpoint"}}}
leeaaron629 commented 3 years ago

I took a deeper look at this and realize it doesn't serialize empty lists within the map. Is that intended?

Wicpar commented 3 years ago

The name parameter is a known issue, i'll look into it when i have some time. If you can fix it i'll accept the PR.