@@ -176,19 +176,20 @@ private static OpenApiParameter AppendParameter(OpenApiDocument document, OpenAp
176176 In = parameterLocation ,
177177 Required = actionParameter . IsRequired ,
178178 Name = actionParameter . ApiParameterName ,
179- Schema = CreateSchema ( document , parameterType , isEnumerable , actionParameter . DefaultValue , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger )
179+ Schema = CreateSchema ( document , parameterType , isEnumerable , actionParameter . DefaultValue , rootNamespace , supportOpenApiNullableReferenceTypes , treatAsFile : false , schemaRegistry , logger )
180180 } ;
181181 operation . Parameters . Add ( apiParameter ) ;
182182 return apiParameter ;
183183 }
184184
185185 private static void AppendBody ( OpenApiDocument document , OpenApiOperation operation , ActionDefinition action , string rootNamespace , bool supportOpenApiNullableReferenceTypes , ISchemaRegistry schemaRegistry , ILogger logger )
186186 {
187- if ( action . RequestBody == null )
187+ ActionRequestBody requestBody = action . RequestBody ;
188+ if ( requestBody == null )
188189 return ;
189190
190191 OpenApiRequestBody body = new OpenApiRequestBody { Required = true } ;
191- AppendContent ( document , body . Content , action . RequestBody . MediaType , action . RequestBody . Contract , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) ;
192+ AppendContent ( document , body . Content , requestBody . MediaType , requestBody . Contract , rootNamespace , supportOpenApiNullableReferenceTypes , requestBody . TreatAsFile != null , schemaRegistry , logger ) ;
192193 operation . RequestBody = body ;
193194 }
194195
@@ -199,7 +200,7 @@ private static void AppendResponses(OpenApiDocument document, OpenApiOperation o
199200 OpenApiResponse apiResponse = new OpenApiResponse ( ) ;
200201
201202 if ( actionResponse . ResultType != null )
202- AppendContent ( document , apiResponse . Content , actionResponse . MediaType , actionResponse . ResultType , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) ;
203+ AppendContent ( document , apiResponse . Content , actionResponse . MediaType , actionResponse . ResultType , rootNamespace , supportOpenApiNullableReferenceTypes , treatAsFile : false , schemaRegistry , logger ) ;
203204
204205 StringBuilder sb = new StringBuilder ( actionResponse . Description ) ;
205206 if ( actionResponse . Errors . Any ( ) )
@@ -230,9 +231,10 @@ private static void AppendResponses(OpenApiDocument document, OpenApiOperation o
230231 }
231232 }
232233
233- private static void AppendContent ( OpenApiDocument document , IDictionary < string , OpenApiMediaType > target , string mediaType , TypeReference typeReference , string rootNamespace , bool supportOpenApiNullableReferenceTypes , ISchemaRegistry schemaRegistry , ILogger logger )
234+ private static void AppendContent ( OpenApiDocument document , IDictionary < string , OpenApiMediaType > target , string mediaType , TypeReference typeReference , string rootNamespace , bool supportOpenApiNullableReferenceTypes , bool treatAsFile , ISchemaRegistry schemaRegistry , ILogger logger )
234235 {
235- OpenApiMediaType content = new OpenApiMediaType { Schema = CreateSchema ( document , typeReference , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) } ;
236+ OpenApiSchema schema = CreateSchema ( document , typeReference , rootNamespace , supportOpenApiNullableReferenceTypes , treatAsFile , schemaRegistry , logger ) ;
237+ OpenApiMediaType content = new OpenApiMediaType { Schema = schema } ;
236238 target . Add ( mediaType , content ) ;
237239 }
238240
@@ -300,10 +302,10 @@ private static void AppendSecuritySchemes(OpenApiDocument document, IEnumerable<
300302 _ => throw new ArgumentOutOfRangeException ( nameof ( value ) , value , null )
301303 } ;
302304
303- private static OpenApiSchema CreateSchema ( OpenApiDocument document , TypeReference typeReference , string rootNamespace , bool supportOpenApiNullableReferenceTypes , ISchemaRegistry schemaRegistry , ILogger logger ) => CreateSchema ( document , typeReference , typeReference . IsEnumerable , defaultValue : null , rootNamespace : rootNamespace , supportOpenApiNullableReferenceTypes : supportOpenApiNullableReferenceTypes , schemaRegistry : schemaRegistry , logger : logger ) ;
304- private static OpenApiSchema CreateSchema ( OpenApiDocument document , TypeReference typeReference , bool isEnumerable , ValueReference defaultValue , string rootNamespace , bool supportOpenApiNullableReferenceTypes , ISchemaRegistry schemaRegistry , ILogger logger )
305+ private static OpenApiSchema CreateSchema ( OpenApiDocument document , TypeReference typeReference , string rootNamespace , bool supportOpenApiNullableReferenceTypes , bool treatAsFile , ISchemaRegistry schemaRegistry , ILogger logger ) => CreateSchema ( document , typeReference , typeReference . IsEnumerable , defaultValue : null , rootNamespace , supportOpenApiNullableReferenceTypes , treatAsFile , schemaRegistry , logger ) ;
306+ private static OpenApiSchema CreateSchema ( OpenApiDocument document , TypeReference typeReference , bool isEnumerable , ValueReference defaultValue , string rootNamespace , bool supportOpenApiNullableReferenceTypes , bool treatAsFile , ISchemaRegistry schemaRegistry , ILogger logger )
305307 {
306- OpenApiSchema schema = CreateSchemaCore ( document , typeReference , defaultValue , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) ;
308+ OpenApiSchema schema = CreateSchemaCore ( document , typeReference , defaultValue , rootNamespace , supportOpenApiNullableReferenceTypes , treatAsFile , schemaRegistry , logger ) ;
307309
308310 if ( isEnumerable )
309311 {
@@ -317,20 +319,27 @@ private static OpenApiSchema CreateSchema(OpenApiDocument document, TypeReferenc
317319 return schema ;
318320 }
319321
320- private static OpenApiSchema CreateSchemaCore ( OpenApiDocument document , TypeReference typeReference , ValueReference defaultValue , string rootNamespace , bool supportOpenApiNullableReferenceTypes , ISchemaRegistry schemaRegistry , ILogger logger )
322+ private static OpenApiSchema CreateSchemaCore ( OpenApiDocument document , TypeReference typeReference , ValueReference defaultValue , string rootNamespace , bool supportOpenApiNullableReferenceTypes , bool treatAsFile , ISchemaRegistry schemaRegistry , ILogger logger )
321323 {
322- switch ( typeReference )
324+ if ( treatAsFile )
323325 {
324- case PrimitiveTypeReference primitiveContractPropertyType : return CreatePrimitiveTypeSchema ( primitiveContractPropertyType , defaultValue , schemaRegistry , logger ) ;
325- case SchemaTypeReference contractPropertyTypeReference : return CreateReferenceSchema ( document , contractPropertyTypeReference , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) ;
326- default : throw new ArgumentOutOfRangeException ( nameof ( typeReference ) , typeReference , $ "Unexpected property type: { typeReference } ") ;
326+ return CreatePrimitiveTypeSchema ( typeReference , PrimitiveType . Stream , defaultValue , schemaRegistry , logger ) ;
327327 }
328+
329+ OpenApiSchema schema = typeReference switch
330+ {
331+ PrimitiveTypeReference primitiveContractPropertyType => CreatePrimitiveTypeSchema ( primitiveContractPropertyType , defaultValue , schemaRegistry , logger ) ,
332+ SchemaTypeReference contractPropertyTypeReference => CreateReferenceSchema ( document , contractPropertyTypeReference , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) ,
333+ _ => throw new ArgumentOutOfRangeException ( nameof ( typeReference ) , typeReference , $ "Unexpected property type: { typeReference } ")
334+ } ;
335+ return schema ;
328336 }
329337
330- private static OpenApiSchema CreatePrimitiveTypeSchema ( PrimitiveTypeReference typeReference , ValueReference defaultValue , ISchemaRegistry schemaRegistry , ILogger logger )
338+ private static OpenApiSchema CreatePrimitiveTypeSchema ( PrimitiveTypeReference typeReference , ValueReference defaultValue , ISchemaRegistry schemaRegistry , ILogger logger ) => CreatePrimitiveTypeSchema ( typeReference , typeReference . Type , defaultValue , schemaRegistry , logger ) ;
339+ private static OpenApiSchema CreatePrimitiveTypeSchema ( TypeReference typeReference , PrimitiveType type , ValueReference defaultValue , ISchemaRegistry schemaRegistry , ILogger logger )
331340 {
332- if ( ! PrimitiveTypeMap . TryGetOpenApiFactory ( typeReference . Type , out Func < OpenApiSchema > schemaFactory ) )
333- throw new InvalidOperationException ( $ "Unexpected primitive type: { typeReference . Type } ") ;
341+ if ( ! PrimitiveTypeMap . TryGetOpenApiFactory ( type , out Func < OpenApiSchema > schemaFactory ) )
342+ throw new InvalidOperationException ( $ "Unexpected primitive type: { type } ") ;
334343
335344 OpenApiSchema schema = schemaFactory ( ) ;
336345 schema . Nullable = typeReference . IsNullable ;
@@ -440,7 +449,7 @@ private static void AppendObjectSchema(OpenApiDocument document, string schemaNa
440449 continue ;
441450
442451 string propertyName = StringExtensions . ToCamelCase ( property . Name ) ;
443- OpenApiSchema propertySchema = CreateSchema ( document , property . Type , rootNamespace , supportOpenApiNullableReferenceTypes , schemaRegistry , logger ) ;
452+ OpenApiSchema propertySchema = CreateSchema ( document , property . Type , rootNamespace , supportOpenApiNullableReferenceTypes , treatAsFile : false , schemaRegistry , logger ) ;
444453 schema . Properties . Add ( propertyName , propertySchema ) ;
445454
446455 if ( property . SerializationBehavior == SerializationBehavior . Always && ! property . IsOptional )
0 commit comments