Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the requestBody for the post endpoints #11

Open
caduvieira opened this issue Dec 25, 2024 · 12 comments
Open

Add the requestBody for the post endpoints #11

caduvieira opened this issue Dec 25, 2024 · 12 comments
Assignees

Comments

@caduvieira
Copy link

The post endpoints in the API doc doesn't have a requestBody example or specification. Would be nice to have it.

If added to the openapi.yaml should be enough
https://learn.openapis.org/specification/parameters.html

@jbrooksuk
Copy link
Member

Great spot! I'm not at my laptop at the moment, but I'll get this fixed when I'm back.

@jbrooksuk
Copy link
Member

I had a quick look at this earlier and it's caused by us switching to spatie/laravel-data. Scribe is no longer able to read a FormRequest so is unable to derive the request body.

We'll need to write a custom Scribe strategy to pull the data from Laravel Data, pretty gnarly.

@jbrooksuk
Copy link
Member

Actually, pinging @joelbutcher (refactored Cachet into laravel-data and @olivernybroe (experience writing Scribe strategies).

@joelbutcher
Copy link

@jbrooksuk I'm working on a Scribe strategy specifically for Laravel Data for work. I'm hoping to publish this soon. If you assign this to me, I'll make sure to create a PR once this is done. 👍

@jbrooksuk
Copy link
Member

Hah, no way @joelbutcher! I'll make the PR in Cachet itself that installs, configures and generates the Scribe docs.

@joelbutcher
Copy link

@jbrooksuk
Copy link
Member

@joelbutcher I've tested this out (cachethq/cachet#4449) but it's not generating everything. A good example is the POST components endpoint. Only the name field is generated.

@joelbutcher
Copy link

joelbutcher commented Jan 6, 2025

@jbrooksuk That's odd, by the looks of it, Laravel Data itself isn't returning any rules for the properties with default values. Might have to dig a bit deeper into laravel-data as to why this is occurring. An alternative is to scrap using PHP attributes and define a static rules method on each request (similar to Laravel Form requests):

public static function rules(ValidationContext $context): array
{
    return [
        //...
    ];
}

@joelbutcher
Copy link

@jbrooksuk I'll send in a PR today that uses the rules method to explicitly define the validation rules, rather than having Laravel Data infer from types and attributes

@jbrooksuk
Copy link
Member

Amazing, thanks @joelbutcher!

@joelbutcher
Copy link

@jbrooksuk at one point we had float as a validation rule for creating and updating a metric, but I'm now running into this error:

Method Illuminate\Validation\Validator::validateFloat does not exist.

Is there an alternative rule we can use? I was thinking decimal?

@jbrooksuk
Copy link
Member

Yeah, decimal should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants