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

Use files as endpoint description #954

Closed
1 task done
Norda-AD opened this issue Feb 20, 2025 · 3 comments
Closed
1 task done

Use files as endpoint description #954

Norda-AD opened this issue Feb 20, 2025 · 3 comments

Comments

@Norda-AD
Copy link

Scribe version

4.38.0

Your question

I have included some HTML content in my endpoint description with the use of docblock. I was trying to replace that with the Endpoint attribute to move the endpoint description to its own file. I had no luck as you could imagine.

The reason behind that is two folds:

  1. I would like to include the same information to multiple endpoints. I want to comply with the DRY principle.
  2. I would like to use some linters on the files to make sure they are properly formatted (not possible at the moment).

Do you think that this could be interesting for the future of scribe?

Thank you for your hard work!

Docs

@shalvah
Copy link
Contributor

shalvah commented Feb 21, 2025

Hey, can you try writing your custom strategy for this? You could make your custom attribute like this:

#[EndpointFromFile(path: '...')]

And then a strategy to read the specified file. It's quite straightforward if you follow the examples in the repo. For example, the UseResponseAttributes strategy does basically this with the ResponseFromFile attribute.

@shalvah shalvah closed this as completed Feb 21, 2025
@shalvah
Copy link
Contributor

shalvah commented Feb 21, 2025

In fact, all you need is an attribute that will read the file. https://github.com/knuckleswtf/scribe/blob/v5/src/Attributes/ResponseFromFile.php

And then extend the PhpAttributeStrategy, specifying the attribute name, defining the extractFromAttributes method, and you're done.

@Norda-AD
Copy link
Author

@shalvah Thank you for your answer. I've never thought of that. I'll try and I'll give you some feedback.

Keep up your nice work!

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

No branches or pull requests

2 participants