Search in sources :

Example 1 with ParameterProcessor

use of io.swagger.v3.core.util.ParameterProcessor in project swagger-parser by swagger-api.

the class ParameterProcessorTest method testProcessParameters_RefToHeader.

@Test
public void testProcessParameters_RefToHeader(@Injectable final HeaderParameter resolvedHeaderParam) throws Exception {
    expectedModelProcessorCreation();
    final String ref = "#/components/parameters/foo";
    Parameter refParameter = new Parameter().$ref(ref);
    expectLoadingRefFromCache(ref, RefFormat.INTERNAL, resolvedHeaderParam);
    new Expectations() {

        {
            resolvedHeaderParam.getSchema();
            result = null;
            resolvedHeaderParam.getContent();
            result = null;
        }
    };
    final List<Parameter> processedParameters = new ParameterProcessor(cache, openAPI).processParameters(Arrays.asList(refParameter));
    new FullVerifications() {

        {
        }
    };
    assertEquals(processedParameters.size(), 1);
    assertEquals(processedParameters.get(0), resolvedHeaderParam);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) CookieParameter(io.swagger.v3.oas.models.parameters.CookieParameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HeaderParameter(io.swagger.v3.oas.models.parameters.HeaderParameter) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 2 with ParameterProcessor

use of io.swagger.v3.core.util.ParameterProcessor in project swagger-parser by swagger-api.

the class ComponentsProcessorTest method testDefinitionsProcessor_RefModelInDefinitionsMap.

@Test
public void testDefinitionsProcessor_RefModelInDefinitionsMap(@Injectable final Schema resolvedModel) throws Exception {
    final OpenAPI openAPI = new OpenAPI();
    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    final Schema refModel = new Schema().$ref(ref);
    openAPI.components(new Components().addSchemas("foo", refModel));
    final MockUp<ResolverCache> mockup = new MockUp<ResolverCache>() {

        @Mock
        String getRenamedRef(String ref) {
            openAPI.getComponents().getSchemas().put("bar", resolvedModel);
            return "bar";
        }
    };
    final ResolverCache mockResolverCache = mockup.getMockInstance();
    new StrictExpectations() {

        {
            new SchemaProcessor(mockResolverCache, openAPI);
            times = 1;
            result = schemaProcessor;
            new ResponseProcessor(mockResolverCache, openAPI);
            times = 1;
            result = responseProcessor;
            new RequestBodyProcessor(mockResolverCache, openAPI);
            times = 1;
            result = requestBodyProcessor;
            new ParameterProcessor(mockResolverCache, openAPI);
            times = 1;
            result = parameterProcessor;
            new HeaderProcessor(mockResolverCache, openAPI);
            times = 1;
            result = headerProcessor;
            new ExampleProcessor(mockResolverCache, openAPI);
            times = 1;
            result = exampleProcessor;
            new LinkProcessor(mockResolverCache, openAPI);
            times = 1;
            result = linkProcessor;
            new CallbackProcessor(mockResolverCache, openAPI);
            times = 1;
            result = callbackProcessor;
            new SecuritySchemeProcessor(mockResolverCache, openAPI);
            times = 1;
            result = securitySchemeProcessor;
            schemaProcessor.processSchema(refModel);
            times = 1;
            resolvedModel.getProperties();
            times = 1;
        }
    };
    new ComponentsProcessor(openAPI, mockResolverCache).processComponents();
    new FullVerifications() {

        {
        }
    };
    final Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
    assertEquals(definitions.size(), 1);
    final Schema foo = definitions.get("foo");
    assertEquals(foo, resolvedModel);
}
Also used : Schema(io.swagger.v3.oas.models.media.Schema) Components(io.swagger.v3.oas.models.Components) ResolverCache(io.swagger.v3.parser.ResolverCache) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 3 with ParameterProcessor

use of io.swagger.v3.core.util.ParameterProcessor 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 ApiResponse incomingResponse, @Injectable final ApiResponse resolvedResponse) throws Exception {
    Operation operation = new Operation();
    operation.setParameters(inputParameterList);
    final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
    ApiResponse refResponse = new ApiResponse().$ref(ref);
    operation.responses(new ApiResponses().addApiResponse("200", refResponse));
    operation.getResponses().addApiResponse("400", incomingResponse);
    new Expectations() {

        {
            new ParameterProcessor(cache, openAPI);
            times = 1;
            result = parameterProcessor;
            new ResponseProcessor(cache, openAPI);
            times = 1;
            result = responseProcessor;
            parameterProcessor.processParameters(inputParameterList);
            times = 1;
            result = outputParameterList;
            responseProcessor.processResponse(refResponse);
            times = 1;
            RefUtils.computeRefFormat(ref);
            times = 1;
            cache.loadRef(ref, RefFormat.URL, ApiResponse.class);
            times = 1;
            result = resolvedResponse;
            RefUtils.computeRefFormat(ref);
            times = 1;
            incomingResponse.get$ref();
            times = 1;
            responseProcessor.processResponse(incomingResponse);
            times = 1;
            responseProcessor.processResponse(resolvedResponse);
            times = 1;
        }
    };
    new OperationProcessor(cache, openAPI).processOperation(operation);
    new FullVerifications() {

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

Aggregations

Test (org.testng.annotations.Test)3 Components (io.swagger.v3.oas.models.Components)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 Operation (io.swagger.v3.oas.models.Operation)1 Schema (io.swagger.v3.oas.models.media.Schema)1 CookieParameter (io.swagger.v3.oas.models.parameters.CookieParameter)1 HeaderParameter (io.swagger.v3.oas.models.parameters.HeaderParameter)1 Parameter (io.swagger.v3.oas.models.parameters.Parameter)1 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)1 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)1 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)1 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)1 ResolverCache (io.swagger.v3.parser.ResolverCache)1 Expectations (mockit.Expectations)1 FullVerifications (mockit.FullVerifications)1