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);
}
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);
}
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);
}
Aggregations