public OpenApiSchema GenerateSchemaFor(Type type, SchemaRepository schemaRepository)
        {
            if (_options.CustomTypeMappings.ContainsKey(type))
            {
                return(_options.CustomTypeMappings[type]());
            }

            if (KnownTypeMappings.ContainsKey(type))
            {
                return(KnownTypeMappings[type]());
            }

            if (type.IsNullable() || type.IsFSharpOption()) // unwrap nullables
            {
                type = type.GenericTypeArguments[0];
            }

            var jsonContract = _jsonContractResolver.ResolveContract(type);

            if (type.IsEnum || // enum
                (jsonContract is JsonObjectContract) || // regular object
                (jsonContract is JsonArrayContract && ((JsonArrayContract)jsonContract).CollectionItemType == jsonContract.UnderlyingType) || // self-referencing array
                (jsonContract is JsonDictionaryContract && ((JsonDictionaryContract)jsonContract).DictionaryValueType == jsonContract.UnderlyingType))    // self-referencing dictionary
            {
                return(GenerateReferenceSchemaFor(type, schemaRepository, jsonContract));
            }

            return(GenerateDefinitionSchemaFor(type, schemaRepository, jsonContract));
        }
Example #2
0
        protected override OpenApiSchema GenerateSchemaFor(ModelMetadata modelMetadata, SchemaRepository schemaRepository, JsonContract jsonContract)
        {
            var modelType = modelMetadata.ModelType;

            if (SchemaGeneratorOptions.CustomTypeMappings.ContainsKey(modelType))
            {
                return(SchemaGeneratorOptions.CustomTypeMappings[modelType]());
            }

            if (KnownTypeMappings.ContainsKey(modelType))
            {
                return(KnownTypeMappings[modelType]());
            }

            return(new OpenApiSchema {
                Type = "string", Format = "binary"
            });
        }
Example #3
0
        protected override bool CanGenerateSchemaFor(ModelMetadata modelMetadata, JsonContract jsonContract)
        {
            var modelType = modelMetadata.ModelType;

            return(SchemaGeneratorOptions.CustomTypeMappings.ContainsKey(modelType) ||
                   KnownTypeMappings.ContainsKey(modelType) ||
                   typeof(IFormFile).IsAssignableFrom(modelType) ||
                   typeof(FileResult).IsAssignableFrom(modelType));
        }
Example #4
0
 protected override OpenApiSchema GenerateSchemaFor(Type type, SchemaRepository schemaRepository)
 {
     return(Options.CustomTypeMappings.ContainsKey(type)
         ? Options.CustomTypeMappings[type]()
         : KnownTypeMappings[type]());
 }
Example #5
0
 protected override bool CanGenerateSchemaFor(Type type)
 {
     return(Options.CustomTypeMappings.ContainsKey(type) || KnownTypeMappings.ContainsKey(type));
 }