Skip to content

docs: release 2.17.0 #475

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

Merged
merged 2 commits into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/reference/plugins/openapi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ npm install --save-dev @zenstackhq/openapi
| summary | String | API summary | No | |
| securitySchemes | Object | Security schemes for the API. See [here](#security-schemes) for more details. | No | |
| omitInputDetails | Boolean | **Only valid for "rpc" flavor.** If true, the output spec will not contain detailed structures for query/mutation input fields like `where`, `select`, `data`, etc. These fields will be typed as generic objects. Use this option to reduce the size of the generated spec. | No | false |
| modelNameMapping | Object | **Only effective for "rest" flavor.** See [here](#model-name-mapping) for more details. | No | |

#### API flavor

Expand Down Expand Up @@ -64,6 +65,22 @@ The names of the configured security schemes will be added to the root `security

You can override the security scheme for a specific model or operation by using the `@@openapi.meta` attribute.

#### Model name mapping

The `modelNameMapping` option is an object that maps ZModel model names to OpenAPI resource names. This is useful for example when you want to use plural names in URL endpoints. It's only effective for the `rest` flavor. The mapping can be partial. You only need to specify the model names that you want to override.

```zmodel
plugin openapi {
provider = '@zenstackhq/openapi'
prefix = '/api'
modelNameMapping = {
User: 'users'
}
}
```

With the above configuration, the `User` operations will be generated under `/api/users` instead of `/api/user`.

### Attributes

- `@@openapi.meta`
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/server-adapters/api-handlers/rest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ The factory function accepts an options object with the following fields:

Optional. A `number` field representing the default page size for listing resources and relationships. Defaults to 100. Set to Infinity to disable pagination.

- modelNameMapping

Optional. An `Record<string, string>` value that provides a mapping from model names (as defined in ZModel) to URL path names. This is useful for example when you want to use plural names in URL endpoints:

```ts
// endpoint for accessing User model will then be ".../users"
RestApiHandler({
modelNameMapping: {
User: 'users'
}
})
```

The mapping can be partial. You only need to specify the model names that you want to override. If a mapping is provided, only the mapped url path is valid, and accessing to unmapped path will be denied.


## Endpoints and Features

The RESTful API handler conforms to the the [JSON:API](https://jsonapi.org/format/) v1.1 specification for its URL design and input/output format. The following sections list the endpoints and features are implemented. The examples refer to the following schema modeling a blogging app:
Expand Down
34 changes: 32 additions & 2 deletions docs/reference/zmodel-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ model User {
}
```

wil be translated to the following Prisma schema:
will be translated to the following Prisma schema:

```zmodel
model User {
Expand All @@ -766,6 +766,21 @@ model User {
}
```

##### @meta

```zmodel
attribute @meta(_ name: String, _ value: Any)
```

Adds arbitrary metadata to a field. The metadata can be accessed by custom plugins for code generation, or at runtime from the `modelMeta` object exported from `@zenstackhq/runtime/model-meta`. The `value` parameter can be an arbitrary literal expression, including object literals.

```zmodel
model User {
id Int @id
name String @meta(name: "description", value: "The name of the user")
}
```

#### Model attributes

##### @@id
Expand Down Expand Up @@ -927,7 +942,7 @@ model User {
}
```

wil be translated to the following Prisma schema:
will be translated to the following Prisma schema:

```zmodel
model User {
Expand All @@ -937,6 +952,21 @@ model User {
}
```

##### @@meta

```zmodel
attribute @meta(_ name: String, _ value: Any)
```

Adds arbitrary metadata to a field. The metadata can be accessed by custom plugins for code generation, or at runtime from the `modelMeta` object exported from `@zenstackhq/runtime/model-meta`. The `value` parameter can be an arbitrary literal expression, including object literals.

```zmodel
model User {
id Int @id
@@meta('description', 'This is a user model')
}
```

### Predefined attribute functions

##### uuid()
Expand Down
4 changes: 2 additions & 2 deletions docs/the-complete-guide/part1/5-data-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ We can use data validation to improve our app's robustness in many places. Two s

```zmodel
model Space {
...
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
...
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ We can use data validation to improve our app's robustness in many places. Two s

```zmodel
model Space {
...
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
...
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
}
```

Expand Down