@@ -168,7 +168,8 @@ internal static void ApplyDefaultValue(this JsonNode schema, object? defaultValu
168
168
/// </remarks>
169
169
/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
170
170
/// <param name="context">The <see cref="JsonSchemaExporterContext"/> associated with the <see paramref="schema"/>.</param>
171
- internal static void ApplyPrimitiveTypesAndFormats ( this JsonNode schema , JsonSchemaExporterContext context )
171
+ /// <param name="createSchemaReferenceId">A delegate that generates the reference ID to create for a type.</param>
172
+ internal static void ApplyPrimitiveTypesAndFormats ( this JsonNode schema , JsonSchemaExporterContext context , Func < JsonTypeInfo , string ? > createSchemaReferenceId )
172
173
{
173
174
var type = context . TypeInfo . Type ;
174
175
var underlyingType = Nullable . GetUnderlyingType ( type ) ;
@@ -177,7 +178,7 @@ internal static void ApplyPrimitiveTypesAndFormats(this JsonNode schema, JsonSch
177
178
schema [ OpenApiSchemaKeywords . NullableKeyword ] = openApiSchema . Nullable || ( schema [ OpenApiSchemaKeywords . TypeKeyword ] is JsonArray schemaType && schemaType . GetValues < string > ( ) . Contains ( "null" ) ) ;
178
179
schema [ OpenApiSchemaKeywords . TypeKeyword ] = openApiSchema . Type ;
179
180
schema [ OpenApiSchemaKeywords . FormatKeyword ] = openApiSchema . Format ;
180
- schema [ OpenApiConstants . SchemaId ] = context . TypeInfo . GetSchemaReferenceId ( ) ;
181
+ schema [ OpenApiConstants . SchemaId ] = createSchemaReferenceId ( context . TypeInfo ) ;
181
182
schema [ OpenApiSchemaKeywords . NullableKeyword ] = underlyingType != null ;
182
183
// Clear out patterns that the underlying JSON schema generator uses to represent
183
184
// validations for DateTime, DateTimeOffset, and integers.
@@ -323,7 +324,8 @@ internal static void ApplyParameterInfo(this JsonNode schema, ApiParameterDescri
323
324
/// </summary>
324
325
/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
325
326
/// <param name="context">The <see cref="JsonSchemaExporterContext"/> associated with the current type.</param>
326
- internal static void ApplyPolymorphismOptions ( this JsonNode schema , JsonSchemaExporterContext context )
327
+ /// <param name="createSchemaReferenceId">A delegate that generates the reference ID to create for a type.</param>
328
+ internal static void ApplyPolymorphismOptions ( this JsonNode schema , JsonSchemaExporterContext context , Func < JsonTypeInfo , string ? > createSchemaReferenceId )
327
329
{
328
330
// The `context.Path.Length == 0` check is used to ensure that we only apply the polymorphism options
329
331
// to the top-level schema and not to any nested schemas that are generated.
@@ -340,7 +342,7 @@ internal static void ApplyPolymorphismOptions(this JsonNode schema, JsonSchemaEx
340
342
// that we hardcode here. We could use `OpenApiReference` to construct the reference and
341
343
// serialize it but we use a hardcoded string here to avoid allocating a new object and
342
344
// working around Microsoft.OpenApi's serialization libraries.
343
- mappings [ $ "{ discriminator } "] = $ "#/components/schemas/{ context . TypeInfo . GetSchemaReferenceId ( ) } { jsonDerivedType . GetSchemaReferenceId ( ) } ";
345
+ mappings [ $ "{ discriminator } "] = $ "#/components/schemas/{ createSchemaReferenceId ( context . TypeInfo ) } { createSchemaReferenceId ( jsonDerivedType ) } ";
344
346
}
345
347
}
346
348
schema [ OpenApiSchemaKeywords . DiscriminatorKeyword ] = polymorphismOptions . TypeDiscriminatorPropertyName ;
@@ -353,9 +355,10 @@ internal static void ApplyPolymorphismOptions(this JsonNode schema, JsonSchemaEx
353
355
/// </summary>
354
356
/// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
355
357
/// <param name="context">The <see cref="JsonSchemaExporterContext"/> associated with the current type.</param>
356
- internal static void ApplySchemaReferenceId ( this JsonNode schema , JsonSchemaExporterContext context )
358
+ /// <param name="createSchemaReferenceId">A delegate that generates the reference ID to create for a type.</param>
359
+ internal static void ApplySchemaReferenceId ( this JsonNode schema , JsonSchemaExporterContext context , Func < JsonTypeInfo , string ? > createSchemaReferenceId )
357
360
{
358
- if ( context . TypeInfo . GetSchemaReferenceId ( ) is { } schemaReferenceId )
361
+ if ( createSchemaReferenceId ( context . TypeInfo ) is { } schemaReferenceId )
359
362
{
360
363
schema [ OpenApiConstants . SchemaId ] = schemaReferenceId ;
361
364
}
0 commit comments