Openapi Beschreibung erstellen

Wiplash4

Aktives Mitglied
Ich versuche gerade eine Schnittstellenbeschreibung fuer Json-Rest Api (Restschnittstellen, welche mit Json angesprochen werden) zu erstellen
Java -> Rest-Api.json
.
Ich habe eine EJB eingebettet in eine was.ear. Ich verwende OpenApiDescription.
Die Interface-Klasse heisst AP.java und die Implementation heisst APImpl.java.

Ich google schon den ganzen Abend.
1. Welches maven plugin sollte ich verwenden?
2. Wie wird die Schnittstellenbeschreibung automatisch beim Bauen erzeugt?

Gruss
 
Ich will hier nicht zu sehr ins Detail gehen. Aber hier sind einige Details
[CODE lang="java" title="Api Interface"]import javax.ejb.Remote;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;


@Remote
@OpenAPIDefinition(tags = { @Tag(name = "widget", description = "Widget operations."),
@Tag(name = "gasket", description = "Operations related to gaskets") }, info = @Info(title = "Example API", version = "1.0.1", contact = @Contact(name = "Example API Support", url = "http://exampleurl.com/contact", email = "techsupport@example.com"), license = @License(name = "Apache 2.0", url = "http://www.apache.org/licenses/LICENSE-2.0.html")))
public interface RestApiInterface
{

/**
* @param requestData requestData
* @return String
* @throws ControlException ControlException
*/
@Operation(summary = "Start", responses = {
@ApiResponse(description = "Start", content = @Content(mediaType = "application/json", schema = @Schema(implementation = RequestData.class))),
@ApiResponse(responseCode = "400", description = "Operation not found") })
public String start(String requestData) throws ControlException;
}[/CODE]


Und dann die Implementation

[CODE lang="java" title="Implementation"]import javax.ejb.Stateless;
import javax.enterprise.inject.Default;
import javax.inject.Inject;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;


@Stateless(name = "RestImpl")
@ApplicationPath("beispiel/restImpl")
@Default
public class RestImpl extends Application implements RestApi
{
/** handlerCollection */
@Inject
protected HandlerCollection handlerCollection;

@Path("start")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Override
public String start(@PathParam("requestData") String requestData) throws ControlException
{
return <some method>;
}
}[/CODE]
 
Ich persönlich würde auf die Microprofile-Annotationen setzen: https://download.eclipse.org/microprofile/microprofile-open-api-1.0/microprofile-openapi-spec.html

Dazu gibt es ein Maven-Plugin, welches das OpenAPI-Schema zu Build-Zeit generiert: https://github.com/smallrye/smallrye-open-api/tree/master/tools/maven-plugin



Die ejb-Annotationen daran sehen etwas komisch aus, besonders das Remote – sicher, dass die gleiche Klasse sowohl JaxRS-Resource als auch als EJB-Remote-Bean fungieren soll? 😵i
 

Zurück
Oben