Example #1
0
        public Message GenerateMessage(Type type, MessageRepository messageRepository, MessageAttribute messageAttribute)
        {
            return(messageRepository.GetOrAdd(type, _options.SchemaIdSelector(type), () =>
            {
                var dataContract = _dataContractResolver.GetDataContractForType(type);
                var message = new Message
                {
                    Title = messageAttribute.Title,
                    Name = messageAttribute.Name
                };

                if (dataContract.DataType == DataType.Array)
                {
                    message.Summary = dataContract.ArrayItemType.GetXmlDocsSummary();
                    message.Payload = new Schema {
                        Type = "array", Items = new Reference(_options.SchemaIdSelector(dataContract.ArrayItemType), ReferenceType.Schema)
                    };
                }
                else
                {
                    message.Summary = type.GetXmlDocsSummary();
                    message.Payload = new Reference(_options.SchemaIdSelector(type), ReferenceType.Schema);
                }

                return message;
            }));
        }
        public ISchema GenerateSchema(Type type, ISchemaRepository schemaRepository)
        {
            var schemaId = _options.SchemaIdSelector(type);

            var reference = schemaRepository.GetOrAdd(type, schemaId, () => TypeSchemaFactory(type, schemaRepository));

            return(reference);
        }
Example #3
0
        private ISchema GenerateSchemaForType(Type type, SchemaRepository schemaRepository)
        {
            var schemaId           = _options.SchemaIdSelector(type);
            var dataContract       = _dataContractResolver.GetDataContractForType(type);
            var shouldBeReferenced =
                // regular object
                (dataContract.DataType == DataType.Object && dataContract.Properties != null && !dataContract.UnderlyingType.IsDictionary()) ||
                // dictionary-based AND self-referencing
                (dataContract.DataType == DataType.Object && dataContract.AdditionalPropertiesType == dataContract.UnderlyingType) ||
                // array-based AND self-referencing
                (dataContract.DataType == DataType.Array && dataContract.ArrayItemType == dataContract.UnderlyingType) ||
                // enum-based AND opted-out of inline
                (dataContract.EnumValues != null && !_options.UseInlineDefinitionsForEnums);

            var schema = shouldBeReferenced ? GenerateReferencedSchema(dataContract, schemaRepository) : GenerateInlineSchema(dataContract, schemaRepository);

            return(schema);
        }