swagger-api / swagger-api/swagger-codegen
[java spring] API Key based Authentication how to access ?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
This is more of a question.
We have a swagger file with authentication mechanism as apikey and appid
security:
- apiKey: []
appId: []
Upon generation of Server ( Java Spring ) and Client (Java) below snippets got generated
Server
the interface GroupAPI has below code
@ApiOperation(value = "Return the group which was created", nickname = "createGroup", notes = "Returns HTTP 201 if the group is successfully created.", response = Void.class, authorizations = {
@Authorization(value = "apiKey"),
@Authorization(value = "appId")
}, tags={ "UserGroups", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. Request is OK."),
@ApiResponse(code = 201, message = "The request has been fulfilled, and a new resource is created ."),
@ApiResponse(code = 400, message = "Bad Request. The request cannot be fulfilled due to bad syntax."),
@ApiResponse(code = 401, message = "Unauthorized. Authentication failed or not provided"),
@ApiResponse(code = 403, message = "Forbidden. The user might not have the necessary permissions for a resource."),
@ApiResponse(code = 500, message = "Internal Server Error. An unexpected condition was encountered."),
})
@RequestMapping(value = "/identity/groups",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.POST)
ResponseEntity<Void> createGroup(@ApiParam(value = "" ,required=true ) @Valid @RequestBody Group body, @RequestHeader(value = "Accept", required = false) String accept) throws Exception;
How do we access the apikey and appId in the controller class method that looks like below ?
public ResponseEntity<Void> createGroup(@ApiParam(value = "" ,required=true ) @Valid @RequestBody Group body,
@RequestHeader(value = "Accept", required = false) String accept) throws Exception {
// do some magic!
return new ResponseEntity<Void>(HttpStatus.OK);
}
Is there any reference example , greatly appreciated .
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated GroupAPI interface and the controller method shown in the issue, then consult the Swagger Codegen Java Spring examples or documentation for API-key and appId security definitions. Confirm how generated server code exposes these values and document a reference example for accessing them in the controller.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100