Skip to content

Commit ba1ecf0

Browse files
committed
Set default type earlier
1 parent 5a39450 commit ba1ecf0

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/OpenApi/src/Services/OpenApiDocumentService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ private async Task<OpenApiResponse> GetResponseAsync(
409409
var targetType = parameter.Type == typeof(string) && parameter.ModelMetadata.ModelType != parameter.Type
410410
? parameter.ModelMetadata.ModelType
411411
: parameter.Type;
412+
// If the type is null, then we're dealing with an inert
413+
// route parameter that does not define a specific parameter type in the
414+
// route handler or in the response. In this case, we default to a string schema.
415+
targetType ??= typeof(string);
412416
var openApiParameter = new OpenApiParameter
413417
{
414418
Name = parameter.Name,

src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,8 @@ internal sealed class OpenApiSchemaService(
126126
}
127127
};
128128

129-
internal async Task<OpenApiSchema> GetOrCreateSchemaAsync(Type? type, IServiceProvider scopedServiceProvider, IOpenApiSchemaTransformer[] schemaTransformers, ApiParameterDescription? parameterDescription = null, bool captureSchemaByRef = false, CancellationToken cancellationToken = default)
129+
internal async Task<OpenApiSchema> GetOrCreateSchemaAsync(Type type, IServiceProvider scopedServiceProvider, IOpenApiSchemaTransformer[] schemaTransformers, ApiParameterDescription? parameterDescription = null, bool captureSchemaByRef = false, CancellationToken cancellationToken = default)
130130
{
131-
// If the type is null, then we're dealing with an ambient
132-
// route parameter that does not define a specific parameter type in the
133-
// route handler or in the response. In this case, we default to a string schema.
134-
if (type is null)
135-
{
136-
return new OpenApiSchema { Type = "string" };
137-
}
138131
var key = parameterDescription?.ParameterDescriptor is IParameterInfoParameterDescriptor parameterInfoDescription
139132
&& parameterDescription.ModelMetadata.PropertyName is null
140133
? new OpenApiSchemaKey(type, parameterInfoDescription.ParameterInfo) : new OpenApiSchemaKey(type, null);

0 commit comments

Comments
 (0)