simialbi / yii2-schema-org

Schema.org yii2 representation and helpers for json-ld generation
MIT License
17 stars 4 forks source link

Using this module in production & generated files #3

Closed machour closed 5 years ago

machour commented 5 years ago

First off, thank you for this well thought module

I'm wondering about using this module on production, and what would be the best method to ensure that the generated models doesn't change.

For example, currently the Offer model for the git repo is missing the price attribute (at least), so I'm generating the files using the console utility.

I'm a little afraid about the next release of this library bringing back the problem in the Offer file, removing an attribute I'm relying on and causing exceptions on the web site.

I see some solutions for this:

What's your thoughts ? I'll be glad to help implement it

simialbi commented 5 years ago

Hi @machour Thanks for your input. You opened another issue #2. Is it completely broken a.tm. or are the models broken? Your idea with generating models while composer install sounds great. I think this is the best way to solve it. Remove all of the models from repository and (re)generate them on composer install / update process.

machour commented 5 years ago

Actually I've uncovered some more issues with the library:

I've forked this repo and I'm currently fixing all these little things, while adding some caching to the console utility as I'm in really poor network conditions.

I'll let you know when I'm done for my needs, and then we'll discuss the changes and I'll open PRs for you to merge if you're okay with that :)

simialbi commented 5 years ago

Sounds good Thank you for your contribution

machour commented 5 years ago

There you go, opened #4 which fixes a bunch of stuff.

To get back to this issue topic, I think I'd prefer having the ability to set a namespace & folder for the schema models to be generated in, and be able to track them in my repository.

It would be really bad if schema.org updated a schema and removed an attribute I'm using, without me being aware of that.

The command would look something like:

php yii schema/schema-org --namespace="\common\schemas" --path="common/schemas"

Furthermore, I'd add an extra optional parameters, allowing me to define the schemas I want to use in my app:

--schemas=Car,AboutPage

The console utility would generate models only for these schemas in this case (and their parents classes). In my case, this would allow me to have 20 generated classes instead of 571 :)

Autoloading performances & my IDE indexing would be grateful I guess :)

simialbi commented 5 years ago

Looks good. I'm going to check your changes in detail. I understand your needs and the whish to be able to choose the models that should be generated and I think it's a good idea. But delivering an initial set of models is IMO still not necessary. Do you agree? Autogenerating on composer install could be a long time term, you're right. But may be it would be a good idea to define some of the most commonly used models (about 10 or 20) and autogenerate them? This would guarantee that the extension works without the need to do anything first without the delivery of about 500 models with the extension...

machour commented 5 years ago

I think that every developer will have its own need and will eventually have to generate the schemas he wants.

For example, I'm working on an automobile site and my needs are really specific.

IMHO we don't need any schema in the repository at all.

Reasoning:

We could ship just Thing as it's the root of all Schemas, but shipping any thing else would be a potential loss IMHO. And since as soon as I'd generate my schemas, Thing would be duplicated in my own folder, the base Thing will serve no purpose.

Also, if tomorrow Thing gets a new attribute in the specs, this library will instantly be considered as "bogus" before you re-run the generation and publish a new version.

machour commented 5 years ago

my last point made me think a bit more (sorry :D)

Schema.org have several releases: https://schema.org/docs/releases.html

If for some reason, a developer needs to stick to a particular version, let's say 3.3 (business requirement), he should be able to specify it in the CLI option.

The tool would parse this page instead https://schema.org/version/3.3/ which contains all information for 3.3 entities & attributes (sadly all anchors links point to the latest build page, so you have to copy anchors in the url bar to navigate correctly)

machour commented 5 years ago

Just came across https://schema.org/docs/developers.html#defs

This file contains all that's needed to generate the user-requested schemas. Using yii\helpers\ArrayHelper:index() would be a great way to parse the JSON object and greatly simplify the current CLI.

You can also change latest in the url to target a particular version ❤️

simialbi commented 5 years ago

Thank you for the link to that JSON. This will sure help to keep it simple. I will change the code based on this JSON.

machour commented 5 years ago

Mind you, I've came across another problem, as Schemas seems to be able to have multiple inheritance (as it's the case for LocalBusiness here): https://schema.org/AutomotiveBusiness

I'm almost done with a new generator which make use of traits instead of inheritance, and it's coming together pretty well :)

/**
 * A particular physical business or branch of an organization. Examples of
 * LocalBusiness include a restaurant, a particular branch of a restaurant
 * chain, a branch of a bank, a medical practice, a club, a bowling alley,
 * etc.
 *
 * @see http://schema.org/LocalBusiness
 */
trait LocalBusiness
{
    /**
     * @see http://schema.org/Place
     */
    use Place;
    /**
     * @see http://schema.org/Organization
     */
    use Organization;

    /**
     * The price range of the business, for example $$$.
     *
     * @see http://schema.org/priceRange
     */
    public $priceRange;

I'll open a PR once done 🎉