swagger-php icon indicating copy to clipboard operation
swagger-php copied to clipboard

Possible to override Parameter Schema?

Open akshare opened this issue 1 year ago • 3 comments

Given this:

@OA\Parameter(
    parameter="sort_by",
    name="sort_by",
    in="query",
    description="Sort by field",
    required=false
),

Is it possible to add/override Schema in the referenced Parameter or some other way to handle this?

Basically, the parameter properties should remain the same (name, in, description, required) and should be reusable while Schema may be different for each implementation.

I understand the example below is incorrect, but it's just for context for what I'm trying to accomplish.


@OA\Get(
    path="/test/{id}",
    tags={"Test"},
    summary="Get specific tests by id",
    @OA\Parameter(
           ref="#/components/parameters/sort_by"
           @OA\Schema(
               type="string",
	       enum={"name","id"},
	       default="name"
           )
    )
),

akshare avatar Apr 30 '24 19:04 akshare

I think the first step would be to try to figure out if this is possible to express in OpenApi yaml/json itself. If so, we can start thinking about how to build it from existing annotations.

DerManoMann avatar Apr 30 '24 21:04 DerManoMann

@DerManoMann your suggestion helped to refine my search.

I think this might work for me, and will update here if I get it to work.

https://stackoverflow.com/questions/27005105/swagger-openapi-use-ref-to-pass-a-reusable-defined-parameter

akshare avatar Apr 30 '24 22:04 akshare

It doesn't seem possible yet.

https://github.com/OAI/OpenAPI-Specification/issues/2029

https://github.com/OAI/OpenAPI-Specification/issues/2026

akshare avatar Apr 30 '24 23:04 akshare