All files / src/app/docs/developer/reference page.tsx

84.61% Statements 11/13
83.33% Branches 10/12
60% Functions 3/5
84.61% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 1451x                       1x         1x                 1x                                                       12x 12x 12x 6x 6x       12x                                         60x                                                                                                                          
"use client";
 
import dynamic from "next/dynamic";
import Link from "next/link";
import { ArrowLeft } from "lucide-react";
import { useEffect, useState } from "react";
import "@scalar/api-reference-react/style.css";
import { IS_STATIC } from "@/lib/static-export";
import { DocsLastUpdated } from "@/components/docs/DocsLastUpdated";
import { ApiSignInGuide } from "@/components/docs/ApiSignInGuide";
import { useT } from "@/lib/i18n/translate";
 
const ApiReferenceReact = dynamic(
  () => import("@scalar/api-reference-react").then((m) => m.ApiReferenceReact),
  { ssr: false },
);
 
const SPEC_URL = IS_STATIC
  ? "/MinimumViableHealthDataspacev2/openapi.yaml"
  : "/openapi.yaml";
 
/**
 * The specifications the API implements, each linked to its version. Scalar's
 * metaData description below names them too, but that is a <meta> tag and
 * cannot carry links, so the page header shows them.
 */
const SPECS: { label: string; href: string }[] = [
  {
    label: "DSP 2025-1",
    href: "https://eclipse-dataspace-protocol-base.github.io/DataspaceProtocol/2025-1/",
  },
  {
    label: "DCP v1.0",
    href: "https://eclipse-dataspace-dcp.github.io/decentralized-claims-protocol/v1.0/",
  },
  { label: "FHIR R4", href: "https://hl7.org/fhir/R4/" },
  {
    label: "OMOP CDM v5.4",
    href: "https://ohdsi.github.io/CommonDataModel/cdm54.html",
  },
  {
    label: "HealthDCAT-AP Release 8",
    href: "https://data.health.europa.eu/healthdcat-ap/releases/release-8/",
  },
];
 
export default function ApiReferencePage() {
  // Scalar's "Test Request" and its curl samples use the first server of the
  // OpenAPI spec, the Azure demo, whichever hub serves the page. baseServerURL
  // does not change that: it only completes relative server URLs, and the
  // spec's are absolute (seen on 2026-11-11: a local stack's samples said
  // https://ehds.mabu.red). `servers` replaces the list, so the one server on
  // offer is the hub the reader is signed in to. The static export has no API
  // routes and keeps the spec's list.
  const t = useT("docsDeveloper");
  const [baseServerUrl, setBaseServerUrl] = useState<string>("");
  useEffect(() => {
    Eif (typeof window !== "undefined") {
      setBaseServerUrl(window.location.origin);
    }
  }, []);
 
  return (
    <div className="min-h-screen flex flex-col">
      <div className="px-6 py-4 border-b border-(--border) bg-(--surface-1)">
        <Link
          href="/docs/developer"
          className="inline-flex items-center gap-1 text-sm text-(--text-secondary) hover:text-(--text-primary)"
        >
          <ArrowLeft size={14} /> {t("Back to Developer Guide")}
        </Link>
        <h1 className="text-2xl font-bold mt-2">{t("API Reference")}</h1>
        <DocsLastUpdated page="/docs/developer/reference" />
        <p className="text-sm text-(--text-secondary) mt-1">
          {t(
            "Interactive, three-column reference for all REST endpoints of the EHDS Integration Hub. Powered by Scalar: try any endpoint directly from the right-hand code panel.",
          )}
        </p>
        <p
          className="text-xs text-(--text-secondary) mt-1"
          data-testid="api-reference-specs"
        >
          {SPECS.map((spec, i) => (
            <span key={spec.href}>
              {i > 0 && " · "}
              <a
                href={spec.href}
                target="_blank"
                rel="noopener noreferrer"
                className="text-(--accent) hover:underline"
              >
                {spec.label}
              </a>
            </span>
          ))}
        </p>
        <div className="mt-3 max-w-5xl">
          <ApiSignInGuide returnTo="/docs/developer/reference" />
        </div>
      </div>
      <div className="flex-1 bg-white">
        <ApiReferenceReact
          configuration={{
            url: SPEC_URL,
            theme: "default",
            layout: "modern",
            hideDarkModeToggle: false,
            // "Open API Client" leaves for client.scalar.com, which cannot
            // send this hub's session cookie (every route but /api/health
            // needs one, ADR-044) and which some networks do not reach at
            // all. The in-page client already sends requests, signed in.
            hideClientButton: true,
            // "Ask AI" sends the question and the document to Scalar's
            // service, which this hub's Content-Security-Policy does not
            // allow (connect-src 'self') and a reader did not ask for.
            agent: { disabled: true },
            // The roles an operation's gate admits, beside the operation.
            showExtensions: ["x-required-roles"],
            ...(baseServerUrl ? { baseServerURL: baseServerUrl } : {}),
            ...(baseServerUrl && !IS_STATIC
              ? {
                  servers: [
                    {
                      url: baseServerUrl,
                      description: "This hub, where you are signed in",
                    },
                  ],
                }
              : {}),
            defaultHttpClient: {
              targetKey: "shell",
              clientKey: "curl",
            },
            metaData: {
              title: "EHDS Integration Hub API",
              description:
                "DSP 2025-1 · DCP v1.0 · FHIR R4 · OMOP CDM · HealthDCAT-AP",
            },
          }}
        />
      </div>
    </div>
  );
}