Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

  • Change from catch-all _ patterns to explicit type matching with or null
  • String formats (uuid, base64url, date-time, etc.) use (JsonSchemaType.String or null, "format")
  • Numeric formats use (JsonSchemaType.Number or JsonSchemaType.Integer or null, "format")
  • Add Integer type support for int16/int32 formats
  • Add changelog entry
  • Maintains compatibility with OpenAPI format registry
  • All 134 tests pass
  • Verified with real-world examples
Original prompt

This section details on the original issue you should resolve

<issue_title>Deal with missing type keyword</issue_title>
<issue_description>### What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

The OpenApi generator from Asp.NET started omitting the type keyword for DateTime properties starting with .NET 10:

"createdAt": {
-"type": "string",
"format": "date-time"
}

This results in UntypedNode being generated. This is legal according to the OAI spec and means "accept any object as long as it behaves like a date-time".

Expected behavior

We should probably default to string in that case.

How to reproduce

A schema like this:

 "Foo": {
    "type": "object",
    "properties": {
      "createdAt": {
        "type": "string",
        "format": "date-time"
      }
}

Open API description file

No response

Kiota Version

1.29.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

No response

Debug output

Click to expand log ```
</details>


### Other information

_No response_</issue_description>

<agent_instructions>Please investigate and propose a change to the KiotaBuilder.GetPrimitiveType method given that the format on the schema is optional and may not be present.

ensure that there is a fallback option for cases where the type is supplied without a format.

ensure that there is complete test coverage for all code paths</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@gavinbarron</author><body>
It's not clear how this is a kiota problem based on your report here. 

Is kiota failing to generate code that handles the field on the object correctly?
Or are you simply suggesting that we implement a default value of `string` internally for the `type` property of the field descriptor? </body></comment_new>
<comment_new><author>@gavinbarron</author><body>
If I've managed to understand the problem correctly we need to make a change in `KiotaBuilder.GetPrimitiveType` to accommodate this change in asp.net openapi generator.

at present we have a switch case with a case that looks like this for the `date-time` format.

```csharp
(JsonSchemaType.String, "date-time") => new CodeType { Name = "DateTimeOffset", IsExternal = true },

To accomplish this change I propose we drop the schemaType match and move it down the list so that it doesn't apply to numbers, integers, or booleans.

The next natural question; has the same thing happened for formats of time, date, or duration?

If so, we might end up with something like:

        return (typeName & ~JsonSchemaType.Null, format?.ToLowerInvariant()) switch
        {
            (_, "byte") => new CodeType { Name = "base64", IsExternal = true },
            (_, "binary") => new CodeType { Name = "binary", IsExternal = true },
            (JsonSchemaType.String, "base64url") => new CodeType { Name = "base64url", IsExternal = true },
            (JsonSchemaType.String, "uuid") => new CodeType { Name = "Guid", IsExternal = true },
            (JsonSchemaType.String, _) => new CodeType { Name = "string", IsExternal = true }, // covers commonmark and html
            (JsonSchemaType.Number, "double" or "float" or "decimal") => new CodeType { Name = format.ToLowerInvariant(), IsExternal = true },
            (JsonSchemaType.Number or JsonSchemaType.Integer, "int8") => new CodeType { Name = "sbyte", IsExternal = true },
            (JsonSchemaType.Number or JsonSchemaType.Integer, "uint8") => new CodeType { Name = "byte", IsExternal = true },
            (JsonSchemaType.Number or JsonSchemaType.Integer, "int64") => new CodeType { Name = "int64", IsExternal = true },
            (JsonSchemaType.Number, "int16") => new CodeType { Name = "integer", IsExternal = true },
            (JsonSchemaType.Number, "int32") => new CodeType { Name = "integer", IsExternal = true },
            (JsonSchemaType.Number, _) => new CodeType { Name = "double", IsExternal = true },
            (JsonSchemaType.Integer, _) => new CodeType { Name = "integer", IsExternal = true },
            (JsonSchemaType.Boolean, _) => new CodeType { Name = "boolean", IsExternal = true },
            (_, "duration") => new CodeType { Name = "TimeSpan", IsExternal = true },
            (_, "time") => new CodeType { Name = "TimeOnly", IsExternal = true },
            (_, "date") => new CodeType { Name = "DateOnly", IsExternal = true },
            (_, "date-time") => new CodeType { Name = "DateTimeOffset", IsExternal = true },
            (_, _) when !string.IsNullOrEmpty(childType) => new CodeType { Name = childType, IsExternal = false, },
            (_, _) => null,
 ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes microsoft/kiota#7116

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 2 commits January 27, 2026 19:07
Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
…ectly

Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing type keyword for DateTime properties Handle OpenAPI schemas with format but no type keyword Jan 27, 2026
Copilot AI requested a review from gavinbarron January 27, 2026 19:18
@gavinbarron
Copy link
Contributor

@copilot please expand this fix given that the type property is optional we could see format uuid without the type for example.

I expect that the format checks happen independent of the type checks, only using the type field as a fallback if no format has bee supplied

Copilot AI and others added 2 commits January 27, 2026 19:50
Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 27, 2026

@copilot please expand this fix given that the type property is optional we could see format uuid without the type for example.

I expect that the format checks happen independent of the type checks...

Expanded the fix in commit b863256. All format checks now happen independently of type, with type serving only as a fallback when format is absent or unrecognized. This includes uuid, base64url, and all numeric formats (int8, uint8, int16, int32, int64, double, float, decimal). Added 20 new test cases covering all supported formats without type.

@gavinbarron gavinbarron marked this pull request as ready for review January 28, 2026 19:23
@gavinbarron gavinbarron requested a review from a team as a code owner January 28, 2026 19:23
…tterns

Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 29, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/microsoft/kiota/releases
    • Triggering command: /home/REDACTED/work/kiota/kiota/src/kiota/bin/Debug/net10.0/kiota /home/REDACTED/work/kiota/kiota/src/kiota/bin/Debug/net10.0/kiota generate -l csharp -d /tmp/test_datetime.yaml -o /tmp/kiota-output -n TestApi --clean-output (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@baywet
Copy link
Member

baywet commented Jan 29, 2026

Additionally, can you please add a changelog entry.

@gavinbarron
Copy link
Contributor

@copilot please add a changelog entry for this fix

Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 29, 2026

@copilot please add a changelog entry for this fix

Added changelog entry in commit 4d9685c.

baywet
baywet previously approved these changes Jan 29, 2026
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes!

@baywet baywet enabled auto-merge (squash) January 29, 2026 20:24
@baywet
Copy link
Member

baywet commented Jan 29, 2026

@adrian05-ms to give it another review, since I handled conflicts, I can't give it the final review.

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.

3 participants