Skip to content

ADR 0007: OpenAPI 3.1 Canonical Schema Mapping Model

Author: Emir Boyacı • Scope: schema-mappings

AirCommerce bridges external distribution protocols (such as IATA NDC 19.2 and 24.x) with downstream Passenger Service Systems (such as IBS iFlyRes) through a canonical internal ONE Order domain model (OrderRetrieveRequest, Order, Passenger, etc.).

Previously, cross-system schema mappings in the architecture portal (src/content/mappings/) were authored in a bespoke YAML format validated by a custom mapping.schema.json. While effective for rendering documentation tables and Mermaid lineage diagrams, the custom YAML format had critical limitations:

  • No Type System for Code Generation: The custom fields: array listed property paths (internal, ndc, external) without JSON Schema types (string, integer, number, boolean, array, format: date). Consequently, standard code generators (openapi-generator, openapi-typescript, Orval) could not generate Java DTOs or TypeScript interfaces from the portal’s definitions.
  • Flat Dot-Notation Instead of Object Hierarchies: Nested internal properties (such as userInformation.travelAgency.name and bookingChannel.channelType) were written as flat dot-delimited strings rather than structured JSON Schema object trees, preventing generators from emitting clean nested classes.
  • Non-Standard Composition (uses:): Shared types were linked through a proprietary uses: array rather than standard JSON Schema $ref pointers.
  • Duplicate Internal Type Projections: Because shared types were previously split by NDC element (journey.yaml for PaxJourney and origin-dest.yaml for OriginDest) rather than by the canonical internal class (Trip), the same trips property was mounted twice on order-view-rs.yaml, which is invalid in a typed object schema.
  • Multi-Language Code Generation: Enable out-of-the-box generation of strongly-typed Java POJOs/records, TypeScript interfaces, and validation schemas across internal services (service-converter-ndc192, service-converter-ndc24, business-orchestrator-service, iflyres-connector) using standard OpenAPI 3.1 tooling.
  • Single Source of Truth: Keep architectural lineage (NDC paths, iFlyRes paths, transformation semantics, ignore reasons, and ubiquitous language glossary terms) co-located with the canonical schema definitions rather than maintaining parallel files.
  • Modular Authoring Ergonomics: Preserve small, human-readable per-operation (operations/*.yaml) and per-shared-type (types/*.yaml) files with concise vendor extensions.
  • 1-to-Many Projection Support: Allow a single canonical internal class (such as Trip) or property to project onto multiple NDC or external schema targets without duplicating the internal property definition.
  • Option 1: Keep the custom mapping YAML format and maintain a separate OpenAPI repository for code generation.
  • Option 2: Keep the custom mapping YAML format (adding a type attribute) and transpile it into OpenAPI YAML during build.
  • Option 3 (Chosen): Author directly in modular OpenAPI 3.1 / JSON Schema YAML files enriched with x-* vendor extensions, and auto-generate a root openapi.yaml bundle for code generators.

We chose Option 3: authoring directly in modular OpenAPI 3.1 Schema Objects under src/content/mappings/operations/ and src/content/mappings/types/, enriched with structured vendor extensions (x-id, x-internal-type, x-ndc24, x-ndc192, x-external, x-mapping, x-overrides, x-term), and automatically generating src/content/mappings/openapi.yaml during the portal build.

1. Modular Schema Layout & Root Bundle (openapi.yaml)

Section titled “1. Modular Schema Layout & Root Bundle (openapi.yaml)”

Each file in src/content/mappings/types/*.yaml and src/content/mappings/operations/*.yaml is a valid OpenAPI 3.1 / JSON Schema object definition. During astro:config:setup (npm run build / npm run validate), astro-mappings.ts validates all schemas and writes src/content/mappings/openapi.yaml registering every non-template schema under components.schemas keyed by its canonical internal class name (x-internal-type):

openapi: 3.1.0
info:
title: AirCommerce Internal Canonical Schema Model
version: 1.0.0
paths: {}
components:
schemas:
Order:
$ref: './operations/order-view-rs.yaml'
OrderItem:
$ref: './types/order-item.yaml'
OrderRetrieveRequest:
$ref: './operations/order-retrieve-rq.yaml'
Passenger:
$ref: './types/passenger.yaml'
PaxJourney:
$ref: './types/trip.yaml'

Template files (template-passenger.yaml, template-mapping.yaml) are excluded from openapi.yaml so downstream code generators only emit production domain models.

2. Root Schema Metadata & 1-to-Many Target Projections

Section titled “2. Root Schema Metadata & 1-to-Many Target Projections”

Each schema file declares its canonical class name via x-internal-type and its target protocol bindings via x-ndc24, x-ndc192, and x-external. When a single internal class projects onto multiple target structures (such as PaxJourney mapping to both PaxJourney and OriginDest in NDC), x-ndc24, x-ndc192, or x-external accepts either a single object or an array of target descriptors:

src/content/mappings/types/trip.yaml
type: object
title: PaxJourney
x-id: trip
x-internal-type: PaxJourney
x-ndc24:
- version: '24.1'
type: PaxJourney
- version: '24.1'
type: OriginDest
x-ndc192:
- version: '19.2'
type: PaxJourney
- version: '19.2'
type: OriginDest
x-external:
system: iFlyRes
version: N/A
type: flightSegmentGroupID
properties:
paxJourneyID:
type: string
x-ndc24: PaxJourney/PaxJourneyID
x-ndc192: PaxJourney/PaxJourneyID
x-mapping:
transform: constant
note: '`FL` plus a counter'
origin:
type: string
x-ndc24: OriginDest/OriginCode
x-ndc192: OriginDest/OriginCode
x-external: flightSegmentGroupID/firstLeg/boardPoint
x-mapping:
transform: identity

3. Nested Object Properties & Standard $ref Composition

Section titled “3. Nested Object Properties & Standard $ref Composition”

Dot-delimited internal paths (userInformation.travelAgency.name) are represented as standard nested JSON Schema object hierarchies so code generators emit clean inner/sub-models, while the portal’s mapping-cache.ts recursively walks properties: to flatten leaf nodes back into userInformation.travelAgency.name for the UI table and Mermaid diagrams:

properties:
userInformation:
type: object
properties:
travelAgency:
type: object
properties:
name:
type: string
x-ndc24:
path: Party/Sender/TravelAgency/Name
transform: lookup
note: 'copied when travel agency values in use'
x-ndc192:
path: Party/Sender/TravelAgency/Name
transform: lookup
note: 'copied when travel agency values in use'
x-external:
path: bookingChannel/channel
transform: identity

Shared types are composed via standard $ref (inside items: for collections or directly on a property for 1:1 references), with prefix paths declared on the mounting property and operation-specific child overrides declared via x-overrides:

travelers:
type: array
items:
$ref: '../types/passenger.yaml'
x-ndc24: Response/DataLists/PaxList/Pax
x-ndc192: Response/DataLists/PaxList/Pax
x-external: guestDetails
x-overrides:
extra:
x-external:
path: guestId
ignore: '`inventoryId`, `age`, `nameRemark` not written onto `Pax`'

Option 1: Separate Custom Mapping YAML and OpenAPI Repository

Section titled “Option 1: Separate Custom Mapping YAML and OpenAPI Repository”
  • Good: Zero changes required to the existing portal parser.
  • Bad: Immediate schema drift between documentation mappings and production Java/TypeScript models; violates single source of truth.

Option 2: Custom Mapping YAML Transpiled to OpenAPI

Section titled “Option 2: Custom Mapping YAML Transpiled to OpenAPI”
  • Good: Keeps the flat YAML authoring syntax.
  • Bad: Requires maintaining a bespoke schema language and custom transpiler; authors lose standard OpenAPI IDE autocompletion, JSON Schema $ref navigation, and standard linting tools (Spectral, Redocly).

Option 3 (Chosen): Native OpenAPI 3.1 YAML with Vendor Extensions

Section titled “Option 3 (Chosen): Native OpenAPI 3.1 YAML with Vendor Extensions”
  • Good: 100% compliant with OpenAPI 3.1 and JSON Schema tooling out of the box. Directly consumable by openapi-generator (Java Spring/POJOs) and openapi-typescript. Enforces explicit property types and clean object hierarchies while retaining all portal mapping visualization features.
  • Bad: Slightly deeper YAML indentation when modeling multi-level nested objects (type: object -> properties:).
  • Build-Time Schema & Semantic Validation: astro-mappings.ts and mapping-cache.ts validate every OpenAPI mapping file during npm run validate and npm run build, checking JSON Schema types, $ref resolution, cycle detection, NDC version consistency across $ref closures, and ontology term existence (x-term).
  • Generated Meta-Schema (mapping.schema.json): astro-mappings.ts generates an updated JSON Schema for IDE YAML language-server validation of OpenAPI properties and x-* vendor extensions.
  • Automated Unit Tests: Vitest suites (tests/mappings.test.ts) verify $ref expansion, nested property flattening, x-overrides precedence, coverage calculation, and root openapi.yaml generation.
  • Portal Migration: All shared types in src/content/mappings/types/*.yaml and operations in src/content/mappings/operations/*.yaml are migrated to OpenAPI 3.1 Schema Objects, and journey.yaml + origin-dest.yaml are consolidated into types/trip.yaml (Trip).
  • Downstream Code Generation: Internal services can point openapi-generator-maven-plugin or openapi-typescript directly at src/content/mappings/openapi.yaml to generate canonical DTOs.