Mike
Mike

Reputation: 736

Is there a trick using the Components object by which I can $Ref a frequently used Description object?

I find myself repeating a description again and again within a requestbody > content. I looked for a DRY technique in the OpenAPI v3 Specification where I might use a $Ref in order to simplify things. Nothing jumped out at me. So I thought I would ask the experts here if they know a way.

Upvotes: 1

Views: 51

Answers (1)

MikeRalphson
MikeRalphson

Reputation: 2393

Is it purely the description which repeats, or a sub-section of your requestBody content schema? If the former, you can simply break down your schema into sub-schemas and $ref them. If the latter...

As description is a string property not an object, it cannot be replaced by a $ref, but you can use the allOf schema keyword to combine schemas:

allOf:
  - $ref: '#/components/schemas/myDescription'
  - ... # other schema properties

and in your components/schemas:

myDescription:
  description: 'Re-usable description here'

Upvotes: 1

Related Questions