Closed sword-jin closed 10 months ago
Hi @sword-jin, Thanks for using kiota and for reaching out. If you remove the "default" section, do you still get the error mappings generated? Also kiota clients support automatic redirection, so instead of describing the 302, you could describe the result you get after the redirection and have the client follow it automatically.
@baywet Yes, it disappeared. We need to use this definition to generate server code and the 302 is required. So, is this a bug?
The error mapping is most likely a bug yes. The 302 can stay as is, it was simply in case the actual payload is schematize if you wanted kiota to generate type for it.
For the error mapping issue, would you be willing to submit a pull request?
This is most likely caused by the fact that these conditions are not properly built:
The call to AddErrorMapping
should be in the first if block (where IsErrorDefinition = true;
is)
The LogWarning
should be in an else block instead.
And you can add a unit test by copying this one
schematize
After I changed the logic like you described,
{
codeClass.IsErrorDefinition = true;
executorMethod.AddErrorMapping(errorCode, errorType);
}
if (errorType != null)
logger.LogWarning("Could not create error type for {Error} in {Operation}", errorCode, operation.OperationId);
there is no errorMapping
in the generated code. Is that right?
I am not familiar with c#, please help to fix it if you have time. @baywet
no worries, just authored microsoft/kiota#4026 to address this issue.
I see, please inform me after you create a new tag, I will test it by latest docker image.
On the nightly tag we have a preview going out every Thursday afternoon, Eastern Time.
@baywet , why didn't push a release last week? I am waiting for this bug fix
@sword-jin we had a code-sign certificate expire last week unfortunately. Thank you for your patience while we work to renew it and unblock releases.
Please release once manually if it's possible. 🙂
@baywet
I feel there is still a bug here
I am using latest pacakges:
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.39",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.38",
"@microsoft/kiota-serialization-form": "^1.0.0-preview.28",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.39",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.18",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.36"
}
Type '(writer: SerializationWriter, multipartBody: MultipartBody | undefined) => void' is not assignable to type 'PrimitiveTypesForDeserialization | ModelSerializerFunction<Parsable> | undefined'.
Type '(writer: SerializationWriter, multipartBody: MultipartBody | undefined) => void' is not assignable to type 'ModelSerializerFunction<Parsable>'.
Types of parameters 'multipartBody' and 'value' are incompatible.
Type 'Parsable | undefined' is not assignable to type 'MultipartBody | undefined'.
Type 'Parsable' is missing the following properties from type 'MultipartBody': _boundary, _parts, addOrReplacePart, getPartValue, and 4 more.ts(2322)
(property) RequestMetadata.requestBodySerializer?: PrimitiveTypesForDeserialization | ModelSerializerFunction<Parsable> | undefined
Also, there is no errorMapping in the post
, get
, I expect it has like:
errorMappings: {
_4XX: createODataErrorFromDiscriminatorValue as ParsableFactory<Parsable>,
_5XX: createODataErrorFromDiscriminatorValue as ParsableFactory<Parsable>,
},
I am still using the original openapi.yaml in this issue description.
Can you open a separate issue for the multi part thing please?
Yes this is expected for your description, since the error being described is only a string, kiota can't generate a type that's both a string AND inherits from ApiException (so it can be thrown) We might consider an improvement in the future to read simple strings, and use them as a message, but the goal of the initial PR was simply to unblock you.
Sure, for error in this PR https://github.com/microsoft/kiota-typescript/issues/1053
openapi yaml like:
the generated code is using
createStringFromDiscriminatorValue
which is not imported and not found in theitem/index.ts
I guess the correct one is createMessageFromDiscriminatorValue