Java Code Examples for org.eclipse.microprofile.openapi.models.Operation#setTags()

The following examples show how to use org.eclipse.microprofile.openapi.models.Operation#setTags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OperationReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a {@link Operation} OpenAPI node.
 * 
 * @param node json object
 * @return Operation model
 */
public static Operation readOperation(final JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    IoLogging.log.singleJsonObject("Operation");
    Operation model = new OperationImpl();
    model.setTags(JsonUtil.readStringArray(node.get(OperationConstant.PROP_TAGS)).orElse(null));
    model.setSummary(JsonUtil.stringProperty(node, OperationConstant.PROP_SUMMARY));
    model.setDescription(JsonUtil.stringProperty(node, OperationConstant.PROP_DESCRIPTION));
    model.setExternalDocs(ExternalDocsReader.readExternalDocs(node.get(ExternalDocsConstant.PROP_EXTERNAL_DOCS)));
    model.setOperationId(JsonUtil.stringProperty(node, OperationConstant.PROP_OPERATION_ID));
    model.setParameters(ParameterReader.readParameterList(node.get(OperationConstant.PROP_PARAMETERS)).orElse(null));
    model.setRequestBody(RequestBodyReader.readRequestBody(node.get(OperationConstant.PROP_REQUEST_BODY)));
    model.setResponses(ResponseReader.readResponses(node.get(OperationConstant.PROP_RESPONSES)));
    model.setCallbacks(CallbackReader.readCallbacks(node.get(OperationConstant.PROP_CALLBACKS)));
    model.setDeprecated(JsonUtil.booleanProperty(node, OperationConstant.PROP_DEPRECATED).orElse(null));
    model.setSecurity(
            SecurityRequirementReader.readSecurityRequirements(node.get(OperationConstant.PROP_SECURITY)).orElse(null));
    model.setServers(ServerReader.readServers(node.get(OperationConstant.PROP_SERVERS)).orElse(null));
    ExtensionReader.readExtensions(node, model);
    return model;
}
 
Example 2
Source File: AirlinesOASFilter.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@Override
public Operation filterOperation(Operation operation) {
    if("Get a booking with ID".equals(operation.getSummary())){
        operation.setSummary("filterOperation - Get a booking with ID");  
    } 
    else if("Update a booking with ID".equals(operation.getSummary())){
        operation.setSummary("filterOperation - Update a booking with ID");  
    }
    else if("Retrieve all available flights".equals(operation.getSummary())){
        operation.setOperationId("filterOperationGetFlights");
    }
    
    List<String> tags = operation.getTags();
    if (tags != null) {
        if (tags.contains("Bookings")) {
            tags = new ArrayList<>(tags);
            tags.set(tags.indexOf("Bookings"), "parent - Bookings");
            operation.setTags(tags);
        }
    }
    return operation;
}
 
Example 3
Source File: AnnotationScanner.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Process tags.
 * Tag and Tags annotations combines with the resource tags we've already found (passed in)
 * 
 * @param method the REST method
 * @param openApi the OpenApi model
 * @param resourceTags tags passed in
 * @param operation the current operation
 */
default void processOperationTags(final MethodInfo method, OpenAPI openApi, Set<String> resourceTags,
        final Operation operation) {
    // 
    Set<String> tags = processTags(method, openApi, true);
    if (tags == null) {
        if (!resourceTags.isEmpty()) {
            operation.setTags(new ArrayList<>(resourceTags));
        }
    } else if (!tags.isEmpty()) {
        operation.setTags(new ArrayList<>(tags));
    }
}
 
Example 4
Source File: ModelConstructionTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@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);
}