microsoft / microsoft/kiota

Generation of number based enum property not supported

Open
#3,228 9 comments 1 reaction 0 assignees View on GitHub
enhancement generator
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

Generation of enum property not working. Instead of an enum type the generated property type is a number/integer instead.

Is this not supported or is there someting wrong in my JSON file?

**Repro:**
```json
{
"openapi": "3.0.1",
"info": {
"title": "My API",
"version": "v1"
},
"paths": {
"/Api/MyDto": {
"get": {
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyDto"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"MyDto": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"myEnumId": {
"$ref": "#/components/schemas/MyEnum"
}
},
"additionalProperties": false
},
"MyEnum": {
"enum": [
0,
1,
2,
3
],
"type": "integer",
"format": "int32",
"x-enum-varnames": [
{
"name": "ItemNone",
"value": 0
},
{
"name": "ItemA",
"value": 1
},
{
"name": "ItemB",
"value": 2
},
{
"name": "ItemC",
"value": 3
}
],
"x-ms-enum": {
"name": "MyEnum",
"modelAsString": false,
"values": [
{
"name": "ItemNone",
"value": 0
},
{
"name": "ItemA",
"value": 1
},
{
"name": "ItemB",
"value": 2
},
{
"name": "ItemC",
"value": 3
}
]
},
"x-enumNames": [
"ItemNone",
"ItemA",
"ItemB",
"ItemC"
]
}
}
}
}
```

```shell
kiota generate --openapi swagger.json --clear-cache --clean-output --output out_typescript --language typescript
kiota generate --openapi swagger.json --clear-cache --clean-output --output out_csharp --language csharp
kiota generate --openapi swagger.json --clear-cache --clean-output --output out_java --language java
```

**Version:**
1.5.1+fa29e2d2bffade1fa69c06bf42719bb7c48910b5

**Actual:**
```typescript
import type {Parsable} from '@microsoft/kiota-abstractions';

export interface MyDto extends Parsable {
/**
* The id property
*/
id?: number | undefined;
/**
* The myEnumId property
*/
myEnumId?: number | undefined;
}
```

**Expected:**
```typescript
import type {Parsable} from '@microsoft/kiota-abstractions';

export interface MyDto extends Parsable {
/**
* The id property
*/
id?: number | undefined;
/**
* The myEnumId property
*/
myEnumId?: MyEnum | undefined;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the provided OpenAPI repro and run the listed Kiota generation commands for TypeScript, C#, and Java. Trace how the referenced MyEnum schema is handled by each generator and compare the generated MyDto property with the expected enum type. Done means the generated property uses MyEnum rather than a numeric type for the supported targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi, typescript
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.