Exemplo n.º 1
0
        /// <summary>
        /// Generate the Channels section of the AsyncApi schema from the
        /// <see cref="ChannelAttribute"/> on classes.
        /// </summary>
        private Channels GenerateChannelsFromClasses(IEnumerable <TypeInfo> asyncApiTypes, ISchemaRepository schemaRepository)
        {
            var channels = new Channels();

            var classesWithChannelAttribute = asyncApiTypes
                                              .Select(type => new
            {
                Channel = type.GetCustomAttribute <ChannelAttribute>(),
                Type    = type,
            })
                                              .Where(cc => cc.Channel != null);

            foreach (var cc in classesWithChannelAttribute)
            {
                var channelItem = new ChannelItem
                {
                    Description = cc.Channel.Description,
                    Parameters  = this.GetChannelParametersFromAttributes(cc.Type, schemaRepository),
                    Publish     = GenerateOperationFromClass(cc.Type, schemaRepository, OperationType.Publish),
                    Subscribe   = GenerateOperationFromClass(cc.Type, schemaRepository, OperationType.Subscribe),
                };

                channels.AddOrAppend(cc.Channel.Name, channelItem);

                var context = new ChannelItemFilterContext(cc.Type, schemaRepository, cc.Channel);
                foreach (var filter in _options.ChannelItemFilters)
                {
                    filter.Apply(channelItem, context);
                }
            }

            return(channels);
        }