use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class ParameterProcessorTest method testProcessParameters_BodyParameter.
@Test
public void testProcessParameters_BodyParameter(@Injectable final Schema bodyParamSchema) throws Exception {
expectedModelProcessorCreation();
RequestBody bodyParameter = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(bodyParamSchema)));
expectModelProcessorInvoked(bodyParamSchema);
new RequestBodyProcessor(cache, openAPI).processRequestBody(bodyParameter);
new FullVerifications() {
{
}
};
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class SchemaProcessorTest method testProcessRefSchema_ExternalRef.
@Test
public void testProcessRefSchema_ExternalRef() throws Exception {
final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
final String newRef = "bar";
setupPropertyAndExternalRefProcessors();
new StrictExpectations() {
{
externalRefProcessor.processRefToExternalSchema(ref, RefFormat.URL);
times = 1;
result = newRef;
}
};
Schema refSchema = new Schema().$ref(ref);
new SchemaProcessor(cache, openAPI).processSchema(refSchema);
assertEquals(refSchema.get$ref(), "#/components/schemas/bar");
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class SchemaProcessorTest method testProcessComposedSchema.
@Test
public void testProcessComposedSchema() throws Exception {
setupPropertyAndExternalRefProcessors();
final String ref1 = "http://my.company.com/path/to/file.json#/foo/bar";
final String ref2 = "http://my.company.com/path/to/file.json#/this/that";
final String ref3 = "http://my.company.com/path/to/file.json#/hello/world";
SchemaProcessor modelProcessor = new SchemaProcessor(cache, openAPI);
new Expectations() {
{
externalRefProcessor.processRefToExternalSchema(ref1, RefFormat.URL);
times = 1;
result = "bar";
externalRefProcessor.processRefToExternalSchema(ref2, RefFormat.URL);
times = 1;
result = "that";
externalRefProcessor.processRefToExternalSchema(ref3, RefFormat.URL);
times = 1;
result = "world";
}
};
ComposedSchema composedModel = new ComposedSchema();
composedModel.addAllOfItem(new Schema().$ref(ref1));
composedModel.addAllOfItem(new Schema().$ref(ref2));
composedModel.addAllOfItem(new Schema().$ref(ref3));
modelProcessor.processSchema(composedModel);
new FullVerifications() {
{
externalRefProcessor.processRefToExternalSchema(ref1, RefFormat.URL);
times = 1;
externalRefProcessor.processRefToExternalSchema(ref2, RefFormat.URL);
times = 1;
externalRefProcessor.processRefToExternalSchema(ref3, RefFormat.URL);
times = 1;
}
};
// child
assertEquals(composedModel.getAllOf().get(0).get$ref(), "#/components/schemas/bar");
// parent
assertEquals(composedModel.getAllOf().get(1).get$ref(), "#/components/schemas/that");
assertEquals(composedModel.getAllOf().get(2).get$ref(), "#/components/schemas/world");
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class SchemaProcessorTest method testProcessMapProperty_AdditionalPropertiesIsRefProperty.
@Test
public void testProcessMapProperty_AdditionalPropertiesIsRefProperty() throws Exception {
expectCreationOfExternalRefProcessor();
final String ref = "http://my.company.com/path/to/file.json#/foo/bar";
final Schema refProperty = new Schema().$ref(ref);
refProperty.setAdditionalProperties(refProperty);
expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar");
new SchemaProcessor(cache, openAPI).processSchema(refProperty);
new FullVerifications() {
{
}
};
assertEquals((((Schema) refProperty.getAdditionalProperties()).get$ref()), "#/components/schemas/bar");
}
use of io.swagger.v3.oas.annotations.media.Schema in project swagger-parser by swagger-api.
the class SchemaProcessorTest method testProcessArraySchema.
@Test
public void testProcessArraySchema() throws Exception {
Schema property = new Schema();
SchemaProcessor propertyProcessor = new SchemaProcessor(cache, openAPI);
propertyProcessor.processSchema(property);
ArraySchema model = new ArraySchema();
model.setItems(property);
SchemaProcessor schemaProcessor = new SchemaProcessor(cache, openAPI);
schemaProcessor.processSchema(model);
assertEquals(property, model.getItems());
}
Aggregations