documentOperationRequestBody method Null safety

  1. @override
APIRequestBody? documentOperationRequestBody(
  1. APIDocumentContext context,
  2. Operation? operation
)
override

Returns a documented request body for operation.

If an operation method binds an Bind.body argument or accepts form data, this method returns a APIRequestBody that describes the bound body type. You may override this method to take an alternative approach or to augment the automatically generated request body documentation.

Implementation

@override
APIRequestBody? documentOperationRequestBody(
  APIDocumentContext context,
  Operation? operation,
) {
  if (operation!.method == "POST" || operation.method == "PUT") {
    return APIRequestBody.schema(
      context.schema.getObjectWithType(InstanceType),
      contentTypes: ["application/json"],
      isRequired: true,
    );
  }

  return null;
}