use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class CustomStaticTypeDeclarationEnricher method getJsonType.
private Optional<MetadataType> getJsonType(String schema) {
String schemaContent = IOUtils.toString(getSchemaContent(schema));
Optional<MetadataType> type = new JsonTypeLoader(schemaContent).load(null);
if (!type.isPresent()) {
throw new IllegalArgumentException("Could not load type from Json schema [" + schema + "]");
}
return type;
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class ImportedTypesDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!extensionType.isPresent()) {
return;
}
Type type = extensionType.get().getType();
final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
if (!importTypes.isEmpty()) {
if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
}
importTypes.forEach(imported -> {
MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
if (!(importedType instanceof ObjectType)) {
throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
}
extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
});
}
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class MetadataOperationTestCase method operationWhichReturnsDynamicListOfMessages.
@Test
public void operationWhichReturnsDynamicListOfMessages() throws Exception {
location = Location.builder().globalName("dynamicListOfMessages").addProcessorsPart().addIndexPart(0).build();
MetadataType param = getResolvedTypeFromList();
assertMessageType(((ArrayType) param).getType(), personType, TYPE_BUILDER.anyType().build());
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class MetadataOperationTestCase method attributesDynamicPersonTypeMetadata.
@Test
public void attributesDynamicPersonTypeMetadata() throws Exception {
location = Location.builder().globalName(OUTPUT_ATTRIBUTES_WITH_DYNAMIC_METADATA).addProcessorsPart().addIndexPart(0).build();
final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY);
final OperationModel typedModel = metadataDescriptor.getModel();
MetadataType type = typedModel.getOutputAttributes().getType();
assertThat(type, is(instanceOf(ObjectType.class)));
ObjectType dictionary = (ObjectType) type;
assertThat(dictionary.getOpenRestriction().get(), is(instanceOf(StringType.class)));
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class MetadataOperationTestCase method dynamicOutputAndContentWithCache.
@Test
public void dynamicOutputAndContentWithCache() throws Exception {
location = Location.builder().globalName(CONTENT_AND_OUTPUT_CACHE_RESOLVER).addProcessorsPart().addIndexPart(0).build();
final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY);
final OperationModel typedModel = metadataDescriptor.getModel();
MetadataType outputType = typedModel.getOutput().getType();
MetadataType contentType = getParameter(typedModel, "content").getType();
assertThat(contentType, is(equalTo(outputType)));
}
Aggregations