openapi-tools / swagger-maven-plugin

Maven plugin to activate the Swagger Core library to generate OpenAPI documentation.
MIT License
72 stars 46 forks source link

Problem at generation of security scheme #71

Closed flueders closed 3 years ago

flueders commented 3 years ago

Describe the bug I want to add A SecurityRequirement to my Open API docs.

After interpreting https://github.com/openapi-tools/swagger-maven-plugin/blob/master/src/main/java/io/openapitools/swagger/config/SwaggerSecurityRequirement.java , this is what I did:

<components>
    <securitySchemes>
        <authorization>
            <type>apiKey</type>
            <name>Authorization</name>
            <in>header</in>
            <scheme>http</scheme>
        </authorization>
        <area>
            <type>apiKey</type>
            <name>Area</name>
            <in>header</in>
            <scheme>http</scheme>
        </area>
    </securitySchemes>
</components>
<securityRequirements>
    <authorization>
        <entries>
            <name>Authorization</name>
        </entries>
    </authorization>
    <area>
        <entries>
            <name>Area</name>
        </entries>
    </area>
</securityRequirements>

This produces the following error:

[ERROR] Failed to execute goal io.openapitools.swagger:swagger-maven-plugin:2.1.5:generate (default) on project application-webservices:
Unable to parse configuration of mojo io.openapitools.swagger:swagger-maven-plugin:2.1.5:generate for parameter name: 
Cannot find default setter in class io.openapitools.swagger.config.SwaggerSecurityRequirement$Entry -> [Help 1]

However, if I remove the <name> tags from inside the <entries>, the maven-plugin does not throw any error. But looking at the generated file, this is what was generated:

"security" : [ null, null ]

Expected behavior The expected result would be :

  "security" : [ {"Authorization": []}, {"Area": []}],

Note: the securitySchemes tag is being created correctly. But to enable the schemes globally, the additional security tag is needed.

So this seems to be a bug while parsing the configuration. Or is there just a mistake in my configuration?

flueders commented 3 years ago

@langecode Can you or someone else help me here? Thanks in advance!

langecode commented 3 years ago

Yeah there is agre PRs and issues laying around. I hope to find some time to look at this during the Christmas holidays. I cannot remember if we did implement support for this but otherwise there are other ways to add the security parts to the output.

man. 21. dec. 2020 kl. 16.18 skrev Fabian Lüders notifications@github.com:

@langecode https://github.com/langecode Can you or someone else help me here? Thanks in advance!

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/openapi-tools/swagger-maven-plugin/issues/71#issuecomment-749026140, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPWOQ6IIX72WAGDVDQTI3SV5RLLANCNFSM4U7OHGQQ .

langecode commented 3 years ago

You might take a look at the example in the unittests: https://github.com/openapi-tools/swagger-maven-plugin/blob/master/src/test/resources/generate-mojo-full-pom.xml#L60

This should explain how to add the areas :-)

flueders commented 3 years ago

Thank you very much! This helped to solve my problem.

Just for the record, this is how it is done:

<securityRequirements>
    <authorization>
        <entries>
            <entry>
                <name>authorization</name>
            </entry>
        </entries>
    </authorization>
</securityRequirements>