openapi: 3.0.3
info:
  title: FHIR Validation Service API
  description: >-
    A Vert.x-based FHIR validation service with PostgreSQL. Every error response is an RFC 9457 problem document
    (application/problem+json). Every response carries an X-Request-Id header.
  version: 1.0.0

servers:
  - url: http://localhost:8880
    description: Local development server (replace with your server)

paths:
  /health:
    get:
      operationId: healthApiHealth
      summary: Detailed health report
      description: Database connectivity plus the readiness report.
      responses:
        '200':
          description: Service is healthy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HealthResponse'
        '503':
          description: Service is unhealthy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HealthResponse'

  /health/liveness:
    get:
      operationId: healthApiLiveness
      summary: Liveness probe (process only; never depends on dependencies)
      responses:
        '200':
          description: Service is live
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum: [UP]
                  timestamp:
                    type: integer
                    format: int64

  /health/readiness:
    get:
      operationId: healthApiReadiness
      summary: Readiness probe
      description: >-
        200 when this instance can serve traffic: database reachable, a usable validator for every enabled FHIR
        version (none out of date), and not draining. Otherwise 503 with the reasons.
      responses:
        '200':
          description: Ready
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadinessResponse'
        '503':
          description: Not ready
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadinessResponse'

  /metrics:
    get:
      operationId: metricsApiScrape
      summary: Prometheus metrics (text exposition format)
      responses:
        '200':
          description: Metrics
          content:
            text/plain:
              schema:
                type: string

  /{version}/validate:
    post:
      operationId: validationApiValidate
      security:
        - apiKey: []
      summary: Validate a FHIR resource
      description: >-
        Content negotiation: Accept absent, */* or application/json returns the ValidationResponse JSON shape;
        application/fhir+json, application/fhir+xml and application/xml return a FHIR OperationOutcome.
        A completed validation answers 200 whether the resource is valid or not; the X-Validation-Context header
        names the validator context used (the IG package name#version, or `base`). The resource is validated against
        exactly one IG package (the `ig` parameter), its dependencies and the core specification, or against the
        core specification alone when `ig` is absent. Every 4xx is problem JSON, whatever Accept asks for:
        invalid-resource (body is not FHIR), invalid-request (e.g. a malformed ig, profile limits, an ig package for
        another FHIR version, or an ig package version that is stored but not included for this FHIR version:
        "IG package name#version is not included for R4; include it first"), package-not-found (404: the ig package is
        not stored) and unknown-profile (a requested profile is not available; see UnknownProfileProblem). 503 covers
        not-ready (an included context still being built or rebuilt), overloaded and insufficient-capacity.
        Included contexts only: validation never builds a context; name an IG version that was included with
        POST /{version}/validator. Terminology: a context whose terminology mode is `server` or `ecosystem`
        checks codes that can't be decided from its packages with an allowlisted terminology server; a code that
        could not be checked (server unavailable, time budget used up, no permitted server) is reported as a warning,
        never an error, and the answer is still 200.
        Organisation ownership: only IG packages and contexts the caller's organisation owns, or that are
        shareable, can be used; an IG package the caller may not use is answered exactly like one that is not stored
        (404), and a dependency the caller may not use gives 424 without naming it. 403 forbidden means the API key's
        organisation is deactivated. X-Validation-Context-Owner and X-Validation-Context-Shareable report the owner
        (short name) and sharing of the context used.
        Terminology per request: a context's terminology setting is its default; `tx` and `txMode` choose
        another setting for one request without a rebuild. Effective setting, with D the context's setting (`none`
        for the base context and a context without one): no parameters = D; only `tx` = D's mode if `server` or
        `ecosystem`, else `server`, with server `tx`; `txMode=server` = `tx`, else D's server (400 invalid-request if
        neither exists); `txMode=ecosystem` = the registry's routing with `tx`, else D's server if D is `ecosystem`, as
        the default server; `txMode=none` = no terminology server (400 invalid-request together with `tx`). A server
        named in `tx` must be allowed for this FHIR version: 400 tx-server-not-registered, or 503
        tx-registry-unavailable while no registry list was ever obtained; no call is made to a server that is not
        allowed. These checks run after the `ig` resolution and access checks, and before not-ready. Malformed
        `tx`/`txMode` (repeated, empty, an unknown mode, not an http(s) base URL, over 512 characters) is 400
        invalid-request with a fixed text that never contains the address. The 200 response reports the setting used
        in X-Tx-Mode, X-Tx-Server and X-Tx-Source; the body is unchanged.
        Regex checks: the validation engine stops any single regex check after 500 ms. When a result reports such a
        timeout, the service validates the resource again before answering: once at once, and if the timeout is
        still there, once more with no other validation running on the instance (for at most one second; a longer
        re-check goes on beside them). The response is the complete result
        of the first attempt without a regex timeout. When the timeout persists (the input makes the regex run too
        long, the re-checks would not fit in the request's time, or the instance is too busy to run the quiet
        re-check within one second), the response is the last attempt's result as the engine reports it: the timeout
        stays an issue with the engine's severity, the status is 200 and the headers are those of any validation. A
        re-check never changes the status code and is never answered with 503.
        Rate limits (spec 014): requests are limited per API key and per organisation, as validation requests per
        rolling minute (operator configured). Responses to a limited key carry RateLimit-Limit, RateLimit-Remaining and
        RateLimit-Reset (also on 4xx and 5xx responses); above the cap the answer is 429 rate-limited with Retry-After.
        Keys of the system organisation, and every request while access control is disabled, are not limited.
      parameters:
        - name: version
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/FhirVersion'
        - name: ig
          in: query
          required: false
          description: >-
            The one IG package to validate against: `name#version`, `name#latest` or `name`. URL-encode `#` as `%23`;
            an unencoded `#` is cut off by the client and the bare name then resolves to the highest stored version.
            Without a version (or with `latest`) the highest included version is used; the response reports the
            concrete version. Only IG versions included for this FHIR version can be named: a stored version
            that isn't included is answered 400 invalid-request. Absent: the core specification only. One value; at most 256 characters. Only packages your organisation owns or
            that are shareable can be named. The trial validator key (and every caller in public mode) can name shareable packages only. Without a version,
            the highest version you may use is chosen. The version must be exact (or `latest`, or omitted): a version
            series such as `name#1.2.x` is rejected with 400 invalid-request; use the concrete version reported
            when the IG was included (POST /{version}/validator).
            Two IGs: `name#version|name#version`, both with exact versions (URL-encode `|` as %7C). The
            context included with exactly these two IGs is used, looked up by its key first and then by the
            reversed order; neither included is 400 invalid-request. A single exact `name#version` uses the single-IG
            context when one is included, otherwise the two-IG context whose first IG it is. A name without a version,
            or `latest`, considers single-IG contexts only. X-Validation-Context always reports the context's key.
          schema:
            type: string
            maxLength: 256
        - name: profile
          in: query
          required: false
          description: >-
            Comma-separated canonical URLs of profiles to validate against, in addition to meta.profile. Each URL must
            be defined by the chosen `ig` package, its dependencies or the core specification (the core specification
            only when `ig` is absent), and is matched exactly against `url` or `url|version`. Profiles are never
            downloaded. At most 10 distinct profiles per request, each at most 1024 characters (otherwise 400
            invalid-request). If any URL cannot be resolved the request fails with 400 unknown-profile (listing
            `unresolvedProfiles`) and nothing is validated.
          schema:
            type: string
        - name: tx
          in: query
          required: false
          description: >-
            Terminology server for this request only: an http(s) base URL, at most 512 characters, without query,
            fragment or user info. It must be on the official HL7 terminology registry's allowlist for this FHIR
            version (otherwise 400 tx-server-not-registered, or 503 tx-registry-unavailable while no registry list was
            ever obtained). No call is made to a server that is not allowed. Not allowed with txMode=none. Overrides
            the context's own server; the context's setting stays the default for other requests. The resource itself
            is never sent to the server. Checked in code (length, form, a single value), so every refusal carries a
            fixed text.
          schema:
            type: string
        - name: txMode
          in: query
          required: false
          description: >-
            Terminology mode for this request only: `none` (no terminology server), `server` (one server: `tx`, or the
            context's server) or `ecosystem` (route each code system through the HL7 registry; `tx`, if given,
            replaces the registry's default server). Exact lower-case values. Absent: the context's mode, or `server`
            when only `tx` is given. Checked in code, so an unknown value is 400 invalid-request with a fixed text.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
          application/fhir+json:
            schema:
              type: object
          application/xml:
            schema:
              type: string
          application/fhir+xml:
            schema:
              type: string
          text/xml:
            schema:
              type: string
      responses:
        '200':
          description: Validation completed (see `valid` / the OperationOutcome issues)
          headers:
            X-Validation-Context:
              description: The IG package (name#version) the result came from, or `base` for the core-only context
              schema:
                type: string
            X-Validation-Context-Owner:
              description: Short name of the organisation owning the validator context (the system organisation for `base`)
              schema:
                type: string
            X-Validation-Context-Shareable:
              description: Whether the validator context is shareable (`true`/`false`)
              schema:
                type: string
                enum: ['true', 'false']
            X-Tx-Mode:
              description: Terminology mode used for this validation
              schema:
                type: string
                enum: [none, server, ecosystem]
            X-Tx-Server:
              description: >-
                Normalised base URL of the terminology server used (mode server). For mode ecosystem, the `tx` value
                if given, else the context's server, else absent (the registry's own default server is not reported).
                Absent for mode none.
              schema:
                type: string
            X-Tx-Source:
              description: Where the setting came from, `request` (tx or txMode given) or `context` (the default)
              schema:
                type: string
                enum: [request, context]
            RateLimit-Limit:
              $ref: '#/components/headers/RateLimitLimit'
            RateLimit-Remaining:
              $ref: '#/components/headers/RateLimitRemaining'
            RateLimit-Reset:
              $ref: '#/components/headers/RateLimitReset'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationResponse'
            application/fhir+json:
              schema:
                $ref: '#/components/schemas/OperationOutcome'
            application/fhir+xml:
              schema:
                type: string
                description: FHIR OperationOutcome (XML)
            application/xml:
              schema:
                type: string
                description: FHIR OperationOutcome (XML)
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '406':
          $ref: '#/components/responses/Problem'
        '413':
          $ref: '#/components/responses/Problem'
        '415':
          $ref: '#/components/responses/Problem'
        '424':
          description: >-
            dependency-not-found: a dependency of the ig package exists but is not available to the caller (not
            named): "A dependency of the requested IG package is not available."
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

  /{version}/validator:
    post:
      operationId: validatorApiIncludeIg
      security:
        - apiKey: []
      summary: Pre-build and keep a validator context for a stored Implementation Guide version
      description: >-
        Adds a pinned validator context for igPackageId#igPackageVersion on every instance; other versions of the
        same package stay included and usable through ?ig=. Including a version that is already included changes
        nothing. igPackageVersion defaults to latest (the highest stored version); nothing is downloaded. The
        response confirms the committed configuration; other instances apply it within the propagation window. A
        context that would not fit in this instance's heap is refused with 413 package-too-large before it is
        committed. A package whose declared FHIR versions don't include this version is refused with 400
        invalid-request. Organisation ownership: the new context is owned by the caller's organisation and is
        shareable unless `shareable` is false; a package (or dependency) the caller may not use is answered 404. When
        the version is already included (possibly by another organisation) nothing changes and the response reports
        the existing owner and sharing. A dependency the caller may not use is answered 424 dependency-not-found
        without naming it. Version series: igPackageVersion `1.2.x` / `1.x.x` includes the highest matching
        stored version; 404 package-not-found when none is stored, and the highest match is never swapped for a lower
        one (a highest match for another FHIR version is 400). Terminology: `terminology` sets the new
        context's terminology mode; a server must be listed by the official HL7 terminology registry
        (https://ecosystem.hl7.org/tx-reg) for this FHIR version (400 tx-server-not-registered otherwise), or, while
        the service has never obtained the registry's list, be on the built-in fallback list (503
        tx-registry-unavailable otherwise). The setting is the context's default; a validation request can override
        it with `tx`/`txMode`. For an already included context `terminology` is ignored with a warning; change it
        with PATCH (no rebuild). Enabled FHIR versions: a FHIR version that is supported but not
        enabled on this deployment (FV_ENABLED_FHIR_VERSIONS) is refused with 422 fhir-version-disabled; this also
        applies when an inactive context for it is already stored. Public mode: while access control is
        disabled (FV_GLOBAL_DISABLED_ACL_SECURITY), `shareable: false` is ignored and the context is stored as
        shareable, with a warning in `warnings`.
        Two IGs: send `igPackages` with two entries instead of `igPackageId`/`igPackageVersion` (exactly one
        of the two forms; one entry behaves like `igPackageId`). One context is built from both IGs, every dependency
        of each and the core specification. Its key is `A#a|B#b` in the order given (at most 256 characters); it is
        also found under the aliases `B#b|A#a` and, for a single-IG request with an exact version when no single-IG
        context of that version is included, `A#a`. Including the same two IG versions again, in either order,
        changes nothing and reports the existing context. Every check above applies to each IG and each dependency.
        When the two IGs need different versions of the same package the include is refused with 400
        dependency-conflict (extension `conflicts`), except packages whose name starts with `hl7.terminology` or
        `hl7.fhir.uv.extensions`: the highest version is used and named in `warnings` (dependencies only; an IG
        named in igPackages is never replaced by another version, so that case is a conflict). A conflict involving a
        version the caller may not use is answered 424 without naming it. 409 alias-conflict: another two-IG context
        for this FHIR version already has the same first IG. `shareable: false` needs ownership of both IG packages.
      parameters:
        - name: version
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/FhirVersion'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: >-
                Exactly one of `igPackageId` (one IG) or `igPackages` (one or two IGs) is required (400
                invalid-request otherwise).
              properties:
                igPackages:
                  type: array
                  minItems: 1
                  maxItems: 2
                  description: >-
                    One or two IG packages for one context. Two entries may not name the same igPackageId.
                  items:
                    type: object
                    required:
                      - igPackageId
                    properties:
                      igPackageId:
                        type: string
                      igPackageVersion:
                        type: string
                        default: latest
                        description: Same values as the top-level igPackageVersion.
                igPackageId:
                  type: string
                igPackageVersion:
                  type: string
                  default: latest
                  description: >-
                    An exact version, `latest` (the highest stored version), or a version series `N.x`, `N.x.x` or
                    `N.N.x` (for example `1.2.x`): the highest matching stored version your organisation may
                    use. No registry is contacted. The context is pinned to that concrete version; storing a newer
                    matching version later does not change it. Any other value containing an `x` part is rejected
                    with 400 invalid-request.
                shareable:
                  type: boolean
                  default: true
                  description: >-
                    Sharing of a newly included context. false is allowed only when your organisation owns the IG
                    package (or you are the system organisation). Ignored, with a warning, when the context is
                    already included.
                terminology:
                  $ref: '#/components/schemas/TerminologySettings'
      responses:
        '200':
          description: IG included
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IncludeResponse'
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '413':
          $ref: '#/components/responses/Problem'
        '409':
          description: >-
            alias-conflict: another two-IG context for this FHIR version already has the same first IG
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '422':
          $ref: '#/components/responses/FhirVersionDisabled'
        '424':
          description: >-
            dependency-not-found: a dependency of the IG package is not available to the caller; the
            dependency is not named
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'
    delete:
      operationId: validatorApiExcludeIg
      security:
        - apiKey: []
      summary: Stop pre-building an included Implementation Guide version for a FHIR version
      description: >-
        Removes one name#version from the included set and propagates to every instance. The package stays stored.
        Validation requests naming it are refused with 400 invalid-request until it is included again. Its
        terminology setting is deleted with the context. Administrative: requires an ADMIN
        key. 404 package-not-found when that version is not included, or when the caller's organisation doesn't own
        its context and isn't the system organisation. Enabled FHIR versions: also works for a
        context that is inactive because its FHIR version is not enabled (FV_ENABLED_FHIR_VERSIONS); the change is
        stored, nothing is built, and it applies when the version is enabled again. Public mode: while access
        control is disabled, `shareable: false` is ignored (the context stays or becomes shareable) with a warning in
        `warnings`; `shareable: true` works as before.
      parameters:
        - name: version
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/FhirVersion'
        - name: ig
          in: query
          required: true
          description: >-
            The exact IG package version to exclude, name#version (URL-encode `#` as %23); no `latest`. A two-IG
            context: its key `A#a|B#b` or `B#b|A#a` (URL-encode `|` as %7C); a single name#version never
            addresses a two-IG context.
          schema:
            type: string
            maxLength: 256
      responses:
        '200':
          description: IG version excluded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExcludeResponse'
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/Problem'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'
    patch:
      operationId: validatorApiChangeIncludedIg
      security:
        - apiKey: []
      summary: Change sharing, ownership or terminology of an included validator context
      description: >-
        Administrative. The context's owner or the system organisation may change `shareable`; only the
        system organisation may transfer ownership (`owner`) to another active organisation. Checks run in this
        order: 404 (not included, or the caller is neither the owner nor the system organisation), 403 (a transfer by
        a caller that isn't the system organisation), 400 (body, unknown or inactive target organisation, or a
        private context of an IG package owned by another organisation, or a malformed terminology setting), then
        400 tx-server-not-registered and 503 tx-registry-unavailable for the terminology server. Access changes take
        effect on every instance within the propagation window without a rebuild. Changing `terminology` takes
        effect on the next validation on every instance within the same window; the context is not rebuilt.
        It is the context's default: a validation request can override it with `tx`/`txMode`. Setting the same
        terminology again changes nothing. Enabled FHIR versions: also works for a context that is inactive
        because its FHIR version is not enabled (FV_ENABLED_FHIR_VERSIONS); the change is stored, nothing is built,
        and it applies when the version is enabled again.
      parameters:
        - name: version
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/FhirVersion'
        - name: ig
          in: query
          required: true
          description: >-
            The exact included IG package version, name#version (URL-encode `#` as %23); no `latest`. A two-IG
            context: its key `A#a|B#b` or `B#b|A#a` (URL-encode `|` as %7C); a single name#version never
            addresses a two-IG context. `shareable: false` on a two-IG context needs ownership of both IG packages.
          schema:
            type: string
            maxLength: 256
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccessChangeRequest'
      responses:
        '200':
          description: Access changed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IncludeAccessResponse'
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

  /igs/upload:
    post:
      operationId: igPackageApiUploadIg
      security:
        - apiKey: []
      summary: Upload and store an Implementation Guide package
      description: >-
        The stored package is owned by the caller's organisation. Uploading a name#version another
        organisation stored gives 409 conflict, unless the caller is the system organisation; a replacement keeps the
        stored owner and sharing. Public mode: while access control is disabled (FV_GLOBAL_DISABLED_ACL_SECURITY),
        `shareable=false` is ignored and the package is stored as shareable, with a warning in `warnings`.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
              properties:
                file:
                  type: string
                  format: binary
                  description: The IG package archive (.tgz). Size limit is FV_HTTP_MAX_BODY_MB.
                shareable:
                  type: string
                  enum: ['true', 'false']
                  default: 'true'
                  description: >-
                    Sharing of the stored package. Ignored when the version is already stored: its owner and
                    sharing are kept.
            encoding:
              file:
                contentType: application/octet-stream, application/gzip, application/x-gzip, application/x-tar, application/x-compressed-tar
      responses:
        '200':
          description: IG package stored
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IgRegistrationResponse'
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Problem'
        '413':
          $ref: '#/components/responses/Problem'
        '422':
          $ref: '#/components/responses/Problem'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

  /igs/register:
    post:
      operationId: igPackageApiRegisterIg
      security:
        - apiKey: []
      summary: Fetch and store an Implementation Guide package (from a registry or an approved URL)
      description: >-
        With `name` and no version (or `latest`), the configured package registries are asked for the highest
        released version: if that version is already stored it is returned without downloading it again, otherwise
        it is downloaded and stored (with its dependencies when includeDependency is true). If no registry can be
        consulted or none lists the package, the highest stored version is returned with a warning; 404
        package-not-found when nothing is stored. `downloaded` says whether the archive was fetched in this call.
        Organisation ownership: every package newly stored by the call, downloaded dependencies included, is
        owned by the caller's organisation with `shareable` from the request (default true; the package licence is
        not used; in public mode `shareable: false` is ignored with a warning in `warnings`). A version that is already stored keeps its owner and sharing, and is answered 404 when the caller
        may not use it. A downloadUrl archive whose name#version another organisation stored gives 409 conflict.
        Version series: `1.2.x` / `1.x.x` resolve to the highest matching registry release, then behave
        exactly like a registration of that version (stored → returned without download; new → downloaded and
        stored). The response's `version` is the concrete version and `requestedVersion` the value sent.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                downloadUrl:
                  type: string
                  format: uri
                name:
                  type: string
                version:
                  type: string
                  default: latest
                  maxLength: 64
                  description: >-
                    An exact version, `latest`, or a version series: `N.x`, `N.x.x` or `N.N.x` (for example `1.2.x`;
                    `x` or `X`). A series is resolved to the highest matching version listed by the configured package
                    registries (a release before a pre-release). If no registry can be consulted or none lists a
                    matching version, the highest matching stored version the caller may use is returned with a
                    warning; 404 package-not-found when there is none. Any other value containing an `x` part is
                    rejected with 400 invalid-request. With `latest`, the fallback to stored versions also uses only
                    versions the caller may use. Dependencies declared with a version series or `latest` are
                    resolved the same way.
                includeDependency:
                  type: boolean
                  default: true
                shareable:
                  type: boolean
                  default: true
                  description: Sharing of every package newly stored by this call
      responses:
        '200':
          description: IG package stored
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IgRegistrationResponse'
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '409':
          $ref: '#/components/responses/Problem'
        '413':
          $ref: '#/components/responses/Problem'
        '422':
          $ref: '#/components/responses/Problem'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

  /igs/{name}/{version}:
    patch:
      operationId: igPackageApiChangeAccess
      security:
        - apiKey: []
      summary: Change sharing or transfer ownership of a stored IG package
      description: >-
        Administrative. The package's owner or the system organisation may change `shareable`; only the
        system organisation may transfer ownership (`owner`) to another active organisation. Checks run in this
        order: 404 (not stored, or the caller is neither the owner nor the system organisation), 403 (a transfer by a
        caller that isn't the system organisation), 400 (body, unknown or inactive target organisation). The change
        takes effect on every instance within the propagation window; no validator context is rebuilt. Public mode:
        while access control is disabled, `shareable: false` is ignored (the package stays or becomes
        shareable) and the response carries a `warnings` entry; `shareable: true` works as before.
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
        - name: version
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccessChangeRequest'
      responses:
        '200':
          description: Access changed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IgAccessResponse'
        '400':
          $ref: '#/components/responses/Problem'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

  /igs/{name}/{version}/dependencies:
    get:
      operationId: igPackageApiGetDependenciesGraph
      security:
        - apiKey: []
      summary: Declared dependencies of a stored IG package
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
        - name: version
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Dependencies retrieved
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                  version:
                    type: string
                  dependencies:
                    type: array
                    items:
                      type: string
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

  /igs/{name}/{version}/conformance:
    get:
      operationId: igPackageApiGenerateConformanceReport
      security:
        - apiKey: []
      deprecated: true
      summary: Files of a stored IG package (deprecated; not a conformance report)
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
        - name: version
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Package file listing
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                  version:
                    type: string
                  files:
                    type: array
                    items:
                      type: string
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/PackageNotFound'
        '500':
          $ref: '#/components/responses/Problem'
        '503':
          $ref: '#/components/responses/Problem'

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        API key as `Authorization: Bearer <key>`. Validation and the package read operations require a VALIDATE or
        ADMIN key. Administrative operations (upload/register IG,
        POST/PATCH/DELETE /{version}/validator, and the PATCH operations that change sharing or ownership) require an
        ADMIN key and, when the operator configures an admin network allowlist (FV_AUTH_ADMIN_CIDRS), must come from an
        allowed network. Every key belongs to an organisation; a key of a deactivated organisation gets 403. Keys may
        expire; an expired key gets 401. Enforced by the service before contract validation (see
        specs/008-api-key-hardening/contracts/http-api.md). An operator can turn access control off for a
        whole deployment (FV_GLOBAL_DISABLED_ACL_SECURITY). Then no operation needs a key and the Authorization
        header is ignored. Each request runs as a fixed caller: validation and the package reads as the
        `trial validator` key, administrative operations as the `system administrator` key. The admin network
        allowlist still applies. GET /health
        reports `security.aclSecurity`. In this mode packages and validator contexts are always stored as shareable:
        `shareable: false` is ignored with a warning.

  headers:
    RetryAfter:
      description: Seconds to wait before a retry of this request can be admitted.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: >-
        The per-minute validation cap that currently leaves the least allowance for this API key (its own cap or its
        organisation's). Not sent for keys that are not rate limited.
      schema:
        type: integer
        minimum: 1
    RateLimitRemaining:
      description: >-
        Validation requests still allowed in the current rolling 60-second window, after this request. Approximate
        when the service runs as several instances.
      schema:
        type: integer
        minimum: 0
    RateLimitReset:
      description: Seconds until the allowance next grows.
      schema:
        type: integer
        minimum: 0
  responses:
    TooManyRequests:
      description: >-
        rate-limited: the API key's or its organisation's per-minute validation cap was reached (spec 014). Nothing
        was validated and the request does not count towards any cap. Retry after the Retry-After seconds.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        RateLimit-Remaining:
          $ref: '#/components/headers/RateLimitRemaining'
        RateLimit-Reset:
          $ref: '#/components/headers/RateLimitReset'
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: rate-limited
            title: Too many requests
            status: 429
            detail: "This API key's rate limit of 30 validation requests per minute was reached; retry after 12 s"
            scope: key
            limit: 30
            retryAfterSeconds: 12
            correlationId: 3f0c6f0e-8c1e-4b7a-9d55-0d2f6c1b9a10
    Unauthorized:
      description: >-
        unauthorized: no valid API key was sent (missing, malformed, unknown, revoked or expired). The response doesn't
        say which (WWW-Authenticate: Bearer).
      headers:
        WWW-Authenticate:
          schema:
            type: string
            example: Bearer
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    Problem:
      description: Error (RFC 9457 problem details)
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    PackageNotFound:
      description: >-
        package-not-found. Also returned when the package or context is owned by another organisation and isn't
        shareable; the two cases can't be told apart.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    FhirVersionDisabled:
      description: >-
        fhir-version-disabled: the FHIR version is supported by this release but not enabled on this
        deployment (FV_ENABLED_FHIR_VERSIONS). Nothing is stored or built.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: fhir-version-disabled
            status: 422
            detail: "IG validator contexts for R5 can't be added: this service serves R4 only (FV_ENABLED_FHIR_VERSIONS)"
    Forbidden:
      description: >-
        forbidden: the API key's role doesn't allow this operation, the key's organisation is deactivated,
        (transfers) the caller isn't a system organisation administrator, or (administrative operations) the client
        address is outside the configured admin networks (FV_AUTH_ADMIN_CIDRS).
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'

  schemas:
    FhirVersion:
      type: string
      pattern: '^([Ss][Tt][Uu]3|[Rr]4[Bb]?|[Rr]5)$'
      description: >-
        STU3, R4, R4B or R5 (case-insensitive). A deployment may serve fewer (FV_ENABLED_FHIR_VERSIONS);
        GET /health lists the served versions.

    ReadinessResponse:
      type: object
      properties:
        status:
          type: string
          enum: [UP, DOWN]
        timestamp:
          type: integer
          format: int64
        catalogRevision:
          type: integer
          format: int64
          description: The package catalog revision this instance has loaded
        versions:
          type: object
          description: >-
            Per FHIR version: appliedRevision, latestRevision, `base` (the core-only context: state, packages,
            packageBytes) and `contexts` (every IG context on this instance: key name#version or, for a two-IG
            context, A#a|B#b, igPackages (the context's IGs, name#version, in key order), aliases, kind pinned,
            state ACTIVE|BUILDING|STALE|ABSENT, appliedRevision, packages, packageBytes, lastUsed, reason, and
            terminology {mode, server}).
            `contexts` lists only contexts that are shareable and whose packages are all shareable; the others
            are summarised in `privateContexts` {count, states {ACTIVE, BUILDING, STALE, ABSENT}}. Owners are never
            listed. Readiness counts the base and pinned contexts only (there are no on-demand contexts).
        reasons:
          type: array
          items:
            type: string

    Problem:
      type: object
      description: RFC 9457 problem details (media type application/problem+json)
      required: [type, title, status, correlationId]
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
          description: Curated, safe text. Never exception messages, class names or stack traces
        correlationId:
          type: string
          description: Same as the X-Request-Id response header
        issues:
          type: array
          description: Present only for type invalid-resource
          items:
            $ref: '#/components/schemas/ValidationMessage'
        unresolvedProfiles:
          type: array
          description: Present only for type unknown-profile (see UnknownProfileProblem)
          items:
            type: string
        scope:
          type: string
          enum: [key, organisation]
          description: Present only for type rate-limited (spec 014) - which cap was reached
        limit:
          type: integer
          description: Present only for type rate-limited (spec 014) - the per-minute cap that was reached
        retryAfterSeconds:
          type: integer
          description: Present only for type rate-limited (spec 014) - the same value as the Retry-After header

    UnknownProfileProblem:
      description: >-
        400 from /{version}/validate when a requested profile is not defined by the chosen ig package, its
        dependencies or the core specification (the core specification alone when ig is absent). Nothing was
        validated.
      allOf:
        - $ref: '#/components/schemas/Problem'
        - type: object
          required: [unresolvedProfiles]
          properties:
            unresolvedProfiles:
              type: array
              minItems: 1
              description: Every requested entry that did not resolve, after trimming and de-duplication, in request order
              items:
                type: string

    HealthResponse:
      type: object
      properties:
        status:
          type: string
          enum: [UP, DOWN]
        timestamp:
          type: integer
          format: int64
        postgres:
          type: object
          properties:
            status:
              type: string
              enum: [UP, DOWN]
            responseTime:
              type: integer
              format: int64
            error:
              type: string
        readiness:
          $ref: '#/components/schemas/ReadinessResponse'
        terminology:
          type: object
          description: >-
            Terminology allowlist state. Readiness does not depend on it.
          properties:
            registry:
              type: string
              description: The official HL7 terminology registry (fixed)
            allowlist:
              type: object
              description: Per FHIR version
              additionalProperties:
                type: object
                properties:
                  source:
                    type: string
                    enum: [registry, stored-registry, built-in]
                  fetchedAt:
                    type: string
                    nullable: true
                  registryLastUpdate:
                    type: string
                    nullable: true
                  servers:
                    type: integer
                  reason:
                    type: string
        fhirVersions:
          type: object
          description: FHIR versions this instance serves, and stored validator contexts that are inactive.
          properties:
            served:
              type: array
              items:
                $ref: '#/components/schemas/FhirVersion'
            inactiveContexts:
              type: object
              properties:
                count:
                  type: integer
                  description: All inactive contexts.
                private:
                  type: integer
                  description: >-
                    Inactive contexts that are private (the context or its IG package isn't shareable). They are counted
                    only, never named, on this unauthenticated endpoint.
                items:
                  type: array
                  maxItems: 100
                  description: >-
                    The first 100 shareable inactive contexts, ordered by FHIR version then package. Private ones are
                    not listed.
                  items:
                    type: object
                    properties:
                      fhirVersion:
                        type: string
                      igPackage:
                        type: string
                        description: name#version, or A#a|B#b for a two-IG context
                      igPackages:
                        type: array
                        description: The context's IGs (name#version) in key order
                        items:
                          type: string
                      aliases:
                        type: array
                        description: Other values that find this context; empty for a single-IG context
                        items:
                          type: string
                      owner:
                        type: string
                        description: The owning organisation's short name
                      reason:
                        type: string
                        enum: [fhir-version-disabled]
        security:
          type: object
          description: Access control state.
          properties:
            aclSecurity:
              type: string
              enum: [enabled, disabled]

    ValidationMessage:
      type: object
      properties:
        severity:
          type: string
          enum: [FATAL, ERROR, WARNING, INFORMATION]
        location:
          type: string
        message:
          type: string

    ValidationResponse:
      type: object
      properties:
        valid:
          type: boolean
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ValidationMessage'
        fhirVersion:
          type: string
        appliedProfiles:
          type: array
          description: >-
            Profiles that were resolved and applied: the requested profiles in request order, then resolvable
            meta.profile entries. Each appears once; an unresolved URL is never listed.
          items:
            type: string
        igPackage:
          type: string
          nullable: true
          description: The concrete IG package (name#version) the result came from; null when the base context was used.
        igOwner:
          type: string
          description: Short name of the organisation owning the validator context (the system organisation for base)
        igShareable:
          type: boolean
          description: Whether the validator context is shareable (true for base)

    OperationOutcome:
      type: object
      description: FHIR OperationOutcome resource
      properties:
        resourceType:
          type: string
          enum: [OperationOutcome]

    IncludeResponse:
      type: object
      properties:
        status:
          type: string
          enum: [success]
        fhirVersion:
          type: string
        key:
          type: object
          description: The validator context this include pins
          properties:
            fhirVersion:
              type: string
            igPackage:
              type: string
              description: concrete name#version, or A#a|B#b for a two-IG context
        igPackages:
          type: array
          description: The context's IGs with concrete versions, in key order
          items:
            type: object
            properties:
              igPackageId:
                type: string
              igPackageVersion:
                type: string
              requestedVersion:
                type: string
                description: Present for a two-IG include; the value the request gave for this entry
        aliases:
          type: array
          description: >-
            Other values that find this context: `B#b|A#a` and `A#a` for a two-IG context, empty otherwise
          items:
            type: string
        requestedVersion:
          type: string
          description: >-
            The igPackageVersion value of the request (latest, an exact version or a version series); absent for a
            two-IG include (see igPackages)
        revision:
          type: integer
          format: int64
        included:
          type: array
          items:
            type: string
        resolved:
          type: array
          items:
            type: string
        terminology:
          $ref: '#/components/schemas/TerminologySettings'
        owner:
          type: string
          description: Short name of the organisation owning the context (may be another organisation when it was already included)
        shareable:
          type: boolean
        warnings:
          type: array
          items:
            type: string

    ExcludeResponse:
      type: object
      properties:
        status:
          type: string
          enum: [success]
        fhirVersion:
          type: string
        revision:
          type: integer
          format: int64
        excluded:
          type: string
        included:
          type: array
          items:
            type: string
        warnings:
          type: array
          items:
            type: string

    IgRegistrationResponse:
      type: object
      properties:
        status:
          type: string
          enum: [success]
        name:
          type: string
        version:
          type: string
          description: The concrete version stored or returned
        requestedVersion:
          type: string
          description: >-
            The version value of the request (latest, an exact version or a version series). Absent for
            downloadUrl and upload registrations, which take the version from the archive.
        downloaded:
          type: boolean
          description: True when the archive was fetched in this call
        owner:
          type: string
          description: Short name of the organisation owning the stored package
        shareable:
          type: boolean
          description: The stored package's sharing; unchanged when the version was already stored
        warnings:
          type: array
          items:
            type: string

    OwnershipFields:
      type: object
      properties:
        owner:
          type: string
          description: Short name of the owning organisation.
        shareable:
          type: boolean
          description: True when every caller may use it; false when only the owner (and the system organisation) may.

    AccessChangeRequest:
      type: object
      minProperties: 1
      additionalProperties: false
      properties:
        terminology:
          $ref: '#/components/schemas/TerminologySettings'
        shareable:
          type: boolean
        owner:
          type: string
          pattern: '^[A-Za-z0-9_-]{2,32}$'
          description: >-
            Transfer to this organisation (short name). System organisation administrators only; the target must exist
            and be active.

    IncludeAccessResponse:
      allOf:
        - $ref: '#/components/schemas/OwnershipFields'
        - type: object
          properties:
            status:
              type: string
              enum: [success]
            fhirVersion:
              type: string
            igPackage:
              type: string
            revision:
              type: integer
              format: int64
            terminology:
              $ref: '#/components/schemas/TerminologySettings'
            warnings:
              type: array
              items:
                type: string

    TerminologySettings:
      type: object
      additionalProperties: false
      required: [mode]
      description: >-
        Terminology setting of an included validator context. `none`: codes are checked only against the
        context's packages and built-in code systems, with no outbound request. `server`: codes that can't be decided
        locally are checked with `server`. `ecosystem`: each code system is routed to the server the official HL7
        terminology registry names for it; `server`, when set, replaces the registry's default server (tx.fhir.org).
        Servers must be open servers listed by https://ecosystem.hl7.org/tx-reg for the FHIR version. The registry
        lists none for STU3 and R4B.
      properties:
        mode:
          type: string
          enum: [none, server, ecosystem]
        server:
          type: string
          maxLength: 512
          description: Base URL of the terminology server, exactly as the registry lists it (required for `server`; not allowed for `none`)

    IgAccessResponse:
      allOf:
        - $ref: '#/components/schemas/OwnershipFields'
        - type: object
          properties:
            status:
              type: string
              enum: [success]
            name:
              type: string
            version:
              type: string
            warnings:
              type: array
              items:
                type: string
              description: >-
                Present when the request's `shareable: false` was ignored because access control is disabled.
