You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 55c119e
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/book/v7/openapi/write-documentation.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ Defines a `DELETE` HTTP request.
39
39
It should specify at least the following parameters:
40
40
41
41
-`path`: the route to the resource (example: `/resource/{id}` - where `id` is a path parameter defined below)
42
+
-`operationId`: a name unique across the whole document, derived from the handler class name without the `Handler` suffix, with a lowercase first letter (example: `deleteUserResource`). Clients generated from the specification use it as the method name, so do not rename it once released
42
43
-`description`: verbose description of the endpoint's purpose
43
44
-`summary`: short description of the endpoint's purpose
44
45
-`security`: an array of security scheme(s) to be used—omit if the endpoint is not protected
@@ -52,6 +53,7 @@ Defines a `GET` HTTP request.
52
53
It should specify at least the following parameters:
53
54
54
55
-`path`: the route to a single or collection of resources (example: `/resource/{id}` for a single resource or `/resource` for a collection of resources)
56
+
-`operationId`: a name unique across the whole document, derived from the handler class name without the `Handler` suffix, with a lowercase first letter (example: `getUserCollection`). Clients generated from the specification use it as the method name, so do not rename it once released
55
57
-`description`: verbose description of the endpoint's purpose
56
58
-`summary`: short description of the endpoint's purpose
57
59
-`security`: an array of security scheme(s) to be used—omit if the endpoint is not protected
@@ -65,6 +67,7 @@ Defines a `PATCH` HTTP request.
65
67
It should specify at least the following parameters:
66
68
67
69
-`path`: the route to the resource (example: `/resource/{id}` - where `id` is a path parameter defined below)
70
+
-`operationId`: a name unique across the whole document, derived from the handler class name without the `Handler` suffix, with a lowercase first letter (example: `patchUserResource`). Clients generated from the specification use it as the method name, so do not rename it once released
68
71
-`description`: verbose description of the endpoint's purpose
69
72
-`summary`: short description of the endpoint's purpose
70
73
-`security`: an array of security scheme(s) to be used—omit if the endpoint is not protected
@@ -79,6 +82,7 @@ Defines a `POST` HTTP request.
79
82
It should specify at least the following parameters:
80
83
81
84
-`path`: the route to the resource (example: `/resource/{id}` - where `id` is a path parameter defined below)
85
+
-`operationId`: a name unique across the whole document, derived from the handler class name without the `Handler` suffix, with a lowercase first letter (example: `postUserResource`). Clients generated from the specification use it as the method name, so do not rename it once released
82
86
-`description`: verbose description of the endpoint's purpose
83
87
-`summary`: short description of the endpoint's purpose
84
88
-`security`: an array of security scheme(s) to be used—omit if the endpoint is not protected
@@ -93,6 +97,7 @@ Defines a `PUT` HTTP request.
93
97
It should specify at least the following parameters:
94
98
95
99
-`path`: the route to the resource (example: `/resource/{id}` - where `id` is a path parameter defined below)
100
+
-`operationId`: a name unique across the whole document, derived from the handler class name without the `Handler` suffix, with a lowercase first letter (example: `putUserResource`). Clients generated from the specification use it as the method name, so do not rename it once released
96
101
-`description`: verbose description of the endpoint's purpose
97
102
-`summary`: short description of the endpoint's purpose
98
103
-`security`: an array of security scheme(s) to be used—omit if the endpoint is not protected
@@ -101,20 +106,13 @@ It should specify at least the following parameters:
101
106
-`parameters`: an array of `query`/`path` parameters - each parameter is specified as a new `OA\Parameter` object
102
107
-`responses`: an array of `OA\Response` objects, each describing a combination of HTTP status codes and their respective response bodies
103
108
104
-
### Optional parameters
105
-
106
-
The following parameter is available on every request object but is not required:
107
-
108
-
-`operationId`: a name for the operation, unique across the whole document (example: `getUserCollection`).
109
-
Client generators typically use it as the method name, and `Link` objects use it to refer to an operation.
110
-
111
109
## Conclusion
112
110
113
111
To summarize, the typical scenario on working on your own instance of Dotkernel API would follow these steps:
114
112
115
113
- create new module (example: `Book`)
116
114
- add functionality to your new module (routes, entities, repositories, handlers, services, tests etc)
117
-
- create file `OpenAPI.php` in the new module and describe each new endpoint
115
+
- create file `OpenAPI.php` in the new module and describe each new endpoint, giving each one a unique `operationId`
118
116
- declare the tags you used under `tags` in `config/autoload/openapi.global.php`, see [OpenAPI configuration](./configuration.md)
119
117
- generate the latest version of a documentation file as described [in this tutorial](./generate-documentation.md)
120
118
@@ -132,16 +130,22 @@ All the endpoints shipped with Dotkernel API are documented there and serve as w
132
130
133
131
**Q: Which parameters should every request attribute define?**
134
132
135
-
A: `path`, `description`, `summary`, `tags`, `parameters` and `responses`, plus `requestBody` for the methods that accept a body, and `security` when the endpoint is protected.
133
+
A: `path`, `operationId`, `description`, `summary`, `tags`, `parameters` and `responses`, plus `requestBody` for the methods that accept a body, and `security` when the endpoint is protected.
136
134
137
135
**Q: How do I document an unprotected endpoint?**
138
136
139
137
A: Omit the `security` parameter.
140
138
141
139
**Q: Do I need `operationId`?**
142
140
143
-
A: It is optional in OpenAPI, but recommended, especially if you generate a client from the specification and want stable method names.
144
-
It must be unique across the document.
141
+
A: Yes.
142
+
Dotkernel API sets it on every endpoint, named after the handler without the `Handler` suffix (for example `GetUserCollectionHandler` becomes `getUserCollection`), except the two token endpoints, which share one handler and are named after their routes: `postGenerateToken` and `postRefreshToken`.
143
+
A test fails when an endpoint lacks one or when two share one.
144
+
145
+
**Q: What `operationId` do I use when two routes share one handler?**
146
+
147
+
A: Name each after its route instead, still starting with the HTTP method, so the IDs stay unique.
148
+
Dotkernel API does this for its token endpoints, which share one handler: `postGenerateToken` for `/security/generate-token` and `postRefreshToken` for `/security/refresh-token`.
145
149
146
150
**Q: What is the difference between `description` and `summary`?**
Copy file name to clipboardExpand all lines: docs/book/v7/tutorials/api-evolution.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,8 @@ Vary: Origin
71
71
72
72
> The `rel` and `type` arguments are optional, they default to `sunset` and `text/html` if no value is provided and are `Link` related parts.
73
73
74
+
> An operation's `operationId` is part of the contract too: clients generated from the OpenAPI document use it as the method name, so renaming it breaks them even if the route is unchanged.
75
+
74
76
## FAQ
75
77
76
78
**Q: What do the `Sunset` and `Link` headers mean?**
@@ -109,3 +111,8 @@ A: Only handler classes implementing `RequestHandlerInterface`.
109
111
**Q: How do I check that the headers are being sent?**
110
112
111
113
A: Request the endpoint with `curl --head` and inspect the response headers.
114
+
115
+
**Q: Is renaming an `operationId` a breaking change?**
116
+
117
+
A: Yes, for clients generated from the OpenAPI document, which use it as the method name.
118
+
Treat it like a renamed field: keep the old name until its consumers have moved.
Copy file name to clipboardExpand all lines: docs/book/v7/tutorials/create-book-module-via-dot-maker.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ Next you will be prompted to add the relevant components of a module, accepting
85
85
*`Allow viewing Books?` (Y): will generate the single resource GET action handler - `GetBookResourceHandler.php`.
86
86
*`Allow creating Books?` (Y): will generate the POST action handler for the `Book` entity - `PostBookResourceHandler.php`, as well as the input filter used for validating the data - `CreateBookInputFilter.php`.
87
87
*`Allow deleting Books?`, `Allow editing Books?` and `Allow replacing Books?` (N): will generate handlers that reflect the DELETE, PATCH and PUT actions respectively, but are not necessary for this tutorial.
88
-
* Following this step, `dot-maker` will automatically generate the `ConfigProvider.php` classes for both the `Api` and `Core` namespaces, as well as the `OpenAPI.php` class which automatically documents the previously generated routes.
88
+
* Following this step, `dot-maker` will automatically generate the `ConfigProvider.php` classes for both the `Api` and `Core` namespaces, as well as the `OpenAPI.php` class which automatically documents the previously generated routes, each with its own `operationId`.
**Q: What does `dot-maker` do that I would otherwise do by hand?**
470
470
471
-
A: It generates the module skeleton — entity, repository, service and interface, handlers, collection, input filter, both `ConfigProvider` classes and the `OpenAPI.php` documentation — and splits the files between the `Api` and `Core` namespaces without being told to.
471
+
A: It generates the module skeleton — entity, repository, service and interface, handlers, collection, input filter, both `ConfigProvider` classes and the `OpenAPI.php` documentation, including an `operationId` per endpoint — and splits the files between the `Api` and `Core` namespaces without being told to.
0 commit comments