Search in sources :

Example 26 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class FilterUtil method filterServers.

/**
 * Filters the given model.
 * @param filter
 * @param models
 */
private static void filterServers(OASFilter filter, List<Server> models) {
    if (models == null) {
        return;
    }
    ListIterator<Server> iterator = models.listIterator();
    while (iterator.hasNext()) {
        Server model = iterator.next();
        filterServer(filter, model);
        if (filter.filterServer(model) == null) {
            iterator.remove();
        }
    }
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server)

Example 27 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project wildfly-swarm by wildfly-swarm.

the class ServersUtil method configureServers.

/**
 * Configures the servers for an Operation.
 * @param config
 * @param operation
 */
protected static void configureServers(OpenApiConfig config, Operation operation) {
    if (operation == null) {
        return;
    }
    if (operation.getOperationId() == null) {
        return;
    }
    Set<String> operationServers = config.operationServers(operation.getOperationId());
    if (operationServers != null && !operationServers.isEmpty()) {
        operation.servers(new ArrayList<>());
        for (String operationServer : operationServers) {
            Server server = new ServerImpl();
            server.setUrl(operationServer);
            operation.addServer(server);
        }
    }
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) ServerImpl(org.wildfly.swarm.microprofile.openapi.api.models.servers.ServerImpl)

Example 28 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project microprofile-open-api by eclipse.

the class ModelConstructionTest method pathItemTest.

@Test
public void pathItemTest() {
    final PathItem pi = processConstructible(PathItem.class);
    final Parameter p = createConstructibleInstance(Parameter.class);
    checkSameObject(pi, pi.addParameter(p));
    checkListEntry(pi.getParameters(), p);
    assertEquals(pi.getParameters().size(), 1, "The list is expected to contain one entry.");
    pi.removeParameter(p);
    assertEquals(pi.getParameters().size(), 0, "The list is expected to be empty.");
    final Parameter p2 = createConstructibleInstance(Parameter.class);
    pi.setParameters(Collections.singletonList(p2));
    assertEquals(pi.getParameters().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(pi.getParameters(), p2);
    checkSameObject(pi, pi.addParameter(p));
    assertEquals(pi.getParameters().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(pi.getParameters(), p);
    Parameter otherParameter = createConstructibleInstance(Parameter.class);
    checkListImmutable(pi, PathItem::getParameters, otherParameter);
    final Server s = createConstructibleInstance(Server.class);
    checkSameObject(pi, pi.addServer(s));
    checkListEntry(pi.getServers(), s);
    assertEquals(pi.getServers().size(), 1, "The list is expected to contain one entry.");
    pi.removeServer(s);
    assertEquals(pi.getServers().size(), 0, "The list is expected to be empty.");
    final Server s2 = createConstructibleInstance(Server.class);
    pi.setServers(Collections.singletonList(s2));
    assertEquals(pi.getServers().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(pi.getServers(), s2);
    checkSameObject(pi, pi.addServer(s));
    assertEquals(pi.getServers().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(pi.getServers(), s);
    Server otherServer = createConstructibleInstance(Server.class);
    checkListImmutable(pi, PathItem::getServers, otherServer);
    final Operation o1 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.GET(o1));
    checkSameObject(o1, pi.getGET());
    final Operation o2 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.PUT(o2));
    checkSameObject(o2, pi.getPUT());
    final Operation o3 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.POST(o3));
    checkSameObject(o3, pi.getPOST());
    final Operation o4 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.DELETE(o4));
    checkSameObject(o4, pi.getDELETE());
    final Operation o5 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.OPTIONS(o5));
    checkSameObject(o5, pi.getOPTIONS());
    final Operation o6 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.HEAD(o6));
    checkSameObject(o6, pi.getHEAD());
    final Operation o7 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.PATCH(o7));
    checkSameObject(o7, pi.getPATCH());
    final Operation o8 = createConstructibleInstance(Operation.class);
    checkSameObject(pi, pi.TRACE(o8));
    checkSameObject(o8, pi.getTRACE());
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.GET, o1);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.PUT, o2);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.POST, o3);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.DELETE, o4);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.OPTIONS, o5);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.HEAD, o6);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.PATCH, o7);
    checkMapEntry(pi.getOperations(), PathItem.HttpMethod.TRACE, o8);
    // test with GET:
    PathItem pathItemGET = createConstructibleInstance(PathItem.class);
    Operation operationGET = createConstructibleInstance(Operation.class).description("This is some GET op");
    pathItemGET.setOperation(HttpMethod.GET, operationGET);
    checkSameObject(pathItemGET.getGET(), operationGET);
    pathItemGET.setOperation(HttpMethod.GET, null);
    assertNull(pathItemGET.getGET());
    // test with POST:
    PathItem pathItemPOST = createConstructibleInstance(PathItem.class);
    Operation operationPOST = createConstructibleInstance(Operation.class).description("This is some POST op");
    pathItemPOST.setOperation(HttpMethod.POST, operationPOST);
    checkSameObject(pathItemPOST.getPOST(), operationPOST);
    pathItemPOST.setOperation(HttpMethod.POST, null);
    assertNull(pathItemPOST.getPOST());
    // test with PUT:
    PathItem pathItemPUT = createConstructibleInstance(PathItem.class);
    Operation operationPUT = createConstructibleInstance(Operation.class).description("This is some PUT op");
    pathItemPUT.setOperation(HttpMethod.PUT, operationPUT);
    checkSameObject(pathItemPUT.getPUT(), operationPUT);
    pathItemPUT.setOperation(HttpMethod.PUT, null);
    assertNull(pathItemPUT.getPUT());
    // test with PATCH:
    PathItem pathItemPATCH = createConstructibleInstance(PathItem.class);
    Operation operationPATCH = createConstructibleInstance(Operation.class).description("This is some PATCH op");
    pathItemPATCH.setOperation(HttpMethod.PATCH, operationPATCH);
    checkSameObject(pathItemPATCH.getPATCH(), operationPATCH);
    pathItemPATCH.setOperation(HttpMethod.PATCH, null);
    assertNull(pathItemPATCH.getPATCH());
    // test with DELETE:
    PathItem pathItemDELETE = createConstructibleInstance(PathItem.class);
    Operation operationDELETE = createConstructibleInstance(Operation.class).description("This is some DELETE op");
    pathItemDELETE.setOperation(HttpMethod.DELETE, operationDELETE);
    checkSameObject(pathItemDELETE.getDELETE(), operationDELETE);
    pathItemDELETE.setOperation(HttpMethod.DELETE, null);
    assertNull(pathItemDELETE.getDELETE());
    // test with HEAD:
    PathItem pathItemHEAD = createConstructibleInstance(PathItem.class);
    Operation operationHEAD = createConstructibleInstance(Operation.class).description("This is some HEAD op");
    pathItemHEAD.setOperation(HttpMethod.HEAD, operationHEAD);
    checkSameObject(pathItemHEAD.getHEAD(), operationHEAD);
    pathItemHEAD.setOperation(HttpMethod.HEAD, null);
    assertNull(pathItemHEAD.getHEAD());
    // test with OPTIONS:
    PathItem pathItemOPTIONS = createConstructibleInstance(PathItem.class);
    Operation operationOPTIONS = createConstructibleInstance(Operation.class).description("This is some OPTIONS op");
    pathItemOPTIONS.setOperation(HttpMethod.OPTIONS, operationOPTIONS);
    checkSameObject(pathItemOPTIONS.getOPTIONS(), operationOPTIONS);
    pathItemOPTIONS.setOperation(HttpMethod.OPTIONS, null);
    assertNull(pathItemOPTIONS.getOPTIONS());
    // test with TRACE:
    PathItem pathItemTRACE = createConstructibleInstance(PathItem.class);
    Operation operationTRACE = createConstructibleInstance(Operation.class).description("This is some TRACE op");
    pathItemTRACE.setOperation(HttpMethod.TRACE, operationTRACE);
    checkSameObject(pathItemTRACE.getTRACE(), operationTRACE);
    pathItemTRACE.setOperation(HttpMethod.TRACE, null);
    assertNull(pathItemTRACE.getTRACE());
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) Server(org.eclipse.microprofile.openapi.models.servers.Server) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) Operation(org.eclipse.microprofile.openapi.models.Operation) Test(org.testng.annotations.Test)

Example 29 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project microprofile-open-api by eclipse.

the class ModelConstructionTest method operationTest.

@Test
public void operationTest() {
    final Operation o = processConstructible(Operation.class);
    final Parameter p = createConstructibleInstance(Parameter.class);
    checkSameObject(o, o.addParameter(p));
    checkListEntry(o.getParameters(), p);
    assertEquals(o.getParameters().size(), 1, "The list is expected to contain one entry.");
    o.removeParameter(p);
    assertEquals(o.getParameters().size(), 0, "The list is expected to be empty.");
    final Parameter p2 = createConstructibleInstance(Parameter.class);
    o.setParameters(Collections.singletonList(p2));
    assertEquals(o.getParameters().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getParameters(), p2);
    checkSameObject(o, o.addParameter(p));
    assertEquals(o.getParameters().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getParameters(), p);
    Parameter otherParameter = createConstructibleInstance(Parameter.class);
    checkListImmutable(o, Operation::getParameters, otherParameter);
    final SecurityRequirement sr = createConstructibleInstance(SecurityRequirement.class);
    sr.addScheme("OAuth2", Arrays.asList("read", "write"));
    checkSameObject(o, o.addSecurityRequirement(sr));
    checkListEntry(o.getSecurity(), sr);
    assertEquals(o.getSecurity().size(), 1, "The list is expected to contain one entry.");
    o.removeSecurityRequirement(sr);
    assertEquals(o.getSecurity().size(), 0, "The list is expected to be empty.");
    final SecurityRequirement sr2 = createConstructibleInstance(SecurityRequirement.class);
    sr2.addScheme("ApiKey");
    o.setSecurity(Collections.singletonList(sr2));
    assertEquals(o.getSecurity().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getSecurity(), sr2);
    checkSameObject(o, o.addSecurityRequirement(sr));
    assertEquals(o.getSecurity().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getSecurity(), sr);
    SecurityRequirement otherSecurityRequirement = createConstructibleInstance(SecurityRequirement.class);
    otherSecurityRequirement.addScheme("BasicAuth");
    checkListImmutable(o, Operation::getSecurity, otherSecurityRequirement);
    final Server s = createConstructibleInstance(Server.class);
    checkSameObject(o, o.addServer(s));
    checkListEntry(o.getServers(), s);
    assertEquals(o.getServers().size(), 1, "The list is expected to contain one entry.");
    o.removeServer(s);
    assertEquals(o.getServers().size(), 0, "The list is expected to be empty.");
    final Server s2 = createConstructibleInstance(Server.class);
    o.setServers(Collections.singletonList(s2));
    assertEquals(o.getServers().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getServers(), s2);
    checkSameObject(o, o.addServer(s));
    assertEquals(o.getServers().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getServers(), s);
    Server otherServer = createConstructibleInstance(Server.class);
    checkListImmutable(o, Operation::getServers, otherServer);
    final String tag = new String("myTag");
    checkSameObject(o, o.addTag(tag));
    checkListEntry(o.getTags(), tag);
    assertEquals(o.getTags().size(), 1, "The list is expected to contain one entry.");
    o.removeTag(tag);
    assertEquals(o.getTags().size(), 0, "The list is expected to be empty.");
    final String tag2 = new String("myTag2");
    o.setTags(Collections.singletonList(tag2));
    assertEquals(o.getTags().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getTags(), tag2);
    checkSameObject(o, o.addTag(tag));
    assertEquals(o.getTags().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getTags(), tag);
    String otherTag = new String("otherTag");
    checkListImmutable(o, Operation::getTags, otherTag);
    final String callbackKey = "myCallback";
    final Callback callbackValue = createConstructibleInstance(Callback.class);
    checkSameObject(o, o.addCallback(callbackKey, callbackValue));
    checkMapEntry(o.getCallbacks(), callbackKey, callbackValue);
    assertEquals(o.getCallbacks().size(), 1, "The map is expected to contain one entry.");
    o.removeCallback(callbackKey);
    assertEquals(o.getCallbacks().size(), 0, "The map is expected to be empty.");
    final String callbackKey2 = "myCallbackKey2";
    final Callback callbackValue2 = createConstructibleInstance(Callback.class);
    o.setCallbacks(Collections.singletonMap(callbackKey2, callbackValue2));
    checkMapEntry(o.getCallbacks(), callbackKey2, callbackValue2);
    assertEquals(o.getCallbacks().size(), 1, "The map is expected to contain one entry.");
    checkSameObject(o, o.addCallback(callbackKey, callbackValue));
    checkMapEntry(o.getCallbacks(), callbackKey, callbackValue);
    assertEquals(o.getCallbacks().size(), 2, "The map is expected to contain two entries.");
    Callback otherCallback = createConstructibleInstance(Callback.class);
    checkMapImmutable(o, Operation::getCallbacks, "otherCallback", otherCallback);
    checkNullValueInAdd(o::getCallbacks, o::addCallback, "someCallback", callbackValue);
}
Also used : Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Server(org.eclipse.microprofile.openapi.models.servers.Server) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) Operation(org.eclipse.microprofile.openapi.models.Operation) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) Info(org.eclipse.microprofile.openapi.models.info.Info) Test(org.testng.annotations.Test)

Example 30 with Server

use of org.eclipse.microprofile.openapi.models.servers.Server in project microprofile-open-api by eclipse.

the class ModelConstructionTest method openAPITest.

@Test
public void openAPITest() {
    final OpenAPI o = processConstructible(OpenAPI.class);
    final SecurityRequirement sr = createConstructibleInstance(SecurityRequirement.class);
    sr.addScheme("BasicAuth");
    checkSameObject(o, o.addSecurityRequirement(sr));
    checkListEntry(o.getSecurity(), sr);
    assertEquals(o.getSecurity().size(), 1, "The list is expected to contain one entry.");
    o.removeSecurityRequirement(sr);
    assertEquals(o.getSecurity().size(), 0, "The list is expected to be empty.");
    final SecurityRequirement sr2 = createConstructibleInstance(SecurityRequirement.class);
    sr2.addScheme("OAuth2", "read");
    o.setSecurity(Collections.singletonList(sr2));
    assertEquals(o.getSecurity().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getSecurity(), sr2);
    checkSameObject(o, o.addSecurityRequirement(sr));
    assertEquals(o.getSecurity().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getSecurity(), sr);
    SecurityRequirement otherSecurityRequirementValue = createConstructibleInstance(SecurityRequirement.class);
    otherSecurityRequirementValue.addScheme("OAuth2", "admin");
    checkListImmutable(o, OpenAPI::getSecurity, otherSecurityRequirementValue);
    final Server s = createConstructibleInstance(Server.class);
    checkSameObject(o, o.addServer(s));
    checkListEntry(o.getServers(), s);
    assertEquals(o.getServers().size(), 1, "The list is expected to contain one entry.");
    o.removeServer(s);
    assertEquals(o.getServers().size(), 0, "The list is expected to be empty.");
    final Server s2 = createConstructibleInstance(Server.class);
    o.setServers(Collections.singletonList(s2));
    assertEquals(o.getServers().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getServers(), s2);
    checkSameObject(o, o.addServer(s));
    assertEquals(o.getSecurity().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getServers(), s);
    Server otherServer = createConstructibleInstance(Server.class);
    checkListImmutable(o, OpenAPI::getServers, otherServer);
    final Tag t = createConstructibleInstance(Tag.class);
    checkSameObject(o, o.addTag(t));
    checkListEntry(o.getTags(), t);
    assertEquals(o.getTags().size(), 1, "The list is expected to contain one entry.");
    o.removeTag(t);
    assertEquals(o.getTags().size(), 0, "The list is expected to be empty.");
    final Tag t2 = createConstructibleInstance(Tag.class);
    o.setTags(Collections.singletonList(t2));
    assertEquals(o.getTags().size(), 1, "The list is expected to contain one entry.");
    checkListEntry(o.getTags(), t2);
    checkSameObject(o, o.addTag(t));
    assertEquals(o.getTags().size(), 2, "The list is expected to contain two entries.");
    checkListEntry(o.getTags(), t);
    Tag otherTag = createConstructibleInstance(Tag.class);
    checkListImmutable(o, OpenAPI::getTags, otherTag);
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) Test(org.testng.annotations.Test)

Aggregations

Server (org.eclipse.microprofile.openapi.models.servers.Server)51 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)13 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)12 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)10 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)9 PathItem (org.eclipse.microprofile.openapi.models.PathItem)9 Operation (org.eclipse.microprofile.openapi.models.Operation)8 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)8 Info (org.eclipse.microprofile.openapi.models.info.Info)7 ServerImpl (io.smallrye.openapi.api.models.servers.ServerImpl)6 List (java.util.List)6 ServerVariable (org.eclipse.microprofile.openapi.models.servers.ServerVariable)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ArrayList (java.util.ArrayList)5 Components (org.eclipse.microprofile.openapi.models.Components)5 SecurityScheme (org.eclipse.microprofile.openapi.models.security.SecurityScheme)5 Test (org.junit.jupiter.api.Test)5 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)4 Map (java.util.Map)4 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)4