Skip to content

Fast Healthcare Interoperability Resources (FHIR) R4 or R5. #11

Closed

Description

@kinlane

We should create a ruleset for governing this standard.

Activity

  1. kinlane commented on Aug 17, 2026

    @kinlane
    ContributorAuthor

    Done — api-commons/spectral-fhir-ruleset, public, Apache-2.0. 15 rules, following the spectral-owasp-ruleset pattern: built-in Spectral functions only, a stable id and a section-level documentationUrl per rule, clean and noncompliant fixtures, and a harness that gates on both.

    extends:
      - https://raw.githubusercontent.com/api-commons/spectral-fhir-ruleset/main/fhir.yaml

    Registered in Ruleset Commons (ruleset-commons#2) and added to the tools table (api-commons#33).

    What it checks

    The gap between returns Patient objects and is a FHIR server. Grounded in hl7.org/fhir/R4/http.html read in full, plus the search, OperationOutcome, CapabilityStatement and SMART App Launch pages.

    The three that catch the most:

    • fhir-resource-type-path-segment — resource types are case-sensitive PascalCase singular names from a closed list. /patients and /Patients are both wrong, and both are what a team writes when bolting FHIR-shaped payloads onto REST conventions. The ruleset embeds the 178-type R4 ∪ R5 union, harvested from the published resource lists.
    • fhir-error-operationoutcome — OperationOutcome is FHIR's problem-details equivalent. A bespoke {"error": "..."} forces every client to carry two error parsers.
    • fhir-read-etag / fhir-etag-weak / fhir-update-if-match — the concurrency contract, where the versionId is a weak validator (W/"3141"). A strong-ETag example in a FHIR description is wrong and gets copied.

    Plus the /metadata CapabilityStatement a server SHALL expose, searchset Bundles instead of bare arrays, application/fhir+json, and SMART v1/v2 scope syntax.

    Validated against a real server

    The public HAPI FHIR R4 server's own generated OpenAPI — 2,973 paths. The first run returned 64 resource-type findings and every one was a bug in this ruleset, not in HAPI: Bundle wrongly excluded, three real types (EffectEvidenceSynthesis, Parameters, Requirements) silently dropped when I typed the pattern by hand, the root path / not allowed, and vendor operations containing dots not matching. The pattern is now generated from the harvested list rather than typed. Zero false positives on resource types.

    The 584 findings that remain there are real: HAPI's generated OpenAPI never documents the ETag / If-Match / 409-412 contract, even though the running server implements it. Expect that on any server-generated FHIR OpenAPI.

    Scope, stated rather than implied

    It governs the HTTP surface, not resource instances. Profile and IG conformance needs StructureDefinitions, terminology servers and the resource graph — none of which exist inside an OpenAPI. The HL7 validator remains the tool for that; this checks what the validator doesn't.

    One residual: the resource list is the R4 ∪ R5 union, so flagging a valid R5 type on an R5 API can't happen — at the cost that an R4 API using an R5-only type passes. Pin the release in info.description and review by hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions