简体   繁体   中英

Swagger: maven plugin does not generate Api Model

I am trying to generate a YAML and a JSON file with the code-first approach with only the ApiModel. I want for the swagger-maven-plugin to generate only this. I don't have any web services on it. But it does not produce anything as an output. When I add a web service, it produces the files properly.

@ApiModel(value="BatchModel", description="Batch model for the documentation")
public class BatchD {

  private Long batchId;

  private String reference;

  private List<BatchStateD> batchStateList;

  public BatchD() {
    batchStateList = new ArrayList<>();
  }

  @ApiModelProperty(required = true, value = "The identification number of the batch.")
  @JsonProperty("id")
  @NotNull
  public Long getBatchId() {
    return batchId;
  }

  public void setBatchId(Long batchId) {
    this.batchId = batchId;
  }

  @ApiModelProperty(required = true, value = "The reference number of batch")
  @JsonProperty("reference")
  @NotNull
  public String getReference() {
    return reference;
  }
 <build>
    <plugins>
      <plugin>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-maven-plugin</artifactId>
        <configuration>
          <outputFileName>openapi</outputFileName>
          <outputPath>${project.build.directory}/generatedtest</outputPath>
          <outputFormat>JSONANDYAML</outputFormat>
          <prettyPrint>TRUE</prettyPrint>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>resolve</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Swagger - it is an API specification that describes your Web service. You cannot have a specification of Web service without having at least one Web service.

@ApiModel annotation just describes the structure of the model which is used in your Web service. Without using this model in the Web service, this annotation is useless.

Thereby, you are getting an expected result - there are no Swagger specification if you don't have at least one Web service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM