openapi-tools / swagger-maven-plugin

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

Problem implementing oauth security scheme #88

Open ashishjadon2145 opened 2 years ago

ashishjadon2145 commented 2 years ago

The problem is with the security definition.

openapi: 3.0.1
    info:
      title: My sample API
      description: |-
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor inc

<a href="example.com">example.com</a>
      version: 1.0.0
    security:
      - /myapp-auth.json: []
    tags:
      - name: name1
        description: description1
      - name: name2
        description: description2

paths:
      /api/v1/path1:
        post:
          tags:
            - Files
          summary: sample summary
          description: some description...

The documentation of the plugin is very limited and I'm not able to use the correct syntax i guess. This is what i am doing

<plugin>
            <groupId>io.openapitools.swagger</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>2.1.6</version>
            <configuration>
                <resourcePackages>
                    <resourcePackage>com.example.controller</resourcePackage>
                </resourcePackages>
                <outputDirectory>${basedir}/src/main/resources/</outputDirectory>
                <outputFilename>swagger-file</outputFilename>
                <outputFormats>JSON</outputFormats>
                <prettyPrint>true</prettyPrint>
                <swaggerConfig>
                    <descriptionFile>${basedir}/src/main/resources/description.txt</descriptionFile>
                    <info>
                        <title>myapp API</title>
                        <version>${api.version}</version>
                    </info>
                   <securityRequirements>
                        <securityRequirement>
                            <entries>
                                <entry>
                                    <name>/myApp-auth.json</name>
                                </entry>
                            </entries>
                        </securityRequirement> 
                    </securityRequirements>
                </swaggerConfig>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

below is my myApp.json file

{
  "myApp_auth": {
    "type": "oauth2",
    "tokenUrl": "example.com",
    "flow": "password",
    "scopes": {
      "read.pet": "read scope",
      "write.pet": "modify scope",
      ...

    }
  }
}
ashishjadon2145 commented 2 years ago

@flueders I saw in one of the issues that you have implemented something similar. Can you please help?