2

I am running two different Payara Micro microservices in one cluster.

The issue I have is that when I try to access the OpenAPI URL of MyApp1 like http://mylink.com/myApp1/openapi it does not work. It actually works when I use URL http://mylink.com/openapi.

This becomes an issue when I want to see the API for the other microservice like http://mylink.com/myApp2/openapi which does not work.

Is there a way in Payara Micro of telling OpenAPI to use the application's context in it's path just like all the other URL in the application do?

FourtyTwo
  • 734
  • 8
  • 19

3 Answers3

1

As you can see in my previous comment, I've also struggled with the same situation.

Context - openapi and microprofile

First let me say that having /openapi URL in the root is the intended behaviour of microprofile-open. Documentation always uses /openapi path as the right to get the document LINK

In the implementation, is very clear that this behaviour is both wanted as enforced: In the ServletContainerInitializer for OpenApi one can see the following code

  // Only deploy to app root
    if (!"".equals(ctx.getContextPath())) {
        return;
    }

Workaround aka Solution.

Now that is clear that we cannot configured this, since it's intended behaviour, one solution ( the one I'm proposing ) is to proxy the request to /YOUR_APP/openapi to /openapi. Since my application is a jax-rs one, deployed on openshift, and I don't want to have a dedicated proxy application for this, I've just created a simple Resource/Controller to proxy this specific request for me. The outstanding method behind:

@GET
@Path("")
public Response proxyOpenApiCall(){
    log.debug("proxyOpenApiCall called");
    String entity = client.target("http://localhost:8080")
            .path("openapi").request()
            .get(String.class);

    return Response.ok(entity).build();
}
Gonçalo
  • 561
  • 5
  • 14
1

I was able to fix this with a small forward proxy. Therefore I create a new REST enpoint wich is callable from public and returns the content of internal http endpoint.

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@RequestScoped
@ApplicationPath("/")
@Path("/")
public class OpenApiProxyRestFacade extends Application {

    private Client client;

    @PostConstruct
    public void init() {
        this.client = ClientBuilder.newClient();
    }

    @GET
    @Path("/openapi")
    @Produces(MediaType.APPLICATION_JSON)
    public Response proxyOpenApiCall() {
        String entity = client.target("http://localhost:9080").path("openapi").request().get(String.class);
        return Response.ok(entity).build();
    }
    
    @GET
    @Path("/openapi/ui")
    @Produces(MediaType.APPLICATION_JSON)
    public Response proxyOpenApiUiCall() {
        String entity = client.target("http://localhost:9080/openapi").path("ui").request().get(String.class);
        return Response.ok(entity).build();
    }

    @PreDestroy
    public void destroy() {
        this.client.close();
    }
}
Michi-2142
  • 1,170
  • 3
  • 18
  • 39
0

For openapi, you can set this property for change of url, so it is configurable after all

mp.openapi.extensions.path=/yourapi/whatever

and for the openapi-UI set this

openapi.ui.yamlUrl=/yourapi/whatever

Sources: I first googled for mp.openapi.xxx parameters, (I found them in source code) which led me to this url https://download.eclipse.org/microprofile/microprofile-open-api-1.0/microprofile-openapi-spec.html

and after looking for more stuff there was one simple sentence mentioning that there is also mp.openapi.extensions and after googling those further I found this random doc here https://github.com/wildfly/wildfly/blob/main/docs/src/main/asciidoc/_admin-guide/subsystem-configuration/MicroProfile_OpenAPI.adoc

hocikto
  • 871
  • 1
  • 14
  • 29