kiwilan / php-opds

PHP package to create OPDS feed (Open Publication Distribution System) for eBooks.

Home Page:https://packagist.org/packages/kiwilan/php-opds

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: JSON Schema validation fails due to 'modified' format and null properties

mikespub opened this issue · comments

What happened?

I tried running json schema validation tests on the OPDS 2.0 output, but they failed whenever publications were included.

Reason is that the 'modified' property should be of type 'string' format 'date-time' like 2018-11-13T20:20:39+00:00
But it's actually an object in the JSON output: {"date":"2012-03-03 19:47:50.000000","timezone_type":1,"timezone":"+00:00"}

See https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times for details.

OPDS validation error{
    "/publications/0/metadata/modified": [
        "The data (object) must match the type: string"
    ]
}

How to reproduce the bug

Try to validate the OPDS 2.0 output against the JSON schema using opis/json-schema or some other validator

Package Version

1.0.23

PHP Version

8.2

Which operating systems does with happen with?

Linux

Notes

No response

Sorry, a couple of other errors - it doesn't seem to like having null properties:

    ...
    "/publications/0/metadata/translator": [
        "The data (null) must match the type: string",
        "The data (null) must match the type: array",
        "The data (null) must match the type: object"
    ],
    "/publications/0/images/0/href": [
        "The data (null) must match the type: string"
    ],
    ...
    "/publications/1/metadata/belongsTo": [
        "The data (null) must match the type: object"
    ],
    ...

I try to find JSON schema you used, it one of them?
https://github.com/opds-community/drafts/tree/master/schema

Yes, you can check out how I used the validator from opis/json-schema at
https://github.com/mikespub-org/seblucas-cops/blob/b20f22e4c86370a91aada1dab04ee75e49d1f8ed/test/KiwilanTest.php#L38

and which schemas I used for validation under https://github.com/mikespub-org/seblucas-cops/tree/main/test/schema

The relevant schemas were copied from the https://drafts.opds.io/ and https://readium.org/webpub-manifest/ sites until it stopped complaining :-)

And another "gotcha" that hasn't been pushed to GitHub yet: you need to specify setMaxErrors to see more than 1 error:

        self::$validator = new Validator();
        self::$validator->setMaxErrors(5);

Thanks for your help, I will release it today ;)

Tell me if it's okay with v1.0.30 ;)

Yes, works for me - thanks :-)