Success
Success
Section titled “Success”Base model for all successful responses.
| Parameter | Type | Description |
|---|---|---|
| status | integer | The HTTP status code |
| message | string | The message to return |
Formats
Section titled “Formats”A JSON example of this model.
{ "status": 200, "message": "Success"}The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: Success.yamltype: objectproperties: status: type: integer minimum: -2147483648 maximum: 2147483647 examples: - 200 message: type: string examples: - Successrequired: - status - messageunevaluatedProperties: not: {}The TypeSpec code for this model.
@Versioning.added(CommonGrants.Versions.v0_1)model Success { @example(200) status: int32;
@example("Success") message: string;}The Python code for this model.
class Success(DefaultResponse): """Default success response."""
status: int = Field( default=200, description="The HTTP status code", examples=[200], ) message: str = Field( default="Success", description="The message", examples=["Success"], )The TypeScript code for this model.
export const SuccessSchema = z.object({ /** HTTP status code */ status: z.number().int(),
/** Success message */ message: z.string(),});Changelog
Section titled “Changelog”| Version | Changes | Schema |
|---|---|---|
| 0.1.0 |
| Success.yaml |
A 200 response with data.
| Parameter | Type | Description |
|---|---|---|
| status | integer | The HTTP status code |
| message | string | The message to return |
| data | any | The data to return |
Formats
Section titled “Formats”A JSON example of this model.
{ "status": 200, "message": "Success", "data": { "id": "123", "name": "Test 1" }}The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: Ok.yamltype: objectproperties: status: type: integer minimum: 200 default: 200 description: The HTTP status code message: type: string default: "Success" description: The message to return data: type: object description: The data to returnrequired: - status - message - dataThe TypeSpec code for this model.
@doc("A 200 response with data")@Versioning.added(CommonGrants.Versions.v0_1)model Ok<T> extends Success { // Inherit the 200 status code ...Http.OkResponse;
/** Response data */ data: T;}Here’s an example of how to use the Ok response within a an API operation:
import "@common-grants/core";import "@typespec/http";
using TypeSpec.Http;using CommonGrants.Responses;
model TestModel { id: string; name: string;}
@summary("Get test")@doc("Get a test model")@getop getTest(): Ok<TestModel>;