Skip to content

Conversation

@desjoerd
Copy link
Contributor

Fix OpenApi Schema type not emiting ["string", "null" ] for [Url] and [Base64String]

Removes explicitly setting the schema type in the applying of data annotation attributes. Both attributes only work on string so it would already have the correct type.

Fixes #63441

Copilot AI review requested due to automatic review settings August 27, 2025 11:13
@desjoerd desjoerd requested review from a team and captainsafia as code owners August 27, 2025 11:13
@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 27, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Aug 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where OpenAPI schema generation was incorrectly setting the type to only "string" for nullable properties decorated with [Url] and [Base64String] attributes, instead of allowing both "string" and "null" types.

Key changes:

  • Removes explicit type setting in validation attribute processing for Base64StringAttribute and UrlAttribute
  • Adds comprehensive test coverage for various data annotation attributes with both nullable and non-nullable properties

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs Removes explicit type assignment for Base64String and Url attributes to preserve nullable type information
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.PropertySchemas.cs Adds comprehensive test coverage for data annotation attributes on nullable and non-nullable properties

@captainsafia
Copy link
Member

/azp run

@captainsafia captainsafia enabled auto-merge (squash) September 3, 2025 18:03
@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@captainsafia captainsafia merged commit 2f18417 into dotnet:main Sep 3, 2025
30 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Sep 3, 2025
@captainsafia
Copy link
Member

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/17444797409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants