use of com.devonfw.cobigen.openapiplugin.model.PropertyDef in project cobigen by devonfw.
the class OpenAPIInputReader method extractResponses.
/**
* Returns a {@link ResponseDef} from a operation '200' response definition depending on the tags
*
* @param overlay overlay of the operator
* @param responses list of OpenApu responses definition
* @param tags list of oasp4j relative tags
* @return List of {@link ResponseDef}'s
*/
private List<ResponseDef> extractResponses(Map<String, ? extends Response> responses, Collection<String> tags) {
ResponseDef response;
List<String> mediaTypes = new LinkedList<>();
List<ResponseDef> resps = new LinkedList<>();
String schemaType;
for (String resp : responses.keySet()) {
response = new ResponseDef();
response.setCode(resp);
Map<String, MediaType> contentMediaTypes = responses.get(resp).getContentMediaTypes();
response.setDescription(responses.get(resp).getDescription());
if (contentMediaTypes != null) {
if (contentMediaTypes.isEmpty()) {
response.setIsVoid(true);
}
for (String media : contentMediaTypes.keySet()) {
mediaTypes.add(media);
Schema schema = contentMediaTypes.get(media).getSchema();
if (schema != null) {
schemaType = schema.getType();
if (Constants.OBJECT.equals(schemaType)) {
response.setType(schema.getName());
response.setIsEntity(true);
EntityDef eDef = new EntityDef();
List<PropertyDef> propDefs = new LinkedList<>();
for (Schema propertySchema : schema.getProperties().values()) {
PropertyDef prop = new PropertyDef();
prop.setDescription(propertySchema.getDescription());
prop.setFormat(propertySchema.getFormat());
prop.setName(propertySchema.getName());
prop.setType(propertySchema.getType());
propDefs.add(prop);
}
eDef.setName(schema.getName());
eDef.setProperties(propDefs);
response.setEntityRef(eDef);
} else if (Constants.ARRAY.equals(schemaType)) {
if (schema.getItemsSchema() != null) {
response.setType(schema.getItemsSchema().getName());
response.setIsEntity(true);
} else {
response.setType(schema.getItemsSchema().getType());
}
if (tags.contains(Constants.PAGINATED)) {
response.setIsPaginated(true);
} else {
response.setIsArray(true);
}
} else if (schemaType != null) {
response.setType(schemaType);
} else {
response.setIsVoid(true);
}
}
}
} else {
response.setIsVoid(true);
}
response.setMediaTypes(mediaTypes);
resps.add(response);
}
return resps;
}
use of com.devonfw.cobigen.openapiplugin.model.PropertyDef in project cobigen by devonfw.
the class OpenAPIInputReaderTest method testNullableEnum.
/**
* Tests if the input reader can handle nullable enums. See: https://github.com/devonfw/cobigen/issues/1244
*
* @throws Exception
*/
@Test
public void testNullableEnum() throws Exception {
List<Object> inputObjects = getInputs("nullableEnum.yaml");
for (Object o : inputObjects) {
if (isEntityDef(o)) {
EntityDef entity = (EntityDef) o;
List<PropertyDef> properties = entity.getProperties();
for (PropertyDef p : properties) {
List<String> enums = p.getEnumElements();
assertThat(enums.get(0)).isEqualTo("enum1");
assertThat(enums.get(1)).isEqualTo("null");
}
}
}
}
use of com.devonfw.cobigen.openapiplugin.model.PropertyDef in project cobigen by devonfw.
the class OpenAPIInputReaderTest method testRetrieveConstraintsOfPropertiesOfEntity.
@Test
public void testRetrieveConstraintsOfPropertiesOfEntity() throws Exception {
List<Object> inputObjects = getInputs("two-components.yaml");
List<PropertyDef> properties = new LinkedList<>();
for (Object o : inputObjects) {
if (isEntityDef(o)) {
properties.addAll(((EntityDef) o).getProperties());
}
}
List<Map<String, Object>> constraints = new LinkedList<>();
for (PropertyDef property : properties) {
constraints.add(property.getConstraints());
}
assertThat(constraints).hasSize(2);
assertThat(constraints).extracting("maximum").containsExactly(null, 100);
assertThat(constraints).extracting("minimum").containsExactly(null, 0);
assertThat(constraints).extracting("maxLength").containsExactly(100, null);
assertThat(constraints).extracting("minLength").containsExactly(5, null);
assertThat(constraints).extracting("unique").containsExactly(true, false);
}
Aggregations