Skip to content

Commit 55c119e

Browse files
committed
added references to operationId
Signed-off-by: bidi47 <bidi@apidemia.com>
1 parent f3cd083 commit 55c119e

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

‎docs/book/v7/openapi/write-documentation.md‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Defines a `DELETE` HTTP request.
3939
It should specify at least the following parameters:
4040

4141
- `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
4243
- `description`: verbose description of the endpoint's purpose
4344
- `summary`: short description of the endpoint's purpose
4445
- `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.
5253
It should specify at least the following parameters:
5354

5455
- `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
5557
- `description`: verbose description of the endpoint's purpose
5658
- `summary`: short description of the endpoint's purpose
5759
- `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.
6567
It should specify at least the following parameters:
6668

6769
- `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
6871
- `description`: verbose description of the endpoint's purpose
6972
- `summary`: short description of the endpoint's purpose
7073
- `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.
7982
It should specify at least the following parameters:
8083

8184
- `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
8286
- `description`: verbose description of the endpoint's purpose
8387
- `summary`: short description of the endpoint's purpose
8488
- `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.
9397
It should specify at least the following parameters:
9498

9599
- `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
96101
- `description`: verbose description of the endpoint's purpose
97102
- `summary`: short description of the endpoint's purpose
98103
- `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:
101106
- `parameters`: an array of `query`/`path` parameters - each parameter is specified as a new `OA\Parameter` object
102107
- `responses`: an array of `OA\Response` objects, each describing a combination of HTTP status codes and their respective response bodies
103108

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-
111109
## Conclusion
112110

113111
To summarize, the typical scenario on working on your own instance of Dotkernel API would follow these steps:
114112

115113
- create new module (example: `Book`)
116114
- 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`
118116
- declare the tags you used under `tags` in `config/autoload/openapi.global.php`, see [OpenAPI configuration](./configuration.md)
119117
- generate the latest version of a documentation file as described [in this tutorial](./generate-documentation.md)
120118

@@ -132,16 +130,22 @@ All the endpoints shipped with Dotkernel API are documented there and serve as w
132130

133131
**Q: Which parameters should every request attribute define?**
134132

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.
136134

137135
**Q: How do I document an unprotected endpoint?**
138136

139137
A: Omit the `security` parameter.
140138

141139
**Q: Do I need `operationId`?**
142140

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`.
145149

146150
**Q: What is the difference between `description` and `summary`?**
147151

‎docs/book/v7/tutorials/api-evolution.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Vary: Origin
7171
7272
> The `rel` and `type` arguments are optional, they default to `sunset` and `text/html` if no value is provided and are `Link` related parts.
7373
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+
7476
## FAQ
7577

7678
**Q: What do the `Sunset` and `Link` headers mean?**
@@ -109,3 +111,8 @@ A: Only handler classes implementing `RequestHandlerInterface`.
109111
**Q: How do I check that the headers are being sent?**
110112

111113
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.

‎docs/book/v7/tutorials/create-book-module-via-dot-maker.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Next you will be prompted to add the relevant components of a module, accepting
8585
* `Allow viewing Books?` (Y): will generate the single resource GET action handler - `GetBookResourceHandler.php`.
8686
* `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`.
8787
* `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`.
8989

9090
You will then be instructed to:
9191

@@ -468,7 +468,7 @@ curl http://0.0.0.0:8080/book/{id}
468468

469469
**Q: What does `dot-maker` do that I would otherwise do by hand?**
470470

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.
472472

473473
**Q: How do I invoke it?**
474474

0 commit comments

Comments
 (0)