Restify for Laravel for Rust

Docs / Agents and tooling

OpenAPI

the OpenAPI 3.1 document of the endpoints, for API clients and SDK generators.

Introduction #

Restify can describe its HTTP endpoints as an OpenAPI 3.1 document. API clients, SDK generators and AI agents read it to learn every endpoint, parameter, request body and response.

The document is built from the same facts as the MCP tools and restify:list: the repositories, their fields, and the #[derive(Schema)] of their input structs. There is no second description to keep in sync.

The document is the crate's openapi feature, on by default. Without it, .openapi(..) and the restify:openapi command don't exist: see Choosing features.

Printing the document #

laravel restify:openapi
laravel restify:openapi --output openapi.json

The first command prints the document as JSON. The second writes it to a file instead. Both work whether or not the application serves the document.

Serving the document #

The document isn't served by default. To serve it, name a path inside the prefix:

Restify::new()
    .authenticate(Authenticate::via::<Sanctum<User>>())
    .openapi("/openapi.json")
    .openapi_version(env!("CARGO_PKG_VERSION"))
    .repository::<PostRepository>()

The application then answers GET /api/restify/openapi.json. The provider's middleware runs first, as it does for every other endpoint, so with the example above a client needs an API token to read it.

The document's settings come from the application:

FieldValue
info.titleAPP_NAME
info.version.openapi_version(..). Default 1.0.0
serversAPP_URL

Describing a model's attributes #

There is nothing to write. The document lists a resource's attributes from the repository's fields: each field's name, and the JSON Schema of its column's type.

In Repository::fieldsIn attributes
Field::new(Post::title)A property with the column's type
A column of Option<T>The type or null
Field::computed("excerpt", ..), Field::computed_with(..)A property with the type the function returns
.label("headline")The property's name
.description("..")description
.as_integer(), .decimals(2)The type the field then writes: an integer, a string
Field::query_only(..)Left out
A column no field listsLeft out

A field of a type the document doesn't know needs restify::Property. See Fields.

attributes requires no field. A list shows fewer fields than one record, and a field with can_see is left out for the requests that don't pass it, so the document lists every field that any HTTP view shows and promises none. A client may rely on a field's type whenever the field is there.

What the document contains #

For a repository named posts:

OperationoperationIdRequestSuccess
GET /api/restify/postsposts.indexThe list parameters200, posts.page
POST /api/restify/postsposts.storeposts.store201, posts.document, with a Location header
GET /api/restify/posts/{id}posts.show200, posts.document
PUT /api/restify/posts/{id}posts.updateposts.update200, posts.document
PATCH /api/restify/posts/{id}posts.patchposts.update200, posts.document
DELETE /api/restify/posts/{id}posts.delete204

Every repository has the bulk endpoints. Its actions and getters appear when it lists them:

When the repositoryOperationoperationIdRequestSuccess
Lists any actionGET /api/restify/posts/actions and /{id}/actionsposts.actions.index, posts.actions.show200, the listing
Lists an action on the list, or a standalone onePOST /api/restify/posts/actionsposts.actions.perform?action= and one of the actions' bodies200, Output
Lists an action on one model, or a standalone onePOST /api/restify/posts/{id}/actionsposts.actions.perform-show?action= and one of the actions' bodies200, Output
Lists any getterGET /api/restify/posts/getters and /{id}/gettersposts.getters.index, posts.getters.show200, the listing
Lists the getter stats on the listGET /api/restify/posts/getters/statsposts.getter.stats200, Output
Lists the getter word-count on one modelGET /api/restify/posts/{id}/getters/word-countposts.getter.word-count200, Output
AlwaysPOST /api/restify/posts/bulkposts.bulk-storeAn array of posts.store200, { "data": [..] } of models
AlwaysPOST /api/restify/posts/bulk/updateposts.bulk-updateAn array of posts.update, each with an id200, {}
AlwaysDELETE /api/restify/posts/bulk/deleteposts.bulk-deleteAn array of ids200, []

The document also has these, each with its own operationId:

  • GET /api/restify/posts/filters and POST /api/restify/posts/apply-restify-advanced-filters, for every repository. See Advanced filters.
  • DELETE /api/restify/posts/{id}/field/{field}, when the repository's update input takes a file. See Files and images.
  • The nested routes of each relationship shown with through or many, such as GET /api/restify/posts/{id}/comments/{relatedId}, and the attach, detach and sync routes of each Related::many. See Relationships.
  • GET /api/restify/search, once, when a repository was added with global_search. See Global search.

The account endpoints appear when the provider serves them, with the tag accounts. Their bodies come from the input structs their handlers check, so the document shows the same fields and rules, and password_confirmation where the confirmed rule asks for it. See Authentication.

When the provider callsOperationoperationIdSuccess
Restify::authPOST /api/register, POST /api/loginregister, login200, the user with meta.token
Restify::authPOST /api/logoutlogout200, { "message" }
Restify::password_resetPOST /api/forgotPassword, POST /api/resetPasswordforgotPassword, resetPassword200, { "message" }
Restify::email_verificationPOST /api/verify/{id}/{hash}verify200, the user with meta.message, or a 302 to the frontend
Restify::profileGET and PUT /api/restify/profileprofile.show, profile.update200, users.document

The answers refer to the user repository's schemas, such as users.attributes, when the provider serves that repository too. Register is the exception: it answers the new user as it was built, before the database filled in its defaults, so such a column shows null, as in Restify for PHP. Its attributes are described as any object. Each throttled route also lists its 429.

Each operation has the tag posts and lists the errors it can answer, as in Reference:

  • Every operation can answer 401 and 403.
  • An operation on one record, with {id} in its path, can answer 404. So can a bulk update or delete, when an item's id isn't found.
  • An operation that reads input or list parameters can answer 422. A getter takes no input, so it never does.

?action= lists the keys of the actions that run there. The request body is anyOf the actions' inputs, from their #[derive(Schema)], with a required repositories for an action on the list. The body is never marked required, because an action whose input has no required field accepts an empty body. The operation's description lists each action's key with its DESCRIPTION. The /action paths, PHP's other name for /actions, aren't listed.

A bulk body is an array of 1 to MAX_BULK items (minItems and maxItems). Its 422 response says how the errors name an item: by its position, from 0, such as 1.title, and items for errors about the array itself. See Bulk operations.

The list parameters are: search when the repository has searchable fields, sort with the columns and scopes it may sort by, page, perPage, related when the repository lists relationships, and each filter column and scope with and without a leading -. Show takes related too.

The schemas live in components.schemas:

SchemaHolds
posts.store, posts.updateThe #[derive(Schema)] of Store and Update
posts.attributesThe repository's fields, none required
posts.resourceid (a string), type (the repository's resource_type), attributes, and relationships when the repository lists relationships
posts.document{ "data": resource }
posts.pagemeta, links and data, as in Reference
posts.list{ "data": [resource, ..] }, what a bulk create or update answers
RelationshipOne RelatedResource, a list of them, or null
RelatedResourceA related model: id, type (its table) and attributes
OutputWhat an action or getter answered. Restify can't see what handle returns, so it may be any JSON
Error, ValidationError{ "message" } and { "message", "errors" }

relationships lists each name from Repository::related, and none is required, because a response has only the ones the request named. Restify doesn't know whether a relationship holds one record or many, so each is a Relationship: one record, a list, or null. See Relationships.

The example app's tests check the document against the official OpenAPI 3.1 schema, and check real responses against the document's own schemas.

What it leaves out #

  • The MCP server. It speaks JSON-RPC, not REST. MCP clients read its tools with tools/list. See MCP.
  • Authentication. Restify can't see what a middleware checks, so the document has no securitySchemes.
  • Filter value types. A filter is described as text, the way the query string carries it.
  • What an action or getter returns. handle returns a Reply of any JSON, which has no schema.
  • Numeric ids in bulk bodies. A bulk update or delete also accepts an id as a number, but the document lists ids as strings.
  • Extra fields in a body. The input schemas refuse properties they don't declare. An HTTP endpoint and an MCP tool ignore such fields instead.