public SwaggerProperty Create(IPropertyDetails propertyDetails, Queue <Type> typeQueue)
        {
            if (propertyDetails == null)
            {
                throw new ArgumentNullException(nameof(propertyDetails));
            }

            var swaggerType = _swaggerTypeConverter.GetSwaggerType(propertyDetails.PropertyType);

            switch (swaggerType)
            {
            case SwaggerType.Object:
                typeQueue.Enqueue(propertyDetails.PropertyType);
                return(new ReferencedSwaggerProperty
                {
                    Name = propertyDetails.Name,
                    Reference = _definitionNameProvider.GetDefinitionName(propertyDetails.PropertyType)
                });

            case SwaggerType.Array:
                var propertyType = _swaggerTypeConverter.GetTypeToDocument(propertyDetails.PropertyType);

                typeQueue?.Enqueue(propertyType);

                return(new ArraySwaggerProperty
                {
                    Name = propertyDetails.Name,
                    Reference = _definitionNameProvider.GetDefinitionName(propertyType)
                });
            }

            return(new TypedSwaggerProperty {
                Name = propertyDetails.Name, Type = swaggerType
            });
        }
Example #2
0
        public IReadOnlyCollection <SwaggerDefinition> Create(IReadOnlyCollection <IApiActionRegistration> registrations)
        {
            var typeQueue = new Queue <Type>(registrations
                                             .SelectMany(r => _responseInfoFactory.CreateResponses(r.ApiActionType)).Select(ri => ri.ResponseData)
                                             .Where(t => t != null).Select(t => _typeProvider.GetTypeToDocument(t)));

            // Add Requests to Queue


            var resultsLookup = new Dictionary <string, SwaggerDefinition>();

            while (typeQueue.Count > 0)
            {
                var type = typeQueue.Dequeue();
                var name = _definitionNameProvider.GetDefinitionName(type);

                if (!resultsLookup.ContainsKey(name))
                {
                    resultsLookup.Add(name, new SwaggerDefinition
                    {
                        Name   = name,
                        Schema = _schemaFactory.Create(type, type.GetTypeDetails().PropertyReaders, typeQueue)
                    });
                }
            }

            return(resultsLookup.Values.ToList());
        }
        public string GetDefinitionName(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            return(_typeProvider.GetTypeToDocument(type).FullName);
        }