kiota icon indicating copy to clipboard operation
kiota copied to clipboard

Kiota warns that format:uri is not supported in headers

Open bkoelman opened this issue 1 year ago • 2 comments

We use "fornat": "uri" to describe the HTTP Location header in our OpenAPI file, for example:

{
  "responses": {
    "201": {
      "headers": {
        "Location": {
          "required": true,
          "schema": {
            "type": "string",
            "format": "uri"
          }
        }
      }
    }
  }
}

This triggers the following warning when running the Kiota command-line tool:

OpenAPI warning : #/paths/~1api~1tags/post/responses/201/headers/Location/schema - The format uri is not supported by Kiota and the string type will be used.

Headers are exposed by HeadersInspectionHandlerOption, which contains the following property:

public RequestHeaders ResponseHeaders { get; private set; } = new RequestHeaders();

RequestHeaders (note the name mismatch: response headers are stored in the request headers object, but that's beside the point) implements IDictionary<string, IEnumerable<string>>, so header values are always exposed as strings. This makes me wonder whether this warning should be emitted. The warning states it will use strings instead, but isn't that always the expected outcome for header values?

I'd rather not disable all warnings using --log-level Error when running Kiota, but without that, these show up as annoying warnings in the IDE (after running Kiota from an Exec task in the project file).

Would it make sense to suppress this warning for HTTP headers?

bkoelman avatar Feb 25 '24 11:02 bkoelman

Thanks for reporting this.

URI in the format registry

Uri's as models

If we wanted to support URIs as a first class concept for models (as properties, or even the full response itself), we'd need to add methods in IParseNode/ISerializationWriter which would be a source breaking change.

We initially said kiota wouldn't support it because:

  • Some languages have no native constructs for URIs/have multiple (it's a bit like the different Date types)
  • Usage of URIs in APIs is fairly low.
  • Additional burden on the implementation for serialization.

Validation rule

The warning you're getting is effectively coming from the validation rules. But since kiota doesn't project a type for request/response headers, it should not even validate those.

This implementation should be updated to ignore the headers by looking at the context.

https://github.com/microsoft/kiota/blob/0495a000e60e69ba45c69ae7d72c75e14a86285c/src/Kiota.Builder/Validation/InconsistentTypeFormatPair.cs#L54

A unit test for that can be added here

https://github.com/microsoft/kiota/blob/0495a000e60e69ba45c69ae7d72c75e14a86285c/tests/Kiota.Builder.Tests/Validation/InconsistentTypeFormatPairTests.cs#L12

Is this something you'd be willing to submit a pull request for?

baywet avatar Feb 26 '24 13:02 baywet

Not anytime soon, I'm pretty occupied with other work at the moment.

bkoelman avatar Feb 26 '24 14:02 bkoelman