Skip to content

Error when creating client for c# type int #6541

Open
@rodriciru

Description

@rodriciru

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

I have this simple model:

public class Image
{
    [JsonPropertyName("imageId")]
    public string? ImageId { get; set; }

    [JsonPropertyName("url")]
    public string? Url { get; set; }

    // Cambiado a Dictionary
    [JsonPropertyName("altText")]
    public Dictionary<string, string>? AltText { get; set; }

    [JsonPropertyName("width")]
    public int Width { get; set; }

    [JsonPropertyName("height")]
    public int Height { get; set; }
}

As you can see, at the bottom there are two properties with type int. My c# OpenApi generator creates this spec:

// not relevant content
"components": {
    "schemas": {
      "Image": {
        "type": "object",
        "properties": {
          "imageId": {
            "type": [
              "null",
              "string"
            ]
          },
          "url": {
            "type": [
              "null",
              "string"
            ]
          },
          "altText": {
            "type": [
              "null",
              "object"
            ],
            "additionalProperties": {
              "type": "string"
            }
          },
          "width": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "integer",
              "string"
            ],
            "format": "int32"
          },
          "height": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "integer",
              "string"
            ],
            "format": "int32"
          }
        }
      },
// ....

Width and height is being created with two types (integer and string) (as I suppose you can do "23" and parse as string).

But when I try to create a client for my C# Razor pages, 1.26.0 kiota generates this warning:

warn: Kiota.Builder.KiotaBuilder[0]

OpenAPI warning: #/components/schemas/Image/properties/width - The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.

warn: Kiota.Builder.KiotaBuilder[0]

 OpenAPI warning: #/components/schemas/Image/properties/height - The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.

This is correct?
For now, my solution is to use OpenAPI v3.0, so I don't get multitypes and Kiota doesn't warn about that.

Expected behavior

Kiota should allow multi type schemas

How to reproduce

model is in the description of the issue

kiota generate -d https://localhost:7241/openapi/v1.json -l CSharp -c ApiClientClass -n ReaderApi.Client -o ./ApiClient --exclude-backward-compatible --clean-output

Open API description file

No response

Kiota Version

1.26.0+dd06afb176dd502bb75cefa5c024d7347263b53c

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

No response

Known Workarounds

Use OpenAPI v3.0, so I don't get multitypes and Kiota doesn't warn about that.

Configuration

Windows 11

Debug output

Click to expand log ```

info: Kiota.Builder.KiotaBuilder[0]
Cleaning output directory C:\Users\XXX\CosasGit\ProyectosGit\XXXX\ReaderApi.Client.\ApiClient
dbug: Kiota.Builder.KiotaBuilder[0]
kiota version 1.26.0
dbug: Kiota.Builder.KiotaBuilder[0]
cache file C:\Users\XXX\AppData\Local\Temp\kiota\cache\generation\E7BA93B18316176A90FF66F0D4DC0AF7359BA4EFE54C6E6D8C244D909E4490C7\v1.json not found, downloading from https://localhost:7241/openapi/v1.json
info: Kiota.Builder.KiotaBuilder[0]
skipping cache write for URI https://localhost:7241/openapi/v1.json as it is a loopback address
info: Kiota.Builder.KiotaBuilder[0]
loaded description from remote source
dbug: Kiota.Builder.KiotaBuilder[0]
step 1 - reading the stream - took 00:00:00.1480758
warn: Kiota.Builder.KiotaBuilder[0]
OpenAPI warning: #/components/schemas/Image/properties/width - The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
OpenAPI warning: #/components/schemas/Image/properties/height - The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.
warn: Kiota.Builder.KiotaBuilder[0]
OpenAPI warning: #/components/schemas/ProblemDetails/properties/status - The format int32 is not supported by Kiota for the type Integer, String and the string type will be used.
dbug: Kiota.Builder.KiotaBuilder[0]
step 2 - parsing the document - took 00:00:00.0963585
dbug: Kiota.Builder.KiotaBuilder[0]
step 3 - updating generation configuration from kiota extension - took 00:00:00.0001215
dbug: Kiota.Builder.KiotaBuilder[0]
step 4 - filtering API paths with patterns - took 00:00:00.0048840
info: Kiota.Builder.KiotaBuilder[0]
Client root URL set to https://localhost:7241
dbug: Kiota.Builder.KiotaBuilder[0]
step 5 - checking whether the output should be updated - took 00:00:00.0214610
dbug: Kiota.Builder.KiotaBuilder[0]
step 6 - create uri space - took 00:00:00.0038184
dbug: Kiota.Builder.KiotaBuilder[0]
InitializeInheritanceIndex 00:00:00.0042083
dbug: Kiota.Builder.KiotaBuilder[0]
CreateRequestBuilderClass 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
MapTypeDefinitions 00:00:00.0070214
dbug: Kiota.Builder.KiotaBuilder[0]
TrimInheritedModels 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
CleanUpInternalState 00:00:00
dbug: Kiota.Builder.KiotaBuilder[0]
step 7 - create source model - took 00:00:00.0778695
dbug: Kiota.Builder.KiotaBuilder[0]
34ms: Language refinement applied
dbug: Kiota.Builder.KiotaBuilder[0]
step 8 - refine by language - took 00:00:00.0347924
dbug: Kiota.Builder.KiotaBuilder[0]
step 9 - writing files - took 00:00:00.0893534
dbug: Kiota.Builder.KiotaBuilder[0]
cache file C:\Users\XXX\AppData\Local\Temp\kiota\cache\generation\E7BA93B18316176A90FF66F0D4DC0AF7359BA4EFE54C6E6D8C244D909E4490C7\v1.json not found, downloading from https://localhost:7241/openapi/v1.json
info: Kiota.Builder.KiotaBuilder[0]
skipping cache write for URI https://localhost:7241/openapi/v1.json as it is a loopback address
info: Kiota.Builder.KiotaBuilder[0]
loaded description from remote source
dbug: Kiota.Builder.KiotaBuilder[0]
step 10 - writing lock file - took 00:00:00.0255176
Generation completed successfully
Client base url set to https://localhost:7241
dbug: Kiota.Builder.KiotaBuilder[0]
Api manifest path: C:\Users\XXX\CosasGit\ProyectosGit\XXXX\ReaderApi.Client\apimanifest.json

</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Waits for author 🔁

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions