zircote / swagger-php

A php swagger annotation and parsing library
http://zircote.github.io/swagger-php/
Apache License 2.0
5.08k stars 933 forks source link

Possible to override Parameter Schema? #1583

Open akshare opened 5 months ago

akshare commented 5 months ago

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"
           )
    )
),
DerManoMann commented 5 months ago

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.

akshare commented 5 months ago

@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 commented 5 months ago

It doesn't seem possible yet.

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

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