Each OpenApi Operation
object typically contains a unique operationId
property. E.g. the PetStore example contains an OpenApi specification which contains a section:
...
"/pet/{petId}": {
"get": {
"tags": ["pet"],
"summary": "Find pet by ID",
"description": "Returns a single pet",
"operationId": "getPetById",
...
In this Petstore example the Service
class in service.js contains:
async getPetById(req, resp) {
console.log("getPetById", req.params.petId);
if (req.params.petId === 0) {
// missing required data on purpose !
// this will trigger a server error on serialization
return { pet: "Doggie the dog" };
}
...
If you provide this class to the serviceHandlers
option then fastify-openapi-glue
will create a configuration for Fastify (including validation schema's and potentially securityHandlers) that will map the path /pet/{petId}
to the method with the name of the operationId
, in this case getPetByID
. All parameters that a caller provides to Fastify will be passed on to the method and any data returned by the method will be returned to the caller.
If no operationId
is present in the specification then fastify-openapi-glue
will try to generate one based on the path and the type of operation.
If you let fastify-openapi-glue
generate a project you can see exactly what methods the plugin will look for.
If you want to use a different mapping of operationId's to methods then you can use the operationResolver option.