Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint with generic type from Interface does not show up #3694

Closed
BRUTTUZ opened this issue Sep 9, 2020 · 1 comment
Closed

Endpoint with generic type from Interface does not show up #3694

BRUTTUZ opened this issue Sep 9, 2020 · 1 comment

Comments

@BRUTTUZ
Copy link

BRUTTUZ commented Sep 9, 2020

Hi,

I got a problem, which bothers me for quite a while. I hope i didnt miss anything, but i just can't figure out, whats wrong.

I have a basic rest service:

package org.example;

import io.swagger.v3.oas.annotations.Operation;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import java.util.List;

@Path("")
public class FooService implements Foo<String> {

    // Does not show up!
    @POST
    @Path("fooList")
    @Operation(summary = "Foo List in Interface", tags = "Foo")
    @Override
    public Response fooList(List<String> foo) {
        return null;
    }

    // Does show up!
    @POST
    @Path("barList")
    @Operation(summary = "Bar List in Interface", tags = "Bar")
    public Response barList(List<String> bar) {
        return null;
    }
}

The fooList endpoint comes from an interface:

package org.example;

import javax.ws.rs.core.Response;
import java.util.List;

public interface Foo<T> {
    Response fooList(List<T> foo);
}

The resulting openapi.yaml does only show the barList Method:

openapi: 3.0.1
paths:
  /barList:
    post:
      tags:
      - Bar
      summary: Bar List not in Interface
      operationId: barList
      requestBody:
        content:
          '*/*':
            schema:
              type: array
              items:
                type: string
      responses:
        default:
          description: default response
          content:
            '*/*': {}

I figured out, that it does work, when I don't implement the method, so lets say, I got another method in the interface and provide a default implementation:

public interface Foo<T> {
    // Method. thats being implemented
    Response fooList(List<T> foo);

    // Method, thats not being implemented
    @POST
    @Path("fooListNotImplemented")
    @Operation(summary = "Foo List not implemented", tags = "Foo")
    default Response fooListNotImplemented(List<T> fooNotImplemented) {
        return null;
    }
}

The method fooListNotImplemented does show up, fooList does not show up:

openapi: 3.0.1
paths:
  /barList:
    post:
      tags:
      - Bar
      summary: Bar List not in Interface
      operationId: barList
      requestBody:
        content:
          '*/*':
            schema:
              type: array
              items:
                type: string
      responses:
        default:
          description: default response
          content:
            '*/*': {}
  /fooListNotImplemented:
    post:
      tags:
      - Foo
      summary: Foo List not implemented
      operationId: fooListNotImplemented
      requestBody:
        content:
          '*/*':
            schema:
              type: array
              items:
                type: string
      responses:
        default:
          description: default response
          content:
            '*/*': {}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>swagger-typeparam</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <version>4.3.1.Final</version>
        </dependency>
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>2.0.10</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>swagger-ui</id>
                        <goals>
                            <goal>wget</goal>
                        </goals>
                        <configuration>
                            <url>https://github.com/swagger-api/swagger-ui/archive/master.tar.gz</url>
                            <unpack>true</unpack>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/${project.artifactId}-${project.version}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/swagger-ui-master/dist</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>2.1.4</version>
                <configuration>
                    <outputFileName>openapi</outputFileName>
                    <outputPath>${project.build.directory}/${project.artifactId}-${project.version}</outputPath>
                    <outputFormat>JSONANDYAML</outputFormat>
                    <resourcePackages>
                        <package>org.example</package>
                    </resourcePackages>
                    <prettyPrint>true</prettyPrint>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>resolve</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

I hope I didnt miss anything stupid. Thank you for your work and have a nice day!
Christopher

frantuma added a commit that referenced this issue Sep 24, 2020
frantuma added a commit that referenced this issue Sep 24, 2020
refs #2144, refs #3149, refs #3426, refs #3694 - fix overridden generic resources methods
@frantuma
Copy link
Member

thanks for reporting this! should be fixed in #3795, closing ticket, please reopen if you're still experiencing issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants