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

Genrator seem does'nt work with custom API endpoints #282

Open
johnkhansrc opened this issue Mar 29, 2021 · 2 comments
Open

Genrator seem does'nt work with custom API endpoints #282

johnkhansrc opened this issue Mar 29, 2021 · 2 comments

Comments

@johnkhansrc
Copy link

Hi

We want to generate TS interfaces from swagger.
15% of our API is made up of custom API endpoints who represent other ressources this isen't no related to entities.

Ts generator seem to be blocked on the first custom API endpoint.

Custom API endpoints are defined like this :

namespace App\SwaggerEndpoint;

use ApiPlatform\Core\Annotation\ApiResource;

/**
 * @ApiResource(
 *     collectionOperations={
 *         "get": {
 *             "route_name": "app_v2_ads_getadbyid",
 *             "method": "GET",
 *             "openapi_context": {
 *                 "summary": "Get ads webview",
 *             },
 *         },
 *     },
 *     itemOperations={}
 * )
 */
class Ads
{
}

Capture d’écran du 2021-03-29 18-39-25

We execute that command :
NODE_TLS_REJECT_UNAUTHORIZED=0 npx @api-platform/client-generator --generator typescript https://xxxxxxxxx/ tsI/
This return :
Error: Unable to find the URL for "https://xxxxxxxxx/docs.jsonld#Entrypoint/ads", make sure your api resource has at least one GET item operation declared.

Is it possible to work around this problem ?

Best regards.

@adrienlucas
Copy link

adrienlucas commented Jun 25, 2021

It seems you have only one GET operation and it is a collection one. The error message says you need at least one GET item operation so maybe try something like :

/**
 * @ApiResource(
 *     collectionOperations={
 *         "get": {
 *             "route_name": "app_v2_ads_getadbyid",
 *             "method": "GET",
 *             "openapi_context": {
 *                 "summary": "Get ads webview",
 *             },
 *         },
 *     },
 *     itemOperations={"get"}
 * )
 */
class Ads
{
}

Edit : ⚠️ the given solution is naive (not to say "dumb"), so it may not be what you are looking for. As a matter of fact, I came here because I had the same error message, and reading your issue helped me solve mine by adding a collection GET operation to my ressource.

@metaclass-nl
Copy link

metaclass-nl commented Oct 19, 2023

I think Branch chapter9-react of My tutorial Api Platform does include instructions to generate code from a custom operation, but it is not on a seperate resource.

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