use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerParserTest method testPetstore.
@Test
public void testPetstore() throws Exception {
SwaggerParser parser = new SwaggerParser();
SwaggerDeserializationResult result = parser.readWithInfo("src/test/resources/petstore.json", null, true);
assertNotNull(result);
assertTrue(result.getMessages().isEmpty());
Swagger swagger = result.getSwagger();
Map<String, Model> definitions = swagger.getDefinitions();
Set<String> expectedDefinitions = new HashSet<String>();
expectedDefinitions.add("User");
expectedDefinitions.add("Category");
expectedDefinitions.add("Pet");
expectedDefinitions.add("Tag");
expectedDefinitions.add("Order");
expectedDefinitions.add("PetArray");
assertEquals(definitions.keySet(), expectedDefinitions);
Model petModel = definitions.get("Pet");
Set<String> expectedPetProps = new HashSet<String>();
expectedPetProps.add("id");
expectedPetProps.add("category");
expectedPetProps.add("name");
expectedPetProps.add("photoUrls");
expectedPetProps.add("tags");
expectedPetProps.add("status");
assertEquals(petModel.getProperties().keySet(), expectedPetProps);
ArrayModel petArrayModel = (ArrayModel) definitions.get("PetArray");
assertEquals(petArrayModel.getType(), "array");
RefProperty refProp = (RefProperty) petArrayModel.getItems();
assertEquals(refProp.get$ref(), "#/definitions/Pet");
assertNull(petArrayModel.getProperties());
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class SwaggerParserTest method assertResponse.
private void assertResponse(Swagger swagger, Map<String, Response> responsesMap, String responseCode, String expectedDescription, String expectedSchemaRef) {
final Response response = responsesMap.get(responseCode);
final RefProperty schema = (RefProperty) response.getSchema();
assertEquals(response.getDescription(), expectedDescription);
assertEquals(schema.getClass(), RefProperty.class);
assertEquals(schema.get$ref(), expectedSchemaRef);
assertTrue(swagger.getDefinitions().containsKey(schema.getSimpleRef()));
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class ExternalRefProcessorTest method testNestedExternalRefs.
@Test
public void testNestedExternalRefs(@Injectable final Model mockedModel) {
final RefFormat refFormat = RefFormat.URL;
// Swagger test instance
Swagger testedSwagger = new Swagger();
// Start with customer, add address property to it
final String customerURL = "http://my.company.com/path/to/customer.json#/definitions/Customer";
final Model customerModel = new ModelImpl();
Map<String, Property> custProps = new HashMap<String, Property>();
RefProperty address = new RefProperty();
final String addressURL = "http://my.company.com/path/to/address.json#/definitions/Address";
address.set$ref(addressURL);
custProps.put("Address", address);
// Create a 'local' reference to something in #/definitions, this should be ignored a no longer result in a null pointer exception
final String loyaltyURL = "#/definitions/LoyaltyScheme";
RefProperty loyaltyProp = new RefProperty();
loyaltyProp.set$ref(loyaltyURL);
loyaltyProp.setName("LoyaltyCardNumber");
loyaltyProp.setRequired(true);
custProps.put("Loyalty", loyaltyProp);
customerModel.setProperties(custProps);
// create address model, add Contact Ref Property to it
final Model addressModel = new ModelImpl();
Map<String, Property> addressProps = new HashMap<String, Property>();
RefProperty contact = new RefProperty();
final String contactURL = "http://my.company.com/path/to/Contact.json#/definitions/Contact";
contact.set$ref(contactURL);
addressProps.put("Contact", contact);
addressModel.setProperties(addressProps);
// Create contact model, with basic type property
final Model contactModel = new ModelImpl();
Property contactProp = new StringProperty();
contactProp.setName("PhoneNumber");
contactProp.setRequired(true);
Map<String, Property> contactProps = new HashMap<String, Property>();
contactProps.put("PhoneNumber", contactProp);
contactModel.setProperties(contactProps);
new Expectations() {
{
cache.loadRef(customerURL, refFormat, Model.class);
result = customerModel;
times = 1;
cache.loadRef(addressURL, refFormat, Model.class);
result = addressModel;
times = 1;
cache.loadRef(contactURL, refFormat, Model.class);
result = contactModel;
times = 1;
}
};
String actualRef = new ExternalRefProcessor(cache, testedSwagger).processRefToExternalDefinition(customerURL, refFormat);
assertTrue(testedSwagger.getDefinitions().get("Customer") != null);
assertTrue(testedSwagger.getDefinitions().get("Contact") != null);
assertTrue(testedSwagger.getDefinitions().get("Address") != null);
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class PropertyProcessorTest method testProcessRefProperty_InternalRef.
@Test
public void testProcessRefProperty_InternalRef() throws Exception {
expectCreationOfExternalRefProcessor();
final String expectedRef = "#/definitions/foo";
final RefProperty property = new RefProperty(expectedRef);
new PropertyProcessor(cache, swagger).processProperty(property);
new FullVerifications() {
{
}
};
assertEquals(property.get$ref(), expectedRef);
}
use of io.swagger.models.properties.RefProperty in project swagger-parser by swagger-api.
the class PropertyProcessorTest 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 RefProperty refProperty = new RefProperty(ref);
MapProperty mapProperty = new MapProperty();
mapProperty.setAdditionalProperties(refProperty);
expectCallToExternalRefProcessor(ref, RefFormat.URL, "bar");
new PropertyProcessor(cache, swagger).processProperty(mapProperty);
new FullVerifications() {
{
}
};
assertEquals(((RefProperty) mapProperty.getAdditionalProperties()).get$ref(), "#/definitions/bar");
}
Aggregations