skip to content

OpenAPI

OpenAPI describes an HTTP API as a document: operations, JSON Schema payloads, reusable components and security schemes. Interviewers ask because a spec makes a contract testable and generatable.

part ofAPI stylesoverview, primer and where to startread it →
on this pageshow

questions

page 1 of 2

In an OpenAPI 3.x document, what are the four values of a parameter's in field, and how do they differ?

level: juniorimportance: must knowfreq 70%

answer

  1. Four places a value can travel
  2. One of them is templated into the URL
  3. Three header names are always ignored
  4. Identity is the name plus location pair
  5. One location cannot be optional

basics

~20 s

OpenAPI parameter objects declare inputs outside the body using in: path, query, header, or cookie. A parameter is identified by name plus in. Path parameters must set required: true and must match a template variable in the path string.

solid answer

~50 s

A Parameter Object in OpenAPI 3.x declares one input that is not the request body. The `in` field says where it travels: `path` (a `{}` template variable in the path key), `query` (after the `?`), `header` (a request header), or `cookie` (a name inside the `Cookie` header). Each parameter needs a `name`, an `in`, and normally a `schema`. Parameters are uniquely identified by the `name` + `in` pair, so `id` in path and `id` in query can coexist. Path parameters are special: every template variable in the path key must have a matching parameter with `in: path` and `required: true` — the spec forbids an optional path parameter. Query, header and cookie parameters default to `required: false`. Parameters declared on the Path Item apply to every operation under it; an operation-level parameter with the same `name` + `in` overrides that inherited one.

code

yaml · 27 lines
yaml
paths:
  /tenants/{tenantId}/orders:
    parameters:
      - name: tenantId
        in: path
        required: true
        schema:
          type: string
    get:
      parameters:
        - name: status
          in: query
          required: false
          schema:
            type: string
        - name: X-Request-Id
          in: header
          schema:
            type: string
            format: uuid
        - name: session
          in: cookie
          schema:
            type: string
      responses:
        '200':
          description: Orders

go deeper

for a junior

Be ready to name the four in values and write a small path item with a path parameter and a query parameter, remembering required: true on the path one.

for a middle

Explain that identity is name plus in, how path-item parameters merge with operation-level ones, and why Accept, Content-Type and Authorization header parameters are ignored.

for a senior

Show judgment about where inputs belong: hoisting shared path parameters, keeping credentials in security schemes rather than parameters, and knowing which mistakes break generated clients.

for a principal

Own the house rules — which parameters are declared once in components.parameters versus inline, and how the document stays the single source of truth as many teams add operations.

## What a Parameter Object is In OpenAPI 3.x, everything a client sends is described in one of two ways: as a **Parameter Object** or as the **requestBody**. Parameter Objects cover the inputs that ride along outside the message body — pieces of the URL, request headers, and cookies. Each Parameter Object is a small record with at minimum a `name`, an `in`, and a description of its value (usually `schema`). ## The four locations `in` accepts exactly four values, and no others: - **`path`** — the value is substituted into a `{variable}` placeholder in the path key, e.g. `/orders/{orderId}`. - **`query`** — the value appears in the query string after `?`, e.g. `/orders?status=open`. - **`header`** — the value is sent as a request header, e.g. `X-Request-Id`. - **`cookie`** — the value is one name/value pair inside the `Cookie` request header. ## Path parameters have extra rules Path templating is a two-sided contract. If the path key contains `{orderId}`, there must be a parameter with `name: orderId`, `in: path`, and `required: true`. The spec states that for `in: path` the `required` field is REQUIRED and its value MUST be `true` — there is no such thing as an optional path segment in OpenAPI. If you want the segment to be optional, that is a different path, declared separately (`/orders` and `/orders/{orderId}`). Conversely, declaring `in: path` for a name that appears in no template variable is invalid, and linters flag it. ## Query, header and cookie parameters These default to `required: false`, so a parameter that a client must always send needs `required: true` written out. Query parameters are the common case for filters, sorting keys and paging cursors. Header parameters describe custom request headers — but three names are explicitly excluded: if `in: header` and the name is `Accept`, `Content-Type`, or `Authorization`, the parameter definition SHALL be ignored, because those three are already described elsewhere in the document (content negotiation is expressed by the `content` maps, and authentication by security schemes). Cookie parameters describe one cookie by name; you do not describe the raw `Cookie` header itself. ## Identity, inheritance and overriding A parameter is uniquely identified by the combination of `name` and `in`. Two entries with the same `name` but different `in` are two different parameters and both are legal; two entries with the same `name` and the same `in` in the same list are invalid. Parameters may be declared in two places: on the **Path Item Object**, where they apply to every operation under that path, and on the **Operation Object**, where they apply only to that operation. The operation-level list does not replace the inherited list wholesale — the two are merged, and an operation-level entry with the same `name` + `in` replaces the inherited one. This is how you hoist a shared `{tenantId}` path parameter to the path item once instead of repeating it on `get`, `put` and `delete`. ## Other fields worth knowing - `description` — human documentation; renderers show it next to the field. - `deprecated` — a boolean flag; generators typically emit a deprecation annotation. - `example` / `examples` — sample values (`examples` is a map of named Example Objects; the two are mutually exclusive). - `allowEmptyValue` — query only, and the specification itself discourages its use; treat it as legacy. - `style` / `explode` / `allowReserved` — how a non-trivial value is serialized into the URL. - `content` — an alternative to `schema` for values whose serialization needs a media type; the map must contain exactly one entry. `schema` and `content` are mutually exclusive: a parameter uses one or the other, never both. ## Where teams get this wrong The frequent mistakes are: forgetting `required: true` on a path parameter (many validators reject the document outright); declaring `Authorization` as a header parameter instead of a security scheme, which makes generated clients grow a raw string argument nobody wires up; repeating the same path parameter on every operation rather than on the path item; and inventing a fifth `in` value such as `body` or `formData`, which were Swagger 2.0 concepts replaced in 3.x by `requestBody`.

  • Why is a header parameter named Authorization ignored by OpenAPI tooling?
    The specification says a header parameter named `Accept`, `Content-Type` or `Authorization` SHALL be ignored, because those are described by other parts of the document: content negotiation by the `content` maps on request bodies and responses, and credentials by security schemes. Declaring `Authorization` as a parameter is usually a Swagger 2.0 habit; move it to `components.securitySchemes` and reference it from `security`.
  • If a parameter is declared on the path item and again on the operation, which one wins?
    They merge, and the operation-level entry wins for any parameter with the same `name` and `in` pair. That lets you declare a shared path parameter once on the path item and still narrow, say, its description or example for a single operation. Parameters the operation does not redeclare are inherited unchanged; there is no way to delete an inherited parameter.
  • Can a path parameter be optional in OpenAPI 3.x?
    No. For `in: path` the `required` field is mandatory and its value must be `true`. If a segment is genuinely optional, that is two different resources and you declare two path keys — for example `/orders` and `/orders/{orderId}` — each with its own operations. Trying to express optionality inside one templated path produces a document most validators reject.

saying these in an interview costs you the question

  • Says body or formData is a valid in value
  • Leaves required off a path parameter
  • Declares Authorization as a header parameter
  • Thinks operation parameters replace the whole inherited list
  • Uses both schema and content on one parameter

context

open as a page

In an OpenAPI document, what does a $ref such as '#/components/schemas/Pet' resolve to?

level: juniorimportance: must knowfreq 70%

basics

~10 s

It is a JSON Pointer into the same document: it resolves to the Pet entry under components.schemas, and tooling substitutes that definition wherever the reference appears, so one definition can serve many operations.

open as a page

Where does required live in an OpenAPI schema object, and what does it actually guarantee?

level: juniorimportance: must knowfreq 58%

basics

~20 s

In an OpenAPI schema, required is an array of property names declared on the object schema itself, not a boolean on each property. It only guarantees the key is present — a required property can still hold null if the schema allows null.

open as a page

In an OpenAPI schema, what is the difference between type and format?

level: juniorimportance: must knowfreq 64%

basics

~20 s

In an OpenAPI schema, type is the JSON data type — string, number, integer, boolean, array, object — and is enforced by validators. format is an open-ended hint refining that type, such as int64 or date-time; validators may ignore unknown formats, but code generators use them for type mapping.

open as a page

In OpenAPI 3.x, where are security schemes declared and what type values may they have?

level: juniorimportance: must knowfreq 65%

basics

~20 s

Security schemes live under components.securitySchemes as named entries. OpenAPI 3.0 defines four types — apiKey, http, oauth2 and openIdConnect — and 3.1 adds mutualTLS. Operations then reference a scheme by its name in a security requirement.

open as a page

In an OpenAPI 3.x document, what are the top-level keys and which are required?

level: juniorimportance: must knowfreq 72%

basics

~20 s

An OpenAPI 3.x document is one object whose root keys are openapi, info, servers, paths, components, security, tags and externalDocs. Only openapi and info are always required; 3.0 also requires paths, and 3.1 adds webhooks and jsonSchemaDialect.

open as a page

In an OpenAPI workflow, what is the difference between contract-first and code-first, and what does each cost?

level: middleimportance: must knowfreq 68%

basics

~20 s

Contract-first treats the hand-written OpenAPI document as the source of truth and derives code from it; code-first treats the implementation as the truth and generates the document from annotations. The first buys design review and parallel work, the second buys speed and automatic freshness.

open as a page

In openapi-generator, what do you get from a server stub versus a client SDK for the same spec?

level: middleimportance: must knowfreq 62%

basics

~20 s

Both derive models from the spec's schemas, but a server generator emits routing or controller interfaces you implement, while a client generator emits a ready-to-call HTTP client. The generator is chosen with -g, and operationId and tags determine method and class names.

open as a page

In OpenAPI, when do you use requestBody instead of a parameter, and what does its content map key on?

level: middleimportance: must knowfreq 65%

basics

~20 s

In OpenAPI 3.x anything sent in the HTTP message body is a requestBody, never a parameter. Its content map is keyed by media type, each entry carrying its own schema and examples. requestBody defaults to required: false, so a mandatory payload must say so explicitly.

open as a page

In OpenAPI, how do the style and explode keywords change how an array query parameter appears in the URL?

level: middleimportance: must knowfreq 60%

basics

~20 s

OpenAPI's style picks the serialization rule and explode says whether each array item gets its own key. Query parameters default to style: form with explode: true, giving tags=a&tags=b; explode: false gives tags=a,b. spaceDelimited and pipeDelimited use spaces or pipes instead.

open as a page

In an OpenAPI schema, what is the difference between allOf, anyOf and oneOf?

level: middleimportance: must knowfreq 68%

basics

~20 s

In an OpenAPI schema, allOf requires the value to satisfy every subschema, anyOf requires at least one, and oneOf requires exactly one. allOf is used for composition, oneOf for alternatives, and anyOf for overlapping permissive unions.

open as a page

How do you declare a nullable field in OpenAPI 3.0 versus OpenAPI 3.1?

level: middleimportance: must knowfreq 54%

basics

~10 s

OpenAPI 3.0 uses its own keyword, nullable: true, alongside a single type. OpenAPI 3.1 removed nullable and follows JSON Schema 2020-12, where you write a type array such as type: [string, "null"].

open as a page

In an OpenAPI document, how does operation-level security interact with the root security block?

level: middleimportance: must knowfreq 55%

basics

~20 s

A root-level OpenAPI security block is the default for every operation. An operation's own security field replaces that default entirely rather than adding to it, and an empty array removes the inherited requirement, making the operation public.

open as a page

In OpenAPI 3.x, what does an operation object contain and what is operationId for?

level: middleimportance: must knowfreq 62%

basics

~20 s

An OpenAPI operation object describes one HTTP method on one path: tags, summary, description, operationId, parameters, requestBody, responses, callbacks, deprecated, security and servers. operationId is a document-unique name that tooling uses to identify the operation, typically as the generated method name.

open as a page

What is the difference between Swagger UI and Redoc for rendering an OpenAPI document?

level: juniorimportance: should knowfreq 40%

basics

~20 s

Both render the same OpenAPI document as HTML. Swagger UI is an interactive explorer whose Try it out sends real requests from the browser; Redoc is a read-only three-panel reference page. The choice is interactivity versus a clean published reference.

open as a page

In OpenAPI, what can you store under components besides schemas, and how is each reused?

level: middleimportance: should knowfreq 44%

basics

~20 s

OpenAPI's components object also holds responses, parameters, examples, requestBodies, headers, securitySchemes, links and callbacks — plus pathItems in 3.1. Each is reused with a $ref at a position where that object type is allowed; security schemes are the exception, referenced by key name.

open as a page

In OpenAPI, how do file and URL $ref targets resolve, and what breaks when a spec is split across files?

level: middleimportance: should knowfreq 50%

basics

~20 s

Relative file references resolve against the base URI of the document containing the reference, not the root spec, and may carry a fragment pointer into the target. URL references fetch at build time. Split specs commonly break because tools resolve differently, so bundle before publishing.

open as a page

In an OpenAPI document, what is the difference between two schemes in one security requirement object versus two objects?

level: middleimportance: should knowfreq 45%

basics

~20 s

Two schemes inside one OpenAPI security requirement object mean AND — the caller must satisfy both. Two requirement objects in the security array are alternatives, meaning OR — satisfying any one of them authorizes the request.

open as a page

In an OpenAPI security scheme of type http, what do scheme and bearerFormat actually specify?

level: middleimportance: should knowfreq 50%

basics

~20 s

OpenAPI's http scheme field names an HTTP authentication scheme from the IANA registry — basic, bearer, digest — and determines the Authorization header's form. bearerFormat is a free-text documentation hint about the token's format and is ignored by tooling.

open as a page

In OpenAPI 3.x, how are an operation's responses keyed, and what does default mean?

level: middleimportance: should knowfreq 52%

basics

~20 s

An OpenAPI responses object maps quoted HTTP status codes such as '200', uppercase range wildcards such as '4XX', and the literal key default to Response Objects. default covers any status not matched explicitly. Every Response Object requires a description.

open as a page

What changed structurally from Swagger 2.0 to OpenAPI 3.0 in a spec document?

level: middleimportance: should knowfreq 45%

basics

~20 s

OpenAPI 3.0 replaced Swagger 2.0's host, basePath and schemes with a servers array, turned body and formData parameters into requestBody, replaced document-level consumes and produces with per-operation content maps, and moved definitions, parameters, responses and securityDefinitions under components.

open as a page

How do you wire openapi-generator into a build so generated code stays maintainable?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Generate into a build output directory, never hand-edit the result, pin the generator version so output does not shift under you, and wrap generated clients behind your own interface. Then decide deliberately whether to commit the output or regenerate it every build.

open as a page

How would you enforce OpenAPI style rules across many specs in CI using Spectral?

level: seniorimportance: should knowfreq 34%

basics

~20 s

Publish one shared Spectral ruleset that each repository extends, define rules as a JSONPath given plus a then function and severity, run spectral lint in CI, and gate the build with --fail-severity. Introduce new rules at warn before promoting them to error.

open as a page

In an OpenAPI document, how do you describe a multipart/form-data upload and what does encoding control?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Declare a requestBody with a multipart/form-data content entry whose schema is an object: each property becomes one part. The encoding map then overrides a part's Content-Type and adds part headers, since OpenAPI otherwise infers the part type from the property's schema.

open as a page

In OpenAPI, how do you describe an object-valued query parameter, and when is deepObject the wrong choice?

level: seniorimportance: should knowfreq 40%

basics

~20 s

OpenAPI offers three ways: style form with explode true, which flattens the object into top-level keys; style deepObject, which produces bracketed keys like filter[status]=open; and a content-typed parameter carrying the value as JSON. deepObject fails for nested objects and arrays.

open as a page

In OpenAPI, is a self-referential schema legal, and what breaks with circular $ref chains?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Yes — recursive references are legal and normal for tree-shaped data, provided the cycle passes through an optional or array property so an instance can terminate. Cycles through required properties describe unsatisfiable data, and any tool that inlines references instead of keeping them recurses forever.

open as a page

What does additionalProperties do in an OpenAPI schema, and when is false a mistake?

level: seniorimportance: should knowfreq 44%

basics

~20 s

In an OpenAPI schema, additionalProperties controls properties not listed under properties: true (the default) allows any, false rejects them, and a schema value types them, which is how free-form maps are modelled. Setting false breaks allOf composition and blocks additive evolution.

open as a page

What does an OpenAPI discriminator do, and what must be true for it to work?

level: seniorimportance: should knowfreq 42%

basics

~20 s

An OpenAPI discriminator names a property whose value tells tooling which subschema a polymorphic payload belongs to. It requires propertyName, that property must be present and required in every variant, and it is a serialization hint — it does not replace oneOf validation.

open as a page

In an OpenAPI oauth2 security scheme, what do the flows object and its scopes declare?

level: seniorimportance: should knowfreq 40%

basics

~20 s

An OpenAPI oauth2 scheme's flows object names which grant types the API supports — authorizationCode, clientCredentials, password, implicit — each with its endpoint URLs and a required scopes map of scope name to description. Operations then reference subsets of those scope names.

open as a page

Your team moves an OpenAPI 3.0 document to 3.1 — what changes at the document level?

level: seniorimportance: should knowfreq 34%

basics

~20 s

OpenAPI 3.1 adds the root keys webhooks and jsonSchemaDialect, makes paths optional so a document may describe only webhooks or components, adds a pathItems bucket to components, adds info.summary and an SPDX license.identifier, and aligns Schema Objects with JSON Schema 2020-12.

open as a page

showing 1–30 of 32