title: OpenAPI Specification (YML/YAML) : All $refs replace or expand to its definition (with schema validation)
body: <p>I am looking for some solution or maybe some script that can help me to replace($ref) or expand its definitions within the YML file with schema validation. (For detail please find below example)</p>
  <p>**Example: Input with $ref **</p>
  <pre><code>  /pets/{petId}:
      get:
        summary: Info for a specific pet
        operationId: showPetById
        tags:
          - pets
        parameters:
          - name: petId
            in: path
            required: true
            description: The id of the pet to retrieve
            schema:
              type: string
        responses:
          '200':
            description: Expected response to a valid request
            content:
              application/json:
                schema:
                  $ref: &quot;#/components/schemas/Pet&quot;
          default:
            description: unexpected error
            content:
              application/json:
                schema:
                  $ref: &quot;#/components/schemas/Error&quot;
  components:
    schemas:
      Pet:
        type: object
        required:
          - id
          - name
        properties:
          id:
            type: integer
            format: int64
          name:
            type: string
          tag:
            type: string
      Pets:
        type: array
        items:
          $ref: &quot;#/components/schemas/Pet&quot;
      Error:
        type: object
        required:
          - code
          - message
        properties:
          code:
            type: integer
            format: int32
          message:
            type: string
  </code></pre>
  <p><strong>Output: All $ref replace or expanded to its definition (with schema validation)</strong></p>
  <pre><code>  /pets/{petId}:
      get:
        summary: Info for a specific pet
        operationId: showPetById
        tags:
          - pets
        parameters:
          - name: petId
            in: path
            required: true
            description: The id of the pet to retrieve
            schema:
              type: string
        responses:
          '200':
            description: Expected response to a valid request
            content:
              application/json:
                schema:
                  type: object
                  required:
                    - id
                    - name
                  properties:
                    id:
                      type: integer
                      format: int64
                    name:
                      type: string
                    tag:
                      type: string
  
          default:
            description: unexpected error
            content:
              application/json:
                schema:
                  type: object
                  required:
                    - code
                    - message
                  properties:
                    code:
                      type: integer
                      format: int32
                    message:
                      type: string
  components:
    schemas:
      Pet:
        type: object
        required:
          - id
          - name
        properties:
          id:
            type: integer
            format: int64
          name:
            type: string
          tag:
            type: string
      Pets:
        type: array
        items:
          type: object
          required:
            - id
            - name
          properties:
            id:
              type: integer
              format: int64
            name:
              type: string
            tag:
              type: string
  
      Error:
        type: object
        required:
          - code
          - message
        properties:
          code:
            type: integer
            format: int32
          message:
            type: string
  </code></pre>
  <p>Can you please suggest?</p>