﻿# OpenAPI input and output schemas: direction and actual serialization

Preserve request and response direction when interpreting schema annotations, compare generated input/output schemas, and verify actual serialization behavior.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-openapi-input-output-schema-direction/
Language: en

## Direction is part of the API contract

A model-management resource can contain server-generated identifiers, submitted settings and fields that should not be returned. A single conceptual entity does not imply that the request and response have identical accepted or emitted shapes.

A proposed client generator preserves the direction in which each schema is used. Reusing a response object as an update body may accidentally send fields that the server owns, while using an input type as the complete response definition can omit information the server promises to return.

## Annotations do not perform runtime filtering

The inspected OpenAPI specification treats readOnly and writeOnly as annotations and describes extended, direction-aware handling. It also explicitly notes differences from earlier specification behavior. Applying a familiar older rule without checking the document's version can therefore misstate the contract.

The annotation itself does not execute a serializer or remove a sensitive field. A consumer needs the application's actual response construction and validation behavior. Documentation that labels a field write-only is not sufficient evidence that no endpoint ever emits it.

## Schema generation can depend on mode

Pydantic documents schema generation for validation and serialization modes. A type's accepted input and serialized output can differ, so the selected mode changes what the generated schema describes.

Record that mode when comparing generated documents. A schema built for serialization should not silently stand in for one describing incoming request acceptance. Conversely, the fact that an input parser can construct an object does not establish the shape later emitted by the configured serializer.

## Frameworks can publish separate components

FastAPI's guide explains that one Pydantic model can lead to separate input and output schemas, including differences in required fields associated with defaults. This is a concrete framework behavior, not proof that every OpenAPI tool handles direction in the same way.

A generated SDK may produce different types from those components. Review the operations that reference them, not only their names. Collapsing apparently similar components can erase a distinction the server deliberately exposed for request validity or response completeness.

## Validate the actual directional boundary

A proposed compatibility review inspects submitted server-owned fields, omitted optional input, promised output and fields excluded from responses. It checks the generated schema and the runtime behavior separately rather than treating either artifact as a substitute for the other.

Keeping annotations, generation mode and actual serialization connected makes the contract inspectable without assuming that documentation alone enforces field visibility or that one generated class fits every operation.

## Primary references

[OpenAPI directional annotation semantics](https://spec.openapis.org/oas/v3.2.0.html).

[Pydantic JSON Schema generation modes](https://pydantic.dev/docs/validation/latest/concepts/json_schema/).

[FastAPI separate input/output schemas](https://fastapi.tiangolo.com/how-to/separate-openapi-schemas/).

Related explanations: [Schema conformance](/journal/provider-structured-output-conformance-tests/); [Schema conversion](/journal/llama-cpp-json-schema-gbnf-validation/).
