0

我需要在 maven 构建阶段生成招摇,为此我使用openapi-tools/swagger-maven-plugin

问题在于安全定义。

 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...

 

该插件的文档非常有限,我猜我无法使用正确的语法。这就是我正在做的

<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>

下面是我的 myApp.json 文件

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

    }
  }
}
4

0 回答 0