Skip to content

Python codegen models of custom API errors do not map detail onto APIError's message attribute #7542

@ejfine

Description

@ejfine

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Linux executable

Client library/SDK language

Python

Describe the bug

I am trying to do use custom error types that populate the "detail" field with Kiota version 1.30.0. In the generated Typescript, the message property of APIError gets automatically mapped to the detail attribute of the error. But this does not happen in the Python codegen.

Expected behavior

I expect the Python codegen to behave the same as the Typescript codegen (the Message attribute of APIError should be populated by the detail field if present)

How to reproduce

Run codegen on that OpenAPI schema. You'll see in the python codegen, that the ProblemDetails model's get_field_deserializers method doesn't do any mapping of detail onto message

Whereas in the typescript, you'll see that message gets set to detail if non-null:
"detail": n => { problemDetails.detail = n.getStringValue(); problemDetails.message = problemDetails.detail ?? ""; },

Open API description file

{
"openapi": "3.1.0",
"info": { "title": "Example", "version": "0.1.0" },
"paths": {
"/api/alarms/thresholds": {
"post": {
"operationId": "create_threshold",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/CreateThresholdPayload" }
}
}
},
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/CreateThresholdResponse" }
}
}
},
"409": {
"description": "Already exists",
"content": {
"application/problem+json": {
"schema": { "$ref": "#/components/schemas/ProblemDetails" }
}
}
}
}
}
}
},
"components": {
"schemas": {
"CreateThresholdPayload": {
"type": "object",
"required": ["metricId"],
"properties": {
"metricId": { "type": "string" }
}
},
"CreateThresholdResponse": {
"type": "object",
"required": ["id"],
"properties": {
"id": { "type": "string" }
}
},
"ProblemDetails": {
"type": "object",
"required": ["title", "status", "detail", "instance"],
"properties": {
"type": { "type": "string", "default": "about:blank" },
"title": { "type": "string" },
"status": { "type": "integer" },
"detail": { "type": "string", "x-ms-primary-error-message": true },
"instance": { "type": "string" }
}
}
}
}
}

Kiota Version

mcr.microsoft.com/openapi/kiota:1.30.0

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

No response

Known Workarounds

No response

Configuration

No response

Debug output

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions