Azure / autorest.python

Extension for AutoRest (https://github.com/Azure/autorest) that generates Python code
MIT License
81 stars 57 forks source link

Unbranded CodeGen should generate error models instead of reusing the model from core library #2937

Open lirenhe opened 1 day ago

lirenhe commented 1 day ago

Need to generate the error model from the following definition:

@error
model ApiError {
  /** A machine readable error code */
  code: string;

  /** A human readable message */
  // https://github.com/microsoft/OpenAPI/blob/main/extensions/x-ms-primary-error-message.md
  @OpenAPI.extension("x-ms-primary-error-message", true)
  message: string;
}

Please also verify we could map the error by status code correctly.

model Standard4XXResponse extends ApiError {
  @minValue(400)
  @maxValue(499)
  @statusCode
  statusCode: int32;
}
msyyc commented 1 day ago

For status code range https://github.com/bterlson/typespec-todo/blob/271e2d528ed60e62fbd1c24ed977ed0bc8952fba/main.tsp#L140-L144, Python emitter doesn't support it now: https://github.com/bterlson/typespec-todo/blob/ac50ff69ebdbcce3aa2a4b3fd3edeffe028c5347/output-python/todo/operations/_operations.py#L293-L299. We need some additional work to support it.

msyyc commented 21 hours ago

duplicated issue for https://github.com/Azure/autorest.python/issues/2940