Пример #1
0
        public async Task <SigSpecDocument> GenerateForHubsAsync(IReadOnlyDictionary <string, Type> hubs)
        {
            var document  = new SigSpecDocument();
            var resolver  = new SigSpecSchemaResolver(document, _settings);
            var generator = new JsonSchemaGenerator(_settings);

            foreach (var h in hubs)
            {
                var type = h.Value;

                var hub = new SigSpecHub();
                hub.Name        = type.Name.EndsWith("Hub") ? type.Name.Substring(0, type.Name.Length - 3) : type.Name;
                hub.Description = await type.GetXmlSummaryAsync();

                foreach (var method in GetOperationMethods(type))
                {
                    var operation = await GenerateOperationAsync(type, method, generator, resolver, SigSpecOperationType.Sync);

                    hub.Operations[method.Name] = operation;
                }

                foreach (var method in GetChannelMethods(type))
                {
                    hub.Operations[method.Name] = await GenerateOperationAsync(type, method, generator, resolver, SigSpecOperationType.Observable);
                }

                var baseTypeGenericArguments = type.BaseType.GetGenericArguments();
                if (baseTypeGenericArguments.Length == 1)
                {
                    var callbackType = baseTypeGenericArguments[0];
                    foreach (var callbackMethod in GetOperationMethods(callbackType))
                    {
                        var callback = await GenerateOperationAsync(type, callbackMethod, generator, resolver, SigSpecOperationType.Sync);

                        hub.Callbacks[callbackMethod.Name] = callback;
                    }
                }

                document.Hubs[h.Key] = hub;
            }

            return(document);
        }
Пример #2
0
        private async Task <SigSpecOperation> GenerateOperationAsync(Type type, MethodInfo method, JsonSchemaGenerator generator, SigSpecSchemaResolver resolver)
        {
            var operation = new SigSpecOperation();

            operation.Description = await type.GetXmlSummaryAsync();

            foreach (var arg in method.GetParameters())
            {
                var parameter = await generator.GenerateWithReferenceAndNullabilityAsync <SigSpecParameter>(
                    arg.ParameterType,
                    arg.GetCustomAttributes(),
                    resolver,
                    async (p, s) =>
                {
                    p.Description = await arg.GetXmlDocumentationAsync();
                });

                operation.Parameters[arg.Name] = parameter;
            }

            return(operation);
        }
Пример #3
0
        private async Task <SigSpecOperation> GenerateOperationAsync(Type type, MethodInfo method, JsonSchemaGenerator generator, SigSpecSchemaResolver resolver, SigSpecOperationType operationType)
        {
            var operation = new SigSpecOperation
            {
                Description = await type.GetXmlSummaryAsync(),
                Type        = operationType
            };

            foreach (var arg in method.GetParameters())
            {
                var parameter = await generator.GenerateWithReferenceAndNullabilityAsync <SigSpecParameter>(
                    arg.ParameterType, arg.GetCustomAttributes(), resolver, async (p, s) =>
                {
                    p.Description = await arg.GetXmlDocumentationAsync();
                });

                operation.Parameters[arg.Name] = parameter;
            }

            var returnType =
                operationType == SigSpecOperationType.Observable
                    ? method.ReturnType.GetGenericTypeArguments().First()
                : method.ReturnType == typeof(Task)
                    ? null
                : method.ReturnType.IsGenericType && method.ReturnType.BaseType == typeof(Task)
                    ? method.ReturnType.GetGenericTypeArguments().First()
                    : method.ReturnType;

            operation.ReturnType = returnType == null ? null : await generator.GenerateWithReferenceAndNullabilityAsync <JsonSchema4>(
                returnType, null, resolver, async (p, s) =>
            {
                p.Description = await method.ReturnType.GetXmlSummaryAsync();
            });

            return(operation);
        }
Пример #4
0
        private async Task <SigSpecOperation> GenerateOperationAsync(Type type, MethodInfo method, JsonSchemaGenerator generator, SigSpecSchemaResolver resolver, SigSpecOperationType operationType)
        {
            var operation = new SigSpecOperation
            {
                Description = method.GetXmlDocsSummary(),
                Type        = operationType
            };

            foreach (var arg in method.GetParameters())
            {
                var parameter = generator.GenerateWithReferenceAndNullability <SigSpecParameter>(
                    arg.ParameterType.ToContextualType(), arg.ParameterType.ToContextualType().IsNullableType, resolver, (p, s) =>
                {
                    p.Description = arg.GetXmlDocs();
                });

                operation.Parameters[arg.Name] = parameter;
            }

            var returnType =
                operationType == SigSpecOperationType.Observable
                    ? method.ReturnType.GetGenericArguments().First()
                : method.ReturnType == typeof(Task)
                    ? null
                : method.ReturnType.IsGenericType && method.ReturnType.BaseType == typeof(Task)
                    ? method.ReturnType.GetGenericArguments().First()
                    : method.ReturnType;

            operation.ReturnType = returnType == null ? null : generator.GenerateWithReferenceAndNullability <JsonSchema>(
                returnType.ToContextualType(), returnType.ToContextualType().IsNullableType, resolver, async(p, s) =>
            {
                p.Description = method.ReturnType.GetXmlDocsSummary();
            });

            return(operation);
        }