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 - messageThe 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: data: description: Response datarequired: - dataallOf: - $ref: Success.yamlunevaluatedProperties: not: {}description: A 200 response with dataThe TypeSpec code for this model.
@doc("A 200 response with data")@Versioning.added(CommonGrants.Versions.v0_1)model Ok extends Success { /** Response data */ data: unknown;}Use the OkT<T> template to define a 200 response with typed data within 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(): OkT<TestModel>;Changelog
Section titled “Changelog”| Version | Changes | Schema |
|---|---|---|
| 0.1.0 |
| Ok.yaml |
Created
Section titled “Created”A 201 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": 201, "message": "Created", "data": { "id": "123", "name": "Test 1" }}The JSON Schema for this model.
$schema: https://json-schema.org/draft/2020-12/schema$id: Created.yamltype: objectproperties: data: description: Response datarequired: - dataallOf: - $ref: Success.yamlunevaluatedProperties: not: {}description: A 201 response with dataThe TypeSpec code for this model.
@doc("A 201 response with data")@Versioning.added(CommonGrants.Versions.v0_1)model Created extends Success { /** Response data */ data: unknown;}Use the CreatedT<T> template to define a 201 response with typed data within an API operation:
import "@common-grants/core";import "@typespec/http";
using TypeSpec.Http;using CommonGrants.Responses;
model TestModel { id: string; name: string;}
@summary("Create test")@doc("Create a test model")@postop createTest(@body body: TestModel): CreatedT<TestModel>;Changelog
Section titled “Changelog”| Version | Changes | Schema |
|---|---|---|
| 0.1.0 |
| Created.yaml |