swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.96k stars 6.04k forks source link

[JAVA] Using API Key in Swagger with JAVA #7090

Open MultiStorm opened 6 years ago

MultiStorm commented 6 years ago
Description

I have created a YAML file with the Swagger Editor (Local). I used API keys as security. I then downloaded the server source code via the Swagger Editor. in the Java codes, the API-KEY does not appear, if I test the server I can use the calls without API-KEY, even though this is defined differently in the YAML file. Am I doing something wrong, is my approach wrong or is this an error generating the source code?

Swagger-codegen version

Swagger Editor Version 2.10.3

Swagger declaration file content or url
Command line used for generation

no command line i use the editor

Steps to reproduce

N/A swagger (4).yaml.zip

wing328 commented 6 years ago

Which generator are you referring to?

MultiStorm commented 6 years ago

I refer to the generator supplied with the Swagger Editor. I have no extra generator installed. I downloaded the Swagger Editor from your website and put it into my Apache server. in the editor I can say above in the Generate Server Code menu. Dan I get as a download a zip file with a Maven project.

wing328 commented 6 years ago

@MultiStorm there are many different server generators listed under the "Generate Server Code" menu such as Java Spring, JAX-RS, etc

Which one did you use?

MultiStorm commented 6 years ago

oh sorry Jaxrs Cfx :-)

MultiStorm commented 6 years ago

If it helps, can you watch the whole thing via Teamviewer?

wing328 commented 6 years ago

Looks like JAX-RS CXF does not leverage {{authMethods}} at the moment:

$ grep -R -i authMethod modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/*
$ 

Would you have time to contribute the enhancement?

deki commented 6 years ago

@MultiStorm are you using OAuth2 or which kind of key/ token? I'm willing to create a PR to use CXFs BearerAuthSupplier/ CodeAuthSupplier (see http://cxf.apache.org/docs/jax-rs-oauth2.html) but first I'd like to understand your use case.

Btw could you please update the title of this issue with a more specific one?