Swagger-php: Is there a way to exclude some (nested) properties from @SWG\Response ?

Created on 30 Nov 2017  路  3Comments  路  Source: zircote/swagger-php

I have following swagger

@SWG\Definition(
    definition="Space",
    @SWG\Property( property="id", type="integer", example=33),
    @SWG\Property( property="name", type="string" ),
    @SWG\Property( property="dataA", type="string", example="very long data string" ),
    @SWG\Property( property="dataB", type="string", example="very long data string" ),
),
@SWG\Get(
    path="/api/v1/client/space/list",
    @SWG\Response( response=200, description="OK", 
        @SWG\Schema(
               type="array", 
               @SWG\Items(ref="#/definitions/Space"), 
        )
    )
)

Above api should return list of Spaces (to show in table) but I only need to getid and name - however Space also have very heavy fields dataA and dataB - which are non needed in table. Is there a way to exclude these fields? For example using some similar syntax to below:

@SWG\Get(
    path="/api/v1/client/space/list",
    @SWG\Response( response=200, description="OK", 
        @SWG\Schema(
               type="array", 
               @SWG\Items(ref="#/definitions/Space", exclude={"dataA","dataB"}), 
        )
    )
)

And also there is a way to exclude more nested fields? By for example:
exclude={"dataA.securityField","dataA.someList[].heavyField"}

?

Most helpful comment

exclude is better.

All 3 comments

Nope, although I can see the benefit of such a feature.

When you split the definition into smaller chunks, you can reuse/combine them with an allOf
You can also create a new "SpaceListEntry" definition and use @SWG\Property(ref="#/definitions/Space/properties/name') etc get some reuse.

@kevupton Any idea how to add this to HandleReferences?

Previously i just use... description attribute (and add comment like: _fields dataA and dataB will be excluded_) however Your third proposition SpaceListEntry:

@SWG\Definition(
    definition="SpaceListEntry",
    @SWG\Property( property="id", ref="#/definitions/Space/properties/id" ),
    @SWG\Property( property="name", ref="#/definitions/Space/properties/name" ),
)

seems to be best in my case. Thanks and I wait for exclude in future :)

The non-array case also would be usefull:

@SWG\Response( response=200, description="OK", 
    @SWG\Schema(ref="#/definitions/Space", exclude={"dataA","dataB"} )
)

exclude is better.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dalabad picture Dalabad  路  4Comments

bfanger picture bfanger  路  4Comments

justicenode picture justicenode  路  4Comments

praditha picture praditha  路  3Comments

jfiala picture jfiala  路  5Comments