📪Define a path (route)

You don't need to do something in particular, the path will be caught from routes of your application.

Specify tags, summary or other definition

You can specify some particular OpenAPI property by using #[OpenApi\Path] attribute.

use Hypnodev\OpenapiGenerator\Attributes\OpenApi;

// ...

#[OpenApi\Path(tags: ['Example'], summary: 'Example summary', description: 'Example description', operationId: 'example')]
public function index(): JsonResponse
{
    return response()->json();
}

Be aware that attribute isn't supporting (yet) the notation.

Define route parameters (or query)

Also here you don't need to do anything in the case of a route parameter, the package will take parameters out from the method signature. You only need to be sure about type-hinting of your parameters.

If your route param is expecting a model, then the parameter will be an it, here an example:

public function show(Example $example): JsonResponse
{
    return response()->json($model);
}

The results will be:

If you have to declare a query param, you need to use Attribute or phpDoc:

use Hypnodev\OpenapiGenerator\Attributes\OpenApi;

// ...

/**
* @OpenApi\Query(name=q, required=false)
*/
public function index(Request $request): JsonResponse
{
    return response()->json([]);
}

// ... or

#[OpenApi\Query(name: 'q', required: false)]
public function index(Request $request): JsonResponse
{
    return response()->json([]);
}

Last updated