laravel-json-api / eloquent

Serialize Eloquent models to JSON API resources
MIT License
12 stars 15 forks source link

Access column from filters #17

Closed bbrala closed 3 years ago

bbrala commented 3 years ago

I'm helping to build a openapi spec generator but it seems it is not possible to get the column property of a filter. This makes collecting examples for the specification very hard.

Any chance we can make this method public?

     /**
     * @return string
     */
    protected function column(): string
    {
        return $this->column;
    }

This would enable us to generate column examples for filters without doing very weird (and ugly) things.

lindyhopchris commented 3 years ago

Can you elaborate on why it's needed? I would have thought the filter name that was needed for the spec would have been the JSON:API filter name? This is referring to the Eloquent model column name, which I would have thought would be an internal implementation detail?

bbrala commented 3 years ago

The filter name is not really the eloquent name. It could be anything. I was using the filter with a name: "modified_since" with a column name of updated_at and operator >=. Which does make sense.

The problem is generating examples for the fields like here: https://github.com/byte-it/openapi-spec-generator/blob/master/src/Descriptors/Schema/Filters/Where.php#L20

lindyhopchris commented 3 years ago

By examples, do you mean you're creating models for the examples?

bbrala commented 3 years ago

The examples are extracted from real model data and published as part of the resulting spec file. Having real exanples helps a lot in understanding the api.

lindyhopchris commented 3 years ago

Ok, thanks for explaining.

Yeah, I'd be happy with the method being made public - your best bet is to do a PR as I'm pretty limited on open source time at the mo. Otherwise I'll see if I can get to it.

If you do a PR, if you could make the same change to all filters that have a column method - just so it's consistent.

bbrala commented 3 years ago

Ok, cool, ill see when i can make some time.

Related issue

bbrala commented 3 years ago

As promised :)