MissingFormatException duration
Closed this issue · 2 comments
Dadinos commented
Implemented this middleware and got the following error:
HKarlstrom\Middleware\OpenApiValidation\Exception\MissingFormatException
Message: Missing validator for type=string, format=duration
File:C:\inetpub\wwwroot\zocommongroundapidevelopment\vendor\hkarlstrom\openapi-validation-middleware\src\OpenApiValidation.php
Does the format: duration needs to be inlemented?
Dadinos commented
For now I did::
class myDurationFormat implements Opis\JsonSchema\IFormat {
public function validate($data) : bool
{
// Validate (ISO 8601) duration format P56D or P1Y2DT0H3M
return preg_match('/^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)([DW]))?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/', $data);
}
}
$mw = new HKarlstrom\Middleware\OpenApiValidation(__DIR__.'/catalog_openapi.json');
$mw->addFormat('string','duration',new myDurationFormat());
Dadinos commented
Works perfect case closed