Skip to content

Commit 3ddf6bb

Browse files
authored
docs: release 2.17.0 (#475)
* docs: release 2.17.0 * add `@meta` and `@@meta` docs
1 parent 0c57b12 commit 3ddf6bb

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

docs/reference/plugins/openapi.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ npm install --save-dev @zenstackhq/openapi
2727
| summary | String | API summary | No | |
2828
| securitySchemes | Object | Security schemes for the API. See [here](#security-schemes) for more details. | No | |
2929
| 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 |
30+
| modelNameMapping | Object | **Only effective for "rest" flavor.** See [here](#model-name-mapping) for more details. | No | |
3031

3132
#### API flavor
3233

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

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

68+
#### Model name mapping
69+
70+
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.
71+
72+
```zmodel
73+
plugin openapi {
74+
provider = '@zenstackhq/openapi'
75+
prefix = '/api'
76+
modelNameMapping = {
77+
User: 'users'
78+
}
79+
}
80+
```
81+
82+
With the above configuration, the `User` operations will be generated under `/api/users` instead of `/api/user`.
83+
6784
### Attributes
6885

6986
- `@@openapi.meta`

docs/reference/server-adapters/api-handlers/rest.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ The factory function accepts an options object with the following fields:
8484

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

87+
- modelNameMapping
88+
89+
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:
90+
91+
```ts
92+
// endpoint for accessing User model will then be ".../users"
93+
RestApiHandler({
94+
modelNameMapping: {
95+
User: 'users'
96+
}
97+
})
98+
```
99+
100+
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.
101+
102+
87103
## Endpoints and Features
88104

89105
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:

docs/reference/zmodel-language.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ model User {
757757
}
758758
```
759759

760-
wil be translated to the following Prisma schema:
760+
will be translated to the following Prisma schema:
761761

762762
```zmodel
763763
model User {
@@ -766,6 +766,21 @@ model User {
766766
}
767767
```
768768

769+
##### @meta
770+
771+
```zmodel
772+
attribute @meta(_ name: String, _ value: Any)
773+
```
774+
775+
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.
776+
777+
```zmodel
778+
model User {
779+
id Int @id
780+
name String @meta(name: "description", value: "The name of the user")
781+
}
782+
```
783+
769784
#### Model attributes
770785

771786
##### @@id
@@ -927,7 +942,7 @@ model User {
927942
}
928943
```
929944

930-
wil be translated to the following Prisma schema:
945+
will be translated to the following Prisma schema:
931946

932947
```zmodel
933948
model User {
@@ -937,6 +952,21 @@ model User {
937952
}
938953
```
939954

955+
##### @@meta
956+
957+
```zmodel
958+
attribute @meta(_ name: String, _ value: Any)
959+
```
960+
961+
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.
962+
963+
```zmodel
964+
model User {
965+
id Int @id
966+
@@meta('description', 'This is a user model')
967+
}
968+
```
969+
940970
### Predefined attribute functions
941971

942972
##### uuid()

docs/the-complete-guide/part1/5-data-validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ We can use data validation to improve our app's robustness in many places. Two s
8181
8282
```zmodel
8383
model Space {
84-
...
85-
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
84+
...
85+
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
8686
}
8787
```
8888

versioned_docs/version-1.x/the-complete-guide/part1/5-data-validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ We can use data validation to improve our app's robustness in many places. Two s
8080
8181
```zmodel
8282
model Space {
83-
...
84-
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
83+
...
84+
slug String @unique @regex('^[0-9a-zA-Z]{4,16}$')
8585
}
8686
```
8787

0 commit comments

Comments
 (0)