Skip to content

Suppress format warnings for response headers - #8009

Open
AayushP123 wants to merge 1 commit into
microsoft:mainfrom
AayushP123:agent/fix-4227-ignore-header-format-warning
Open

Suppress format warnings for response headers#8009
AayushP123 wants to merge 1 commit into
microsoft:mainfrom
AayushP123:agent/fix-4227-ignore-header-format-warning

Conversation

@AayushP123

@AayushP123 AayushP123 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4227.

Skips unsupported-format validation for response and component header schemas. Kiota exposes response header values as strings, so validating their OpenAPI formats as generated model types produced warnings that users could not act on.

Changes

  • Ignore direct response/component header schemas in both format validation rules.
  • Match structural path segments so a model property named headers is still validated.
  • Add regression tests for response headers, component headers, and similarly named model properties.
  • Add a changelog entry.

Testing

  • dotnet format whitespace kiota.slnx --no-restore --verify-no-changes --include over the four changed source/test files
  • Focused validation tests (11 passed)
  • dotnet test tests/Kiota.Builder.Tests/Kiota.Builder.Tests.csproj --no-restore (2,194 passed, 2 skipped)

Copilot AI review requested due to automatic review settings August 1, 2026 07:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates Kiota’s OpenAPI validation so that “unsupported format” warnings aren’t emitted for response header schemas, since Kiota surfaces response headers as string values and users can’t meaningfully act on those format warnings.

Changes:

  • Skips InconsistentTypeFormatPair validation when the schema path is under an OpenAPI headers node.
  • Adds a regression test for a Location response header using format: uri.
  • Adds a changelog entry describing the behavior change.

Reviewed changes

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

File Description
src/Kiota.Builder/Validation/InconsistentTypeFormatPair.cs Adds a path-based early-return intended to suppress type/format warnings under OpenAPI headers.
tests/Kiota.Builder.Tests/Validation/InconsistentTypeFormatPairTests.cs Adds a regression test asserting no warnings for a response header schema using format: uri.
CHANGELOG.md Documents the suppression of response-header format warnings.
Suppressed comments (1)

src/Kiota.Builder/Validation/InconsistentTypeFormatPair.cs:56

  • This change won’t suppress the warning reported in #4227: the message shown in the issue ("The format uri is not supported by Kiota and the string type will be used.") is emitted by KnownAndNotSupportedFormats, and InconsistentTypeFormatPair already short-circuits for formats in KnownAndNotSupportedFormats.knownAndUnsupportedFormats (which includes uri). To fully address the issue, the same /.../headers/... exclusion likely needs to be applied in KnownAndNotSupportedFormats as well.
        if (context.PathString.Contains("/headers/", StringComparison.OrdinalIgnoreCase) ||
            schema is null || !schema.Type.HasValue || string.IsNullOrEmpty(schema.Format) || KnownAndNotSupportedFormats.knownAndUnsupportedFormats.Contains(schema.Format) || escapedTypes.Contains(schema.Type.Value))
            return;
        var sanitizedType = schema.Type.Value & ~JsonSchemaType.Null;
        if (!validPairs.TryGetValue(sanitizedType, out var validFormats) || !validFormats.Contains(schema.Format))
            context.CreateWarning(nameof(InconsistentTypeFormatPair), $"The format {schema.Format} is not supported by Kiota for the type {sanitizedType} and the string type will be used.");

Comment on lines 51 to 53
if (context.PathString.Contains("/headers/", StringComparison.OrdinalIgnoreCase) ||
schema is null || !schema.Type.HasValue || string.IsNullOrEmpty(schema.Format) || KnownAndNotSupportedFormats.knownAndUnsupportedFormats.Contains(schema.Format) || escapedTypes.Contains(schema.Type.Value))
return;
Comment on lines 126 to 127
var diagnostic = await GetDiagnosticFromDocumentAsync(documentTxt);
Assert.Empty(diagnostic.Warnings);
Comment thread CHANGELOG.md

### Changed

- Fixed unsupported type-format warnings for response header schemas, which are always emitted as strings. [#4227](https://github.com/microsoft/kiota/issues/4227)
@AayushP123
AayushP123 force-pushed the agent/fix-4227-ignore-header-format-warning branch from 58d7b16 to ab3d5db Compare August 1, 2026 09:10
Copilot AI review requested due to automatic review settings August 2, 2026 08:45
@AayushP123
AayushP123 force-pushed the agent/fix-4227-ignore-header-format-warning branch from ab3d5db to 308281d Compare August 2, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (4)

src/Kiota.Builder/Validation/KnownAndNotSupportedFormats.cs:30

  • IsHeaderSchema(context.PathString) is evaluated before checking schema.Format, so this path-splitting logic will run for every schema even when Format is null/empty. Reordering the condition avoids extra allocations and work during validation.
    public KnownAndNotSupportedFormats() : base(nameof(KnownAndNotSupportedFormats), static (context, schema) =>
    {
        if (!IsHeaderSchema(context.PathString) &&
            !string.IsNullOrEmpty(schema.Format) && knownAndUnsupportedFormats.Contains(schema.Format))
            context.CreateWarning(nameof(KnownAndNotSupportedFormats), $"The format {schema.Format} is not supported by Kiota and the string type will be used.");

src/Kiota.Builder/Validation/InconsistentTypeFormatPair.cs:53

  • IsHeaderSchema(context.PathString) is checked first in the early-return condition, so it runs even when schema is null or when Format is empty/irrelevant. Put the header-path check last to short-circuit earlier and reduce per-schema overhead.
    public InconsistentTypeFormatPair() : base(nameof(InconsistentTypeFormatPair), static (context, schema) =>
    {
        if (KnownAndNotSupportedFormats.IsHeaderSchema(context.PathString) ||
            schema is null || !schema.Type.HasValue || string.IsNullOrEmpty(schema.Format) || KnownAndNotSupportedFormats.knownAndUnsupportedFormats.Contains(schema.Format) || escapedTypes.Contains(schema.Type.Value))
            return;

tests/Kiota.Builder.Tests/Validation/InconsistentTypeFormatPairTests.cs:124

  • This test file covers suppressing warnings for response-header schemas, but InconsistentTypeFormatPair now also skips #/components/headers/.../schema. Adding a regression test for component headers would help prevent accidental reintroduction of warnings for reusable header components.
          headers:
            Location:
              schema:
                type: string
                format: int32

CHANGELOG.md:103

  • The changelog entry mentions only response headers, but the change also suppresses warnings for components/headers schemas. Updating the entry to include component headers makes the release note accurate and easier to discover.
- Fixed unsupported type-format warnings for response header schemas, which are always emitted as strings. [#4227](https://github.com/microsoft/kiota/issues/4227)

@AayushP123
AayushP123 marked this pull request as ready for review August 3, 2026 09:43
@AayushP123
AayushP123 requested a review from a team as a code owner August 3, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kiota warns that format:uri is not supported in headers

2 participants