-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Unbranded Client CodeGen]: Support generating error models instead of reusing the model from core library #5203
Comments
@lirenhe @lmazuel I'd like to clarify the requirement here, when we talk about supporting error model generation, do we talk about the following 1 or both?
|
It should be both, but currently, we don't generate error models so I am not sure the status of (2). |
@lirenhe Hi! Another question about generating erros models, and consider I'm new to this spec: |
Spent some time today to confirm with @bterlson and @johanste Today we consider errors based on a constant, but if intervals are applied to status code, we should be able to use them. For instance:
Means clearly "if in that range, use this model". I create a Python issue with the Python design, linking it here if that helps: This may requires some TCGC help, TBD with @tadelesh We should support only intervals through |
Continued the talk, and ended up with this: P0: "do no harm" behavior.A client language can decide to ignore custom error type if it's not idiomatic to the language, and if their core library doesn't expose custom error deserialization to customers through exception. P1: Support for custom error modelA client language can decide to parse an error received from the service according an error model defined in the TypeSpec. The right model can be discriminated the following way:
Example of TypeSpec with those scenarios: @error
model ApiError {
/** A machine readable error code */
code: string;
/** A human readable message */
message: string;
}
model Standard400Response extends ApiError {
@statusCode
statusCode: 400;
}
model Standard4XXResponse extends ApiError {
@minValue(401)
@maxValue(499)
@statusCode
statusCode: int32;
}
alias WithStandardErrors<T> = T | Standard400Response | Standard4XXResponse | ApiError Translate as:
This would translate to the following Python code (to illustrate): if response.status_code not in [200]:
error = None
if response.status_code == 400:
error = self._deserialize.failsafe_deserialize(_models.Standard400Response, pipeline_response)
elif 401 <= response.status_code <= 499:
error = self._deserialize.failsafe_deserialize(_models.Standard4XXResponse, pipeline_response)
else:
error = self._deserialize.failsafe_deserialize(_models.ApiError, pipeline_response)
raise HttpResponseError(response=response, model=error) Note:
|
Agree to above. There are a few cases in typespec-todo @get op get(@path id: TodoItem.id): TodoItem | NotFoundResponse; It produces
@delete op delete(
@path id: TodoItem.id,
): WithStandardErrors<NoContentResponse | NotFoundResponse>;
alias WithStandardErrors<T> = T | Standard4XXResponse | Standard5XXResponse; It produces
There is also a nuance about model Standard4XXResponse extends ApiError {
@minValue(400)
@maxValue(499)
@statusCode
statusCode: int32;
} On this tsp, there seems no need to have another An alias may be more appropriate, if we don't need the alias Standard4XXResponse = ApiError & {
@minValue(400)
@maxValue(499)
@statusCode
statusCode: int32;
}; |
Clear and concise description of the problem
For unbranded client generation, today, we still use the models from core library when we see the following code which is not correct.
In the unbranded scenario, we should generate models for each Error decorated by
@error
.list of item for each language
Checklist
The text was updated successfully, but these errors were encountered: