-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Python] Swagger spec 2.0 with global security setting fails #7847
Comments
@ensonic thanks for reporting the issue. Looks we fixed the problem before: #1365 Have you validated your OpenAPI spec using https://editor.swagger.io or other tools? |
I am having a nearly-identical problem with the ruby client. securityDefinitions:
HttpHeaderApiKey:
type: apiKey
in: header
name: api-key
security:
- HttpHeaderApiKey: [] Debugging the ruby client, specifically def update_params_for_auth!(header_params, query_params, auth_names)
# auth_names is coming in as [] here
Array(auth_names).each do |auth_name|
auth_setting = @config.auth_settings[auth_name]
next unless auth_setting
case auth_setting[:in]
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
end
end
end |
We do have a test case for this: swagger-codegen/modules/swagger-codegen/src/test/java/io/swagger/codegen/DefaultGeneratorTest.java Line 96 in c66a0aa
The global security definition in the test spec can be found here: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/globalSecurity.json#L818-L847 |
Can you please share the full spec via https://gist.github.com so that we can more easily repeat the issue? |
Mistake on my side:
needs to be:
and
|
@ensonic no problem. Glad to hear that the issue is resolved. |
@jasonl99 if you still need help with the issue, please share the spec with us so that we can troubleshoot more easily. |
@wing328 My apologies for not reporting back sooner. I went to create a minimally viable example that failed, and found that it worked just fine. That led me to discover my original code had a careless mistake, using an underscore instead of a dash. My header's key was |
@jasonl99 no problem at all. Just let us know if you've further question or feedback. |
I'm new with codegen, I'd like some help with this: Thankss |
Description
Swagger-codegen version
2.3.1
Swagger declaration file content or url
I have this in my open-api-spec.json:
and in the code I'll do this:
expected would be a header "x-api-key: 12345", but the header is not set :/ I added some logging into the generated
api_client.py
andauth_settings
passed to__call_api()
areNone
. In the generatedmy_api.py
I seeauth_settings = []
and I think this is the cultprit.If you look at the top-level swagger object:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#swagger-object
One can attach a global security setting there.
The text was updated successfully, but these errors were encountered: