swagger-maven-plugin not producing keys and values, results in "empty" swagger.json
c1910475054 opened this issue · 0 comments
c1910475054 commented
I am missing all the api and model attributes in my swagger.json file. I provided my pom.xml, the restcontroller with the annotations, the swagger.json and the stacktrace when using maven install
My pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependencies>
<dependency>
<groupId>com.mart11.backend</groupId>
<artifactId>mart11-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<nodeVersion>v14.16.0</nodeVersion>
<npmVersion>7.6.0</npmVersion>
<resources.generated>${project.build.directory}/generated-resources</resources.generated>
<sources.generated>${project.build.directory}/generated-sources</sources.generated>
<swagger.json.output>${resources.generated}/swagger</swagger.json.output>
<swagger.templates.folder>${project.basedir}/swagger</swagger.templates.folder>
<swagger.ts.output>${sources.generated}/swagger</swagger.ts.output>
<swagger.html.output>${project.build.directory}/classes/public/swagger</swagger.html.output>
</properties>
<build>
<plugins>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<mkdir dir="${project.build.directory}/classes"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.parent.groupId}</groupId>
<artifactId>mart11-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</artifactItem>
</artifactItems>
<outputDirectory>${resources.generated}</outputDirectory>
<includes>swagger/**/*.mustache</includes>
</configuration>
<executions>
<execution>
<id>unpack mustache template</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>${com.github.kongchen.swagger-maven-plugin.version}</version>
<executions>
<execution>
<id>Generate Swagger JSON</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<apiSources>
<apiSource>
<schemes>https</schemes>
<basePath>localhost:8080/</basePath>
<springmvc>true</springmvc>
<locations>
<location>com.mart11.controller</location>
</locations>
<info>
<title>${project.name}</title>
<version>${project.version}</version>
</info>
<swaggerDirectory>${swagger.json.output}</swaggerDirectory>
</apiSource>
</apiSources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<execution>
<id>Generate TypeScript API</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<inputSpec>${swagger.json.output}/swagger.json</inputSpec>
<generatorName>typescript-angular</generatorName>
<output>${swagger.ts.output}</output>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My RestController:
import com.mart11.dto.ReserveTableDTO;
import com.mart11.service.ReservationTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.util.List;
@Api(value = "ReservationApi")
@RequestMapping
@RestController
public class ReservationController {
private static final Logger LOGGER = LoggerFactory.getLogger(ReservationController.class);
private final ReservationTableService reservationTableService;
public ReservationController(ReservationTableService reservationTableService) {
this.reservationTableService = reservationTableService;
}
@ApiOperation("Return account settings for the user")
@GetMapping(value = "/api/getAllByDate", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiResponses({
@ApiResponse(code = 200, message = "", response = List.class),
@ApiResponse(code = 500, message = "", response = SQLException.class)
})
public @ResponseBody
List<ReserveTableDTO> getAllReservationsByDate(@RequestParam String date) throws SQLException {
LOGGER.debug("JSON/REST GET call on /api/getAllByDate for date '{}'", date);
return reservationTableService.getAllTablesByDate(date);
}
}
The generated swagger.json file:
{
"swagger" : "2.0",
"info" : {
"version" : "0.0.1-SNAPSHOT",
"title" : "Mart 11 Frontend"
},
"basePath" : "localhost:8080/",
"schemes" : [ "https" ]
}
Maven install:
[INFO] --- maven-dependency-plugin:3.1.2:unpack (unpack mustache template) @ mart11-frontend ---
[INFO] Configured Artifact: com.mart11:mart11-backend:0.0.1-SNAPSHOT:jar
[INFO] Unpacking C:\Users\aleks\mart11-reservation\mart11-backend\target\mart11-backend-0.0.1-SNAPSHOT.jar to C:\Users\aleks\mart11-reservation\mart11-frontend\target\generated-resources with includes "swagger/**/*.mustache" and excludes ""
[INFO]
[INFO] --- swagger-maven-plugin:3.1.7:generate (Generate Swagger JSON) @ mart11-frontend ---
[INFO] Reflections took 43 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 23 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 18 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 15 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 16 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 15 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 15 ms to scan 99 urls, producing 0 keys and 0 values
[INFO] Reflections took 20 ms to scan 99 urls, producing 0 keys and 0 values
[INFO]
[INFO] --- openapi-generator-maven-plugin:5.0.0:generate (Generate TypeScript API) @ mart11-frontend ---
[WARNING] C:\Users\aleks\mart11-reservation\mart11-frontend\target\generated-resources\swagger\swagger.json [0:0]: unexpected error in Open-API generation
org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
| Error count: 1, Warning count: 0
Errors:
-attribute paths is missing
at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:541)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:568)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:717)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
[ERROR]
org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
| Error count: 1, Warning count: 0
Errors:
-attribute paths is missing
at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:541)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:568)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:717)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for mart11 0.0.1-SNAPSHOT:
[INFO]
[INFO] mart11 ............................................. SUCCESS [ 0.293 s]
[INFO] Mart 11 Backend .................................... SUCCESS [ 2.369 s]
[INFO] Mart 11 Frontend ................................... FAILURE [ 4.294 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------