2

I have an OpenAPI 3.0 file that specifies two REST resources with operations, let's say:

openapi: 3.0.0
[...]
paths:
  /a:
    post:
      [...]
  /b
    post:
      [...]

Then I use the openapi-generator-maven-plugin like:

<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>4.1.2</version>
  <configuration>
    [...]
    <configOptions>
      <interfaceOnly>true</interfaceOnly>
      [...]
    </configOptions>
 </configuration>
</plugin>

To generate Java interfaces, giving me:

public interface AApi {

  default Optional<NativeWebRequest> getRequest() {
    return Optional.empty();
  }

  default ResponseEntity<String> postA([...]) { [...] }

}

public interface BApi {

  default Optional<NativeWebRequest> getRequest() {
    return Optional.empty();
  }

  default ResponseEntity<String> postB([...]) { [...] }

}    

In the end, I would like to write a single class that implements both interfaces:

class TheController implements AApi, BApi { [...] }

However, the getRequest() method gets in the way, because Java is unable to inherit two default implementations with identical names.

Is there a way to suppress generating this method? (Or some other means to enable implementing both interfaces, that I haven't thought of?)

Florian
  • 4,821
  • 2
  • 19
  • 44

2 Answers2

3

I know this question is already answered, but I also had this issue and found a different solution. You can also add this in the configOptions section:

<configOptions>
    <skipDefaultInterface>true</skipDefaultInterface>
</configOptions>

It does have the 'side effect' that you no longer have default implementations.

See also documentation

  • Exactly what I was looking for. I don't think there's any point in keeping the default implementations anyway if you're just going to override the methods in a controller class. – Jaxon Crosmas Aug 24 '23 at 20:04
0

You can override the getRequest() method in your implementing controller class.

For further reading, refer to https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.8.4

rohan
  • 74
  • 4