@@ -168,7 +168,8 @@ internal static void ApplyDefaultValue(this JsonNode schema, object? defaultValu
168168 /// </remarks>
169169 /// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
170170 /// <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 )
172173 {
173174 var type = context . TypeInfo . Type ;
174175 var underlyingType = Nullable . GetUnderlyingType ( type ) ;
@@ -177,7 +178,7 @@ internal static void ApplyPrimitiveTypesAndFormats(this JsonNode schema, JsonSch
177178 schema [ OpenApiSchemaKeywords . NullableKeyword ] = openApiSchema . Nullable || ( schema [ OpenApiSchemaKeywords . TypeKeyword ] is JsonArray schemaType && schemaType . GetValues < string > ( ) . Contains ( "null" ) ) ;
178179 schema [ OpenApiSchemaKeywords . TypeKeyword ] = openApiSchema . Type ;
179180 schema [ OpenApiSchemaKeywords . FormatKeyword ] = openApiSchema . Format ;
180- schema [ OpenApiConstants . SchemaId ] = context . TypeInfo . GetSchemaReferenceId ( ) ;
181+ schema [ OpenApiConstants . SchemaId ] = createSchemaReferenceId ( context . TypeInfo ) ;
181182 schema [ OpenApiSchemaKeywords . NullableKeyword ] = underlyingType != null ;
182183 // Clear out patterns that the underlying JSON schema generator uses to represent
183184 // validations for DateTime, DateTimeOffset, and integers.
@@ -323,7 +324,8 @@ internal static void ApplyParameterInfo(this JsonNode schema, ApiParameterDescri
323324 /// </summary>
324325 /// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
325326 /// <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 )
327329 {
328330 // The `context.Path.Length == 0` check is used to ensure that we only apply the polymorphism options
329331 // 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
340342 // that we hardcode here. We could use `OpenApiReference` to construct the reference and
341343 // serialize it but we use a hardcoded string here to avoid allocating a new object and
342344 // 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 ) } ";
344346 }
345347 }
346348 schema [ OpenApiSchemaKeywords . DiscriminatorKeyword ] = polymorphismOptions . TypeDiscriminatorPropertyName ;
@@ -353,9 +355,10 @@ internal static void ApplyPolymorphismOptions(this JsonNode schema, JsonSchemaEx
353355 /// </summary>
354356 /// <param name="schema">The <see cref="JsonNode"/> produced by the underlying schema generator.</param>
355357 /// <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 )
357360 {
358- if ( context . TypeInfo . GetSchemaReferenceId ( ) is { } schemaReferenceId )
361+ if ( createSchemaReferenceId ( context . TypeInfo ) is { } schemaReferenceId )
359362 {
360363 schema [ OpenApiConstants . SchemaId ] = schemaReferenceId ;
361364 }
0 commit comments