Search in sources :

Example 1 with RefResponse

use of io.swagger.models.RefResponse in project swagger-parser by swagger-api.

the class OperationProcessor method processOperation.

public void processOperation(Operation operation) {
    final List<Parameter> processedOperationParameters = parameterProcessor.processParameters(operation.getParameters());
    operation.setParameters(processedOperationParameters);
    final Map<String, Response> responses = operation.getResponses();
    if (responses != null) {
        for (String responseCode : responses.keySet()) {
            Response response = responses.get(responseCode);
            if (response != null) {
                if (response instanceof RefResponse) {
                    RefResponse refResponse = (RefResponse) response;
                    Response resolvedResponse = cache.loadRef(refResponse.get$ref(), refResponse.getRefFormat(), Response.class);
                    if (resolvedResponse != null) {
                        response = resolvedResponse;
                        responses.put(responseCode, resolvedResponse);
                    }
                }
                responseProcessor.processResponse(response);
            }
        }
    }
}
Also used : Response(io.swagger.models.Response) RefResponse(io.swagger.models.RefResponse) RefResponse(io.swagger.models.RefResponse) Parameter(io.swagger.models.parameters.Parameter)

Example 2 with RefResponse

use of io.swagger.models.RefResponse in project swagger-parser by swagger-api.

the class OperationProcessorTest method testProcessOperation.

@Test
public void testProcessOperation(@Injectable final List<Parameter> inputParameterList, @Injectable final List<Parameter> outputParameterList, @Injectable final Response incomingResponse, @Injectable final Response resolvedResponse) throws Exception {
    Operation operation = new Operation();
    operation.setParameters(inputParameterList);
    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    RefResponse refResponse = new RefResponse(ref);
    operation.response(200, refResponse);
    operation.response(400, incomingResponse);
    new Expectations() {

        {
            new ParameterProcessor(cache, swagger);
            times = 1;
            result = parameterProcessor;
            new ResponseProcessor(cache, swagger);
            times = 1;
            result = responseProcessor;
            parameterProcessor.processParameters(inputParameterList);
            times = 1;
            result = outputParameterList;
            cache.loadRef(ref, RefFormat.URL, Response.class);
            times = 1;
            result = resolvedResponse;
            responseProcessor.processResponse(incomingResponse);
            times = 1;
            responseProcessor.processResponse(resolvedResponse);
            times = 1;
        }
    };
    new OperationProcessor(cache, swagger).processOperation(operation);
    new FullVerifications() {

        {
        }
    };
    assertEquals(operation.getResponses().get("200"), resolvedResponse);
    assertEquals(operation.getParameters(), outputParameterList);
}
Also used : Expectations(mockit.Expectations) RefResponse(io.swagger.models.RefResponse) FullVerifications(mockit.FullVerifications) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Aggregations

RefResponse (io.swagger.models.RefResponse)2 Operation (io.swagger.models.Operation)1 Response (io.swagger.models.Response)1 Parameter (io.swagger.models.parameters.Parameter)1 Expectations (mockit.Expectations)1 FullVerifications (mockit.FullVerifications)1 Test (org.testng.annotations.Test)1