Skip to content

.NET 10 OpenAPI UrlAttribute doesn't emit type: ["null","string"] for nullable string #63441

@desjoerd

Description

@desjoerd

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

While playing around moving the applying of validation attributes to a transformer I found this curious part:

            else if (attribute is UrlAttribute)
            {
                schema[OpenApiSchemaKeywords.TypeKeyword] = JsonSchemaType.String.ToString();
                schema[OpenApiSchemaKeywords.FormatKeyword] = "uri";
            }

This forces the type to be "string" always.
The UrlAttribute only works on strings so it would never be the wrong type, so it doesn't need to be "forced" to a string.

Commenting this line still passes all the tests and emits the correct openapi, both for nullable and not nullable strings.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.NET 10 RC1

Anything else?

It's a one line change and some tests which can be added to OpenApiSchemaService.PropertySchemas.cs.
I can pick this up this week.

Metadata

Metadata

Assignees

Labels

area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions