Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference self in a definition?

Tags:

swagger

---
swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
paths:
  /:
    get:
      responses:
        200:
          description: OK
definitions:
  Thing:
    properties:
      parent_thing:
        allOf:
          - $ref: '#/definitions/Thing'
        description: parent of this thing

Here is the minimal example. If I write this in swagger-editor, it shows that parent_thing is of type undefined: https://i.imgur.com/OGHlKxg.png

How do I fix that? I want Thing to have a reference to other Things.

like image 872
CrabMan Avatar asked Mar 11 '16 16:03

CrabMan


People also ask

What is an example of self reference?

Self-Reference. In the context of language, self-reference is used to denote a statement that refers to itself or its own referent. The most famous example of a self-referential sentence is the liar sentence : “This sentence is not true.” Self-reference is often used in a broader context as well.

What is self-reference?

Self-reference occurs in natural or formal languages when a sentence, idea or formula refers to itself. The reference may be expressed either directly—through some intermediate sentence or formula—or by means of some encoding.

What is the meaning of reference in English grammar?

The reference may be expressed either directly—through some intermediate sentence or formula—or by means of some encoding. In philosophy, it also refers to the ability of a subject to speak of or refer to itself, that is, to have the kind of thought expressed by the first person nominative singular pronoun "I" in English.

What is self reference criterion?

What is Self Reference Criterion? Self reference criterion is concept specially in international marketing, where all marketers have some unconscious reference towards own culture, religion and values.


1 Answers

You can have self-references, but you probably don't use the allOf construct:

definitions:
  Thing:
    properties:
      parent_thing:
        $ref: '#/definitions/Thing'

The above is valid, if the swagger-editor is not showing it correctly, that is a bug.

like image 68
fehguy Avatar answered Oct 15 '22 08:10

fehguy