'Does OpenAPI 3 support using $ref indirectly?

Suppose I'm trying to break out an OpenAPI 3 specification into multiple files. I might do the following:

Spec/
  requestBodies/
    Blog/
      post.yaml
    __index.yaml
  schemas/
    requests/
      post.yaml
    __index.yaml
  SampleAPI.yaml
// SampleAPI.yaml
openapi: 3.0.0

info:
  ...

servers:
  ...

security:
  ...

paths:
  /blog/post:
    post:
      requestBody:
        $ref: ./requestBodies/Blog/post.yaml
      responses:
        ...

components:
  securitySchemes:
    ...

  requestBodies:
    $ref: ./requestBodies/__index.yaml

  schemas:
    $ref: ./schemas/__index.yaml
// requestBodies/__index.yaml
Post:
  $ref ./Blog/post.yaml
// schemas/__index.yaml
Post:
  $ref ./requests/post.yaml

It seems like it would be a better idea to reference components based on where they will fall in the resolved component hierarchy: i.e. blog/post's requestBody would be '#/components/requestBodies/Post', rather than the relative location of the definition file: './requestBodies/Blog/post.yaml'. The latter seems more brittle and like it leaks the implementation details for how the API is split out into files. It's even worse when, say, a requestBody needs to reference a schema, and the choice is between declaring $ref: '#/components/schemas/Post' vs $ref: '../../schemas/requests/post.yaml'.

I have yet to see an IDE that works with OpenAPI that supports the former type of reference, however, while the latter type is readily supported. Is this a case of the IDEs just not being able to validate a specification multiple references deep in real time, or is the OpenAPI specification's intention/requirement that you either put your entire definition in one huge file or fill your definitions with relative file paths between components?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source