Forum Discussion

swathi1's avatar
swathi1
Visitor
3 years ago

Swagger API specs - customize API response property usign @ApiPropertyModel

<dependencies>
  <dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-core</artifactId>
    <version>1.5.1</version>
  </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>3.1.8</version>
            <configuration>
                <apiSources>
                    <apiSource>
                        ...
                    </apiSource>
                </apiSources>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
---------------------------------

class ResponsePojo {
   ...
   @ApiModelProperty(name="metadata")
   private Map<String, Object> metadata;
   ...
}
-----------------------------------------------
Generated yaml file

definitions:
  ResponsePojo:
   type: object
   properties:
     metadata:
      type: object
      additionalProperties:
        type: object
---------------------------------------
Expected yaml file
definitions:
  ResponsePojo:
   type: object
   properties:
     metadata:
      type: object
      additionalProperties: {}
------------------------------------------

How to achieve this programmatically using ApiModelProperty ? Please advise.



No RepliesBe the first to reply