Code Monkey home page Code Monkey logo

models-php's Introduction

models-php Latest Stable Version Total Downloads Tests

PHP Models for the OpenActive Opportunity and Booking Specifications

OpenActive aims to provide model files for all classes defined in its Opportunity and Booking specifications across the PHP, Ruby, and .NET languages. This repository is intended for the PHP files; see also the Ruby and .NET implementations.

Table of Contents

Requirements

This project requires PHP >=5.6.

Installation

To install via Composer, from terminal, run:

composer require openactive/models

Usage

This package provides PHP models for the OpenActive specifications.

It also provide a set of models for the schema.org specifications.

Finally it provides a set of classes to handle OpenActive's RPDE data feeds.

Models

The models are included under the \OpenActive\Models namespace.

You can instantiate a new model, passing an associative array, where the key is the attribute name, and the value is the attribute value.

For example, from your PHP application, run:

// Make sure you use the right namespace for your models
use OpenActive\Models\OA\SessionSeries;
use OpenActive\Models\OA\Place;
use OpenActive\Models\OA\GeoCoordinates;
use OpenActive\Models\OA\Concept;
use OpenActive\Models\OA\Organization;
use OpenActive\Models\OA\Offer;

$sessionSeries = new SessionSeries([
    "name" => "Virtual BODYPUMP",
    "description" => "This is the virtual version of the original barbell class, which will help you get lean, toned and fit - fast",
    "startDate" => "2017-04-24T19:30:00-08:00",
    "endDate" => "2017-04-24T23:00:00-08:00",
    "location" => new Place([
        "name" => "Raynes Park High School, 46A West Barnes Lane",
        "geo" => new GeoCoordinates([
            "latitude" => 51.4034423828125,
            "longitude" => -0.2369088977575302,
        ])
    ]),
    "activity" => [new Concept([
        "id" => "https://openactive.io/activity-list#5e78bcbe-36db-425a-9064-bf96d09cc351",
        "prefLabel" => "Bodypump™",
        "inScheme" => "https://openactive.io/activity-list"
    ])],
    "organizer" => new Organization([
        "name" => "Central Speedball Association",
        "url" => "http://www.speedball-world.com"
    ]),
    "offers" => [new Offer([
        "identifier" => "OX-AD",
        "name" => "Adult",
        "price" => 3.3,
        "priceCurrency" => "GBP",
        "url" => "https://profile.everyoneactive.com/booking?Site=0140&Activities=1402CBP20150217&Culture=en-GB"
    ])],
]);

Please note that type enforcement is in place whenever creating a new model.

For example, providing a string to the target attribute in the example above will result in an \OpenActive\Exception\InvalidArgumentException being thrown.

A set of getters and setters for all the attributes is provided. Type enforcement is in place for setters too.

OpenActive

The OpenActive models are included under the \OpenActive\Models\OA namespace.

To instantiate a new one, see the models section, making sure you are using the right namespace from your model.

Schema.org

The Schema.org models are included under the \OpenActive\Models\SchemaOrg namespace.

To instantiate a new one, see the models section, making sure you are using the right namespace from your model.

RPDE

RpdeItem & RpdeBody are the main classes to use when generating a page for an RPDE feed.

Feed items

RpdeItem is used to create each individual item for a page. It includes a data attribute to which should be an instance of an OA Model along with metadata (id, modified, state and kind). It is left to each application developer to generate these models and metadata.

e.g. a session series collection

use OpenActive\Rpde\RpdeItem;

$feedItems = [
    new RpdeItem([
        "id" => "2",
        "modified" => 4,
        "state" => RpdeState::UPDATED,
        "kind" => RpdeKind::SESSION_SERIES,
        "data" => $sessionSeries2,
    ]),
    new RpdeItem([
        "id" => "1",
        "modified" => 5,
        "state" => RpdeState::DELETED,
        "kind" => RpdeKind::SESSION_SERIES,
    ]),
];

Feed page

RpdeBody is then used to wrap a collection of items and provide the licence and next entries expected from an RPDE page. To help keep pages valid and create an correct next link, use RpdeBody::createFromNextChangeNumber or RpdeBody::createFromModifiedId to create an RPDE page feed out of an array of RpdeItems (the constructor has been made private).

RpdeBody::createFromNextChangeNumber will check that all feed items do indeed come after the $changeNumber argument provided. It will contruct the next link based on the modified value of the newest feed item and the provided $feedBaseUrl argument.

e.g.

use OpenActive\Rpde\RpdeBody;

$feedPage = RpdeBody::createFromNextChangeNumber(
    'https://www.example.com/rpde-feeds/session-series', # $feedBaseUrl
    0, # $changeNumber,
    $feedItems
);

$feedPage->getNext(); # 'https://www.example.com/rpde-feeds/session-series?afterTimestamp=5&afterId=2'

RpdeBody::createFromModifiedId will check that all feed items do indeed come after the $id and $modified arguments provided. It will contruct the next link based on the id and modified value of the newest feed item and the provided $feedBaseUrl argument.

e.g.

use OpenActive\Rpde\RpdeBody;

$feedPage = RpdeBody::createFromModifiedId(
    'https://www.example.com/rpde-feeds/session-series', # $feedBaseUrl
    0, # $modified,
    0, # $id
    $feedItems
);

$feedPage->getNext(); # 'https://www.example.com/rpde-feeds/session-series?afterChangeNumber=5'

To override the default licence:

$feedPage->setLicense('https://www.example.com/my-licence/v2.0');

Serializing the feed page

Finally the feed page can then be serialized with Serialize RpdeBody::serialize($feedPage) which will also take care of serializing the each feed item's data attribute as JSON-LD.

$jsonFeedPage = RpdeBody::serialize($feedPage);

See the OpenActive's guide to publishing data and the RPDE specification for more details about RPDE feeds.

Enums

Each enum is represented by a class which contains a constant for each available value.

e.g. Adding days of the week to a Schedule:

use OpenActive\Models\OA\Schedule;
use OpenActive\Enums\SchemaOrg\DayOfWeek;

new Schedule([
    "scheduledEventType" => "Event",
    "startTime" => "12:00:00",
    "endTime" => "14:00:00",
    "byDay" => [
        new DayOfWeek\Monday,
        new DayOfWeek\Wednesday,
        new DayOfWeek\Friday
    ],
    ...
]);

Serialization

This package provides support for JSON-LD serialization/deserialization of models and and for the \OpenActive\Rpde\RpdeBody object.

serialize($obj, $prettyPrint = false, $schema = false, $modifiers = [])

Returns the JSON-LD string representation of the given object $obj.

An additional parameter $prettyPrint is available to return a JSON-LD string in a human-readable format.

An example, using the \OpenActive\Models\OA\SessionSeries defined above:

use OpenActive\Models\OA\SessionSeries;

echo SessionSeries::serialize($sessionSeries, true);

Will output:

{
    "@context": [
        "https:\/\/openactive.io\/",
        "https:\/\/openactive.io\/ns-beta"
    ],
    "type": "SessionSeries",
    "name": "Virtual BODYPUMP",
    "description": "This is the virtual version of the original barbell class, which will help you get lean, toned and fit - fast.",
    "startDate": "2017-04-24T19:30:00-08:00",
    "endDate": "2017-04-24T23:00:00-08:00",
    "location": {...},
    "activity": {...},
    "organizer": {...},
    "offers": [...]
}

Please note: at the moment by default, only the OpenActive @context is rendered in the serialization output. You may supply the $schema flag to add the Schema.org @context.

deserialize($data)

Returns an object from a given JSON-LD representation.

The $data argument can be a JSON-LD string, or an associative array, for example as a result of json_encode($string, true).

For example:

use OpenActive\Models\OA\Action;

$jsonLd = '{"@context": ["https:\/\/openactive.io\/","https:\/\/openactive.io\/ns-beta"],"type": "Action","name": "Book","target": {"type": "EntryPoint","encodingType": "application\/vnd.openactive.v1.0+json","httpMethod": "POST","type": "EntryPoint","url": "https:\/\/example.com\/orders"}}';

$action = Action::deserialize($jsonLd);

var_dump($action);

Will result in:

object(OpenActive\Models\OA\Action)#3 (24) {
  ["name":protected]=>
  string(4) "Book"
  ["target":protected]=>
  object(OpenActive\Models\OA\EntryPoint)#2 (20) {
    ["encodingType":protected]=>
    string(36) "application/vnd.openactive.v1.0+json"
    ["httpMethod":protected]=>
    string(4) "POST"
    ["urlTemplate":protected]=>
    NULL
    ["actionApplication":protected]=>
    NULL
    ["application":protected]=>
    NULL
    ["actionPlatform":protected]=>
    NULL
    ["contentType":protected]=>
    NULL
    ["identifier":protected]=>
    NULL
    ["name":protected]=>
    NULL
    ["description":protected]=>
    NULL
    ["sameAs":protected]=>
    NULL
    ["url":protected]=>
    string(26) "https://example.com/orders"
    ["image":protected]=>
    NULL
    ["additionalType":protected]=>
    NULL
    ["subjectOf":protected]=>
    NULL
    ["mainEntityOfPage":protected]=>
    NULL
    ["potentialAction":protected]=>
    NULL
    ["disambiguatingDescription":protected]=>
    NULL
    ["alternateName":protected]=>
    NULL
    ["id":protected]=>
    NULL
  }
  ["result":protected]=>
  NULL
  ["startTime":protected]=>
  NULL
  ["actionStatus":protected]=>
  NULL
  ["agent":protected]=>
  NULL
  ["endTime":protected]=>
  NULL
  ["instrument":protected]=>
  NULL
  ["participant":protected]=>
  NULL
  ["object":protected]=>
  NULL
  ["error":protected]=>
  NULL
  ["location":protected]=>
  NULL
  ["identifier":protected]=>
  NULL
  ["description":protected]=>
  NULL
  ["sameAs":protected]=>
  NULL
  ["url":protected]=>
  NULL
  ["image":protected]=>
  NULL
  ["additionalType":protected]=>
  NULL
  ["subjectOf":protected]=>
  NULL
  ["mainEntityOfPage":protected]=>
  NULL
  ["potentialAction":protected]=>
  NULL
  ["disambiguatingDescription":protected]=>
  NULL
  ["alternateName":protected]=>
  NULL
  ["id":protected]=>
  NULL
}

Modifiers

Modifiers allow you to change the serialized context after it has been normalized by the library. An example use-case for this is if you are working with a third party who does not completely adhere to the specification, or has other implementation details which require non-standard serialization. For example, if the third party requires a different date format you could do this:

use OpenActive\Models\OA\SessionSeries;

echo SessionSeries::serialize($sessionSeries, true, false, [
    function ($class, $key, $value, $object) {
      if (!in_array($key, ['startDate', 'endDate'])) {
        return $value;
      }
      return (new \DateTime($value))->format('Y.m.d.H:i:s');
    }
]);

The given modifiers MUST adhere to this method signature:

function (string $class, string $key, mixed $value, mixed $object): mixed

Each modifier MUST always respond with a value, as the modifiers are always applied. If it does not return a value all the data in your object will be wiped during serialization. You SHOULD use the $class and $key parameters to determine if the modifier should run for the parameter, and simply return the $value if it is not necessary. The $object parameter is also available for modifiers which require further information from the parent object.

Modifiers can also be added to the Deserialization process, and are applied before the property is set. This can be useful when having to handle migration paths as changes happen in the library, or to fix data coming from an incompatible seller. Building on the previous example, if the third party in this case is sending dates in an odd format you could do this:

use OpenActive\Models\OA\SessionSeries;

$session = SessionSeries::deserialize('{...}', [
    function ($class, $key, $value, $object) {
      if (!in_array($key, ['startDate', 'endDate'])) {
        return $value;
      }
      return \DateTime::createFromFormat('Y.m.d.H:i:s', $value, new \DateTimeZone('Europe/London'));
    }
]);

Example & helper modifiers can be found in the src/Modifiers directory.

Contributing

Installation

Please note: Composer is required for dependency management.

git clone [email protected]:openactive/models-php.git
cd models-php
composer install

Running Tests

PHPUnit is used to run tests.

To run the whole suite:

./vendor/bin/phpunit

If you want to run the whole suite in verbose mode:

./vendor/bin/phpunit --verbose

You can also run a section of the suite by specifying the class's relative path on which you want to perform tests:

./vendor/bin/phpunit --verbose tests/Unit/RpdeTest.php

For additional information on the commands available for PHPUnit, consult their documentation

Updating models

A guide is provided in UPDATING.md

Implementing APIs

These models can be used in the context of implementing an data API. A guide is provided in IMPLEMENTING_APIS.md

models-php's People

Contributors

adam-openplay avatar drinkynet avatar henryaddison avatar jameslkingsley avatar nathansalter avatar nickevansuk avatar openactive-bot avatar rachelwilson avatar thill-odi avatar thtg88 avatar ylt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

models-php's Issues

Issues with beta:virtualLocation and beta:video

Issue report

There appears to be an issue with beta properties

beta:virtualLocation

$event->setVirtualLocation([]); requires @param \OpenActive\Models\VirtualLocation. When using a VirtualLocation object the Event won’t accept it

Workaround

$array_event["beta:virtualLocation"] = [
  "@type" => "VirtualLocation",
  "name" => "Zoom Video Chat",
  "url" => $live_link,
  "description" => "Please log into Zoom a few minutes before the event, and mute your mic while you wait for the session to start",
];

beta:video

$event->setVideo([$beta_video]) did not work

Workaround:
$array_event += ["beta:video" => [$beta_video]]

Suggested resolution

Check that beta properties and types are being generated correctly, and add tests for these

Reserved word 'Abstract' used in PropertyEnumeration.php

Method OrderItem::setAttendeeDetailsRequired() expects an argument of type \OpenActive\Enums\PropertyEnumeration[] or null passing it an array of instances of Enums (GivenName & FamilyName) generates this syntax error:

PHP Parse error: syntax error, unexpected 'Abstract' (T_ABSTRACT), expecting identifier (T_STRING) in .../vendor/openactive/models/src/Enums/PropertyEnumeration.php on line 88

Line 88 of \OpenActive\Enums\PropertyEnumeration attempts to declare a const called Abstract, which isn't allowed.

Snippet from \OpenActive\Enums\PropertyEnumeration

Time property doesn't support HH:mm

Trying to parse the following:

"openingHoursSpecification": [
    {
        "@type": "OpeningHoursSpecification",
        "opens": "16:00",
        "dayOfWeek": [
            "https://schema.org/Monday"
        ],
        "closes": "21:00"
    },
    {
        "@type": "OpeningHoursSpecification",
        "opens": "16:00",
        "dayOfWeek": [
            "https://schema.org/Tuesday"
        ],
        "closes": "21:00"
    }
]

Will throw the following error:

The first argument type does not match any of the declared parameter types (Time, null) for "16:00" at OpeningHoursSpecification.Opens.

This works fine with HH:mm:ss, so just needs to be fixed.

Serialization bugs relating to type checks

Hi folks,

I've been familiarising myself with OpenActive recently and have been playing around with this package to implement a realtime data doodad.

Very quickly I've stumbled across a serialization issue, that appears to be caused by 2 bugs within Helpers/JsonLd:

  1. Not using instanceof to check for implementations of classes
  2. Assuming all objects will have a getType method (9b5d4d4)

Not using instanceof to check for implementations of classes

There is a lot of comparisons against $fq_classname to check types in Helpers/JsonLd. This is very fragile as it does not detect extensions of classes.

For example, the dates within my application are all instances of Carbon (its a Laravel app), which itself is an extension of \DateTime.

// Get interval spec string, e.g. "P1D"
if($fq_classname === "\\DateInterval") {
return DateIntervalHelper::specString($obj);
}
// Get ISO 8601 date time representation,
// e.g. "2019-01-01T00:00:00-08:00"
if($fq_classname === "\\DateTime") {
return DateTimeHelper::iso8601($obj);
}

These strict comparisons against $fq_classname with the fixed string \\DateTime means JsonLd does not see that my dates are indeed implementations of DateTime instances.

Assuming all objects will have a getType method (9b5d4d4)

// Add type to data if not an RpdeItem
if (
$fq_classname !== "\\OpenActive\\Rpde\\RpdeBody" &&
$fq_classname !== "\\OpenActive\\Rpde\\RpdeItem"
) {
$data["@type"] = $obj->getType();
}

(Similarly, these checks should probably be ! instanceof checks)

Because my Carbon dates are not captured by the DateTime checks earlier in the code, they end up within this block and my app blows up with a BadMethodCallException – because neither Carbon nor DateTIme has a getType method.

I'm not familiar enough with this package to make a judgement whether this is another bug or not. It may be entirely expected that only OpenActive models would make it this far, because from this point forward the class expects objects to have getType and fieldList methods.

Either way, it may be worth adding extra checks to be safe. It looks like OpenActive\Models\SchemaOrg\Thing is a common ancestor to all models that implements both the getType and fieldList methods?


I've only reviewed JsonLd, as that was causing my crash. I've not checked whether anywhere else in this package is susceptible to these issues.

Add new Price type upstream and use for Price properties

The work done in #67 has left us with a little bit of technical debt surrounding the models and properties. We need to have more granular types for some of our properties, mainly TaxChargeSpecification, Offer and PriceSpecification. We should change these to be the more accurate price property when generating the models, and add a validator in this library to handle the new type. This new validator should be very similar to the newly added CurrencyValidator.

RpdeBody::serialize doesn't work

When trying to use RpdeBody::serialize it fails throwing the following exception:

Attempted to call an undefined method named "defineProperty" of class "OpenActive\Rpde\RpdeBody".

Stack trace:

Exception trace:
  at ../vendor/openactive/models/src/Concerns/Serializer.php:65
 ...

Improve documentation

The existing documentation is good as far as it goes, but leaves out a lot of context. To illustrate more fully how the library is to be used, we need to make clear that the library is essentially used to create a (very simple) API.

This means we need to lay out a straightforward sequence for developers walking them through from receiving the request to returning the response. We thus need steps, with examples, illustrating:

  1. Receiving a request
  2. Parsing the request for parameters
  3. Querying the database
  4. Using the query results to create data items
  5. Sequencing these data items
  6. Wrapping up these data items as an RPDE feed
  7. Serialising the RPDE feed to JSON
  8. Returning this JSON as a response

Validator: Required property @id is missing from ScheduledSession.

Its possible to not set the @id for an RpdeItem when building an RpdeBody. The validator then flags an error that it is missing when you validate the feed.

It may aid development if a RuntimeException was thrown if the field is missing so you can pick it up in development before you get to the validator stage.

PriceSpecification & TaxChargeSpecification rounding issues...

Issue Report

I'm seeing rounding issues with the floats in PriceSpecification and TaxChargeSpecification. I'm setting the values to floats with 2 decimal places, but when it comes to serialising the Order/OrderQuote/OrderProposal, it's appending a load of precision issues.

The issue lies in JsonLd->prepareDataForSerialization I believe.

Suggested Resolution

Two possible options:

  1. Move to using integers for financial and percentage values (better solution but more effort)
  2. Change the serialisation/deserialisation routines to handle financial and percentage values as strings.

@context not being set correctly

Issue report

Not specifically setting @context, the models auto generated 3 urls and https://openactive.io/ was not first as the validator requires.

Suggested resolution

serialize($obj, $prettyPrint = false) should accept a parameter for $schemaContext = false, which will add "https://schema.org/" as the first element in the @context array of the root.

The function should also detect if any keys in JSON to be outputted contain the "beta:" prefix, and add "https://openactive.io/ns-beta" as the last element in the @context array if so.

Class OpenActive\Models\SchemaOrg\ThreeDModel does not comply with psr-4 autoloading standard

The ThreeDModel class is defined in the file src/Models/SchemaOrg/3DModel.php, which means it doesn't comply with the psr-4 autoloading standard (the class and the file need the same name/path). This warning is subsequently displayed when composer attempts to generated optimized autoload files:

Class OpenActive\Models\SchemaOrg\ThreeDModel located in ./vendor/openactive/models/src/Models/SchemaOrg/3DModel.php does not comply with psr-4 autoloading standard. Skipping.

Given the models are generated, this seems like a problem with the generation script. I'm adding this issue here for reference, and will cross-link it to one in openactive/models-lib.

integration-(codeIgniter-3.1.10 PHP framwork) openActive package error

openActive package Integration in my 'codeIgniter-3.1.10' php framework , shows below error after RUN example... (example from - https://packagist.org/packages/openactive/models)


A PHP Error was encountered

Severity: Notice

Message: Undefined index: class

Filename: Concerns/TypeChecker.php

Line Number: 52

Backtrace:

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/Concerns/TypeChecker.php
Line: 52
Function: _error_handler

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/Concerns/TypeChecker.php
Line: 32
Function: getTypeCheckerErrorLocation

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/Models/OA/Event.php
Line: 875
Function: checkTypes

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/BaseModel.php
Line: 83
Function: setActivity

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/BaseModel.php
Line: 55
Function: defineProperty

File: /public_html/_repo/codeIgniter-3.1.10/application/controllers/Welcome.php
Line: 56
Function: __construct

File: /public_html/_repo/codeIgniter-3.1.10/index.php
Line: 315
Function: require_once
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /public_html/_repo/codeIgniter-3.1.10/system/core/Exceptions.php:271)

Filename: core/Common.php

Line Number: 570

Backtrace:
An uncaught Exception was encountered

Type: OpenActive\Exceptions\InvalidArgumentException

Message: The first argument type does not match any of the declared parameter types (\OpenActive\Models\OA\Concept[]) for {} at Event.Activity.

Filename: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/Concerns/TypeChecker.php

Line Number: 33

Backtrace:

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/Models/OA/Event.php
Line: 875
Function: checkTypes

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/BaseModel.php
Line: 83
Function: setActivity

File: /public_html/_repo/codeIgniter-3.1.10/application/vendor/openactive/models/src/BaseModel.php
Line: 55
Function: defineProperty

File: /public_html/_repo/codeIgniter-3.1.10/application/controllers/Welcome.php
Line: 56
Function: __construct

File: /public_html/_repo/codeIgniter-3.1.10/index.php
Line: 315
Function: require_once

Duration test failing on equivalent values

@henryaddison @ylt The duration tests described here (SessionSeries.duration: Matches subEvent.startDate and subEvent.endDate difference) and implemented here, which describe the difference between 2 dates must match the duration attribute, are currently failing as PHP seems to convert the difference's interval spec string into a more "normalised" value like the following:

--- Expected
+++ Actual
@@ @@
-'PT90M'
+'PT1H30M'

Where PT90M is the provided interval spec, and PT1H30M is the difference's interval spec.
As you can see these are equivalent (90 minutes is 1h 30min), and both accepted values for ISO8601.

Do you think we should try and normalise the duration input (adding some potentially unnecessary complexity), or leave that test failing for the time-being?

Thanks

Issue with Enums

From Kinetic Insight: We are trying to pass eventstatus to Scheduled session,but we are getting an error. I am attaching the code we used and the error we are getting. Please check it

Code

 $eventStatus =   new  EventStatusType\EventCancelled();
  $scheduledsessionOptions = [
          'id' => '124',
          'identifier'   => '1234',
         'duration'  => 'PT1H',
        'eventStatus'  => $eventStatus
  ];
$session = new ScheduledSession($scheduledsessionOptions);

Error

8883608cbefb6ac05b04bacb5d38cad3

RPDE feed not serialized correctly for empty pages

Currently when serializing an RPDE feed with an empty page the items key is blank.

Example code:

$feedPage = RpdeBody::createFromModifiedId(
    'http://example.com',
    1585574114067820,
    'c8de7e8b-f035-4a1f-a588-4c788176a0e7',
    []
);
$serialized = RpdeBody::serialize($feedPage);

Expected response:

{
  "next": "\/api\/open-active\/individual-facility-uses?afterTimestamp=1585574114067820&afterId=c8de7e8b-f035-4a1f-a588-4c788176a0e7",
  "license": "https:\/\/creativecommons.org\/licenses\/by\/4.0\/",
  "items": []
}

Actual response:

{
  "next": "\/api\/open-active\/individual-facility-uses?afterTimestamp=1585574114067820&afterId=c8de7e8b-f035-4a1f-a588-4c788176a0e7",
  "license": "https:\/\/creativecommons.org\/licenses\/by\/4.0\/"
}

`->id` on objects did not work

Issue report

The validator sometimes required id fields but simply setting ->id on objects did not work because they were not parameters of the class and neither had setter of getter methods defined.

Suggested resolution

Investigation required: ->id should be available on all JSON-LD classes, and should output an @id property

Improve error messages

Issue report

I had to add debug_backtrace() in the TypeChecker trait to see which class the error came from. When some data might be missing or of incorrect type the error sent back is simply saying "The first argument type does not match any of the declared parameter types …” and this can be confusing when I am creating a bunch of objects from various classes in one go (Event, Place, Address, Person, Brand, Concept, etc…)

I am not sure (or maybe I don’t know how to read the code) but I don’t think there is any indication of which are the minimum required fields for each object.

Suggested resolution

Improve error messages, and check that the model does not enforce required fields?

Date serialiser issues for Schedule and PartialSchedule

There is an issue outputting dates from the serialiser for the properties startDate and endDate for Schedule and PartialSchedule.

In the model files it is clear that the properties must be https://schema.org/Date rather than https://schema.org/DateTime:
https://github.com/openactive/data-models/blob/master/versions/2.x/models/Schedule.json#L176

However the serialiser seems to output https://schema.org/DateTime.

Example 1

When running the following code:
echo PartialSchedule::serialize(new PartialSchedule(["startDate" => "2019-11-29"]))

Current output:

{
  "@type": "PartialSchedule",
  "@context": 
  [
    "https://openactive.io/",
    "https://openactive.io/ns-beta"
  ],
  "startDate": "2019-11-29T21:01:31+05:30"
}

Expected output:

{
  "@type": "PartialSchedule",
  "@context": 
  [
    "https://openactive.io/"
  ],
  "startDate": "2019-11-29"
}

Example 2

When running the following code:
echo Schedule::serialize(new Schedule(["startDate" => "2019-11-29"]))

Current output:

{
  "@type": "Schedule",
  "@context": 
  [
    "https://openactive.io/",
    "https://openactive.io/ns-beta"
  ],
  "startDate": "2019-11-29T21:01:31+05:30"
}

Expected output:

{
  "@type": "Schedule",
  "@context": 
  [
    "https://openactive.io/"
  ],
  "startDate": "2019-11-29"
}

Other notes

Issue - Event Status

We are facing an issue with EventStatus Type in OrderQuote.
https://www.openactive.io/open-booking-api/EditorsDraft/#request-and-response
https://gyazo.com/5e75b87fe391d8ba5f471cd11a4a84ed

We are trying to create eventstatus like this
https://gyazo.com/985b456d12fb0c2300e15ff8ef820994
But getting below error message.
{
"status": false,
"error": {
"classname": "OpenActive\Exceptions\InvalidArgumentException",
"message": "The first argument type does not match any of the declared parameter types (\OpenActive\Enums\SchemaOrg\EventStatusType, null) for "OpenActive\\Enums\\SchemaOrg\\EventStatusType\\EventRescheduled"."
}
}
Screenshot 2020-01-08 at 14 33 34

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.