Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger: Add description with ref

I want to add a description to an object property that his definition is referenced. Something like that:

      newCreditCard:
        type: object
        properties:
          billingPhone:
            description: Phone number of the card holder
            $ref: "#/definitions/PhoneNumber"

But the editor warns that the description property will be skipped:

Extra JSON Reference properties will be ignored: description

I have found a less elegant workaround that works for the editor, but not for the Swagger UI (not sure that is may due to the recent update to 3.0.2 version of the Swagger UI)

      newCreditCard:
        type: object
        properties:
          billingPhone:
            description: Phone number of the card holder
            allOf:
            - $ref: "#/definitions/PhoneNumber"

How do you do it in your Swaggers specification?

Thanks for the help!

like image 368
Jonathan Huet Avatar asked Mar 24 '17 15:03

Jonathan Huet


1 Answers

If you add anything to the same level of $ref it will be ignored .

json $ref definition https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03#section-3

correct way is to provide the description in the referenced object.

like image 168
Arun Killu Avatar answered Nov 18 '22 12:11

Arun Killu