Prev Next

API / Swagger Interview questions

Explain the internal working of $ref resolution across multiple OpenAPI files?

When a tool encounters a $ref pointing outside the current file, it has to locate and load the referenced file, navigate to the specific fragment within it, and substitute that fragment in place of the reference — a process called dereferencing, or "bundling" when the goal is producing one fully self-contained output document.

flowchart TD A[Tool loads main OpenAPI file] --> B[Encounter external $ref, e.g. ./schemas/user.yaml#/User] B --> C[Resolve relative file path from current file's location] C --> D[Load and parse the referenced file] D --> E[Navigate to fragment via the JSON Pointer after #] E --> F{Does that fragment contain further $refs?} F -- Yes --> B F -- No --> G[Substitute resolved content in place of the original $ref] G --> H[Continue processing remaining document]

This resolution is inherently recursive: a referenced file's fragment might itself contain further $refs pointing to yet another file, so a correct resolver has to keep following the chain until every reference bottoms out in an actual concrete value, while also detecting and rejecting circular references that would otherwise resolve forever.

Two related but distinct end results are common: dereferencing fully inlines every reference's content directly in place (producing a larger, but entirely self-contained, single document with no remaining $refs), while bundling collects all referenced content into one file's components section but keeps internal $ref pointers between them intact, avoiding the potentially large duplication that full dereferencing can produce when the same schema is referenced from many places.

What is it called when a resolver fully inlines every $ref's content directly in place?
What must a correct resolver detect and reject to avoid resolving forever?

More Related questions...

What is Swagger? What is the purpose of Swagger? What is the OpenAPI Specification? What is the difference between Swagger and OpenAPI? What are the key components of Swagger? What is Swagger UI? What is Swagger Editor? What is Swagger Codegen? Define paths in an OpenAPI document? What are operations in OpenAPI? What is a schema in OpenAPI? What are the supported formats for writing an OpenAPI document? What is the purpose of the info object in OpenAPI? What are tags used for in Swagger? List the HTTP methods supported in OpenAPI operations? What is a parameter in OpenAPI, and what are its types? What is a response object in OpenAPI? Describe the components section in OpenAPI 3.0? What is $ref used for in OpenAPI documents? How do you use Swagger annotations in a Java Spring Boot application? What is the difference between OpenAPI 2.0 (Swagger) and OpenAPI 3.0? What is the difference between OpenAPI 3.0 and OpenAPI 3.1? Why is contract-first API design preferred over code-first in some teams? How does Swagger support security schemes like OAuth2 and API keys? What is the difference between springfox and springdoc-openapi? How do you document request and response examples in OpenAPI? Explain how Swagger Codegen generates client SDKs from an OpenAPI spec? What is the difference between path parameters and query parameters? How do you handle polymorphism and discriminators in OpenAPI schemas? Explain the lifecycle of validating an OpenAPI document with a linter like Spectral? When should you use the allOf, oneOf, and anyOf keywords in OpenAPI schemas? How do you version a REST API documented with Swagger? What happens when you click "Try it out" in Swagger UI? How do you split a large OpenAPI specification across multiple files? Explain the internal working of Swagger UI's rendering process? How do you mock an API server using an OpenAPI specification? What is the difference between Swagger and Postman? How do you deprecate an API operation in OpenAPI? Explain the execution flow of generating server stubs from an OpenAPI document? What is the difference between Swagger 2.0's definitions and OpenAPI 3.0's components/schemas? How does content negotiation work in OpenAPI, using the content field? Why doesn't OpenAPI natively describe webhooks before version 3.1? How do you handle authentication in Swagger UI for testing secured endpoints? What is the difference between OpenAPI Generator and the legacy Swagger Codegen? Explain how to enforce validation constraints in an OpenAPI schema? How do you convert a Swagger 2.0 document to OpenAPI 3.0? What is the role of the servers object in OpenAPI 3.0? Explain the internal working of $ref resolution across multiple OpenAPI files? How do you implement contract testing using an OpenAPI specification? Explain the execution flow of API documentation generation in a CI/CD pipeline using Swagger/OpenAPI tooling?
Show more question and Answers...

BigData

Comments & Discussions