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
17.03k stars 6.03k forks source link

Jaxrs-server: Support @ApiOperation authorizations scope attribute #6679

Open jfiala opened 7 years ago

jfiala commented 7 years ago
Description

The @ApiOperation authorizations attribute is currently not included in the generated code.

For details on authorizations/scopes: https://swagger.io/docs/specification/authentication/

For details on Java @ApiOperation annotation: https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#authorization-authorizationscope

Swagger-codegen version

master

Swagger declaration file content or url
"/hello": {
            "get": {
                "tags": [
                    "hello"
                ],
                "summary": "",
                "description": "",
                "operationId": "sayHello",
...
"security": [
                    {
                        "HelloWorldAuth": [
                            "read:hello_world"
                        ]
                    }
                ]
....
"securityDefinitions": {
        "HelloWorldAuth": {
            "type": "basic",
            "scopes": {
                "read:hello_world": "read hello world greetings"
            }
        },

Java-code:

    @GET
    @Path("/hello")
    @ApiOperation(value = "", tags={ "hello",  })
...
    public String sayHello(@QueryParam("name") String name);
Suggest a fix/enhancement

Add support for security attribute / authorizations

hkosova commented 4 years ago

OpenAPI 2.0 Specification allows scopes only for OAuth 2. Basic authentication does not use scopes.