diff --git a/.github/workflows/sync-rerum-shared-openapi.yml b/.github/workflows/sync-rerum-shared-openapi.yml new file mode 100644 index 0000000..072f1e4 --- /dev/null +++ b/.github/workflows/sync-rerum-shared-openapi.yml @@ -0,0 +1,34 @@ +name: Sync shared RERUM OpenAPI artifact + +on: + push: + branches: + - main + paths: + - openapi/components/rerum-shared-components.openapi.yaml + workflow_dispatch: + +permissions: + contents: read + +jobs: + dispatch-sync: + runs-on: ubuntu-latest + steps: + - name: Dispatch sync-provider-artifact workflow + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.BRY_PAT }} + script: | + await github.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', { + owner: 'cubap', + repo: 'rerum_openapi', + workflow_id: 'sync-provider-artifact.yml', + ref: 'main', + inputs: { + provider_repository: '${{ github.repository }}', + provider_ref: '${{ github.sha }}', + provider_artifact_path: 'openapi/components/rerum-shared-components.openapi.yaml', + target_artifact_path: 'schemas/openapi/rerum-shared-components.openapi.yaml' + } + }) diff --git a/__tests__/openapi_sync_artifacts.test.js b/__tests__/openapi_sync_artifacts.test.js new file mode 100644 index 0000000..d63db01 --- /dev/null +++ b/__tests__/openapi_sync_artifacts.test.js @@ -0,0 +1,34 @@ +import fs from "fs" +import path from "path" +import { fileURLToPath } from "url" + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) +const repoRoot = path.resolve(__dirname, "..") + +describe("Shared OpenAPI artifact sync scaffolding", () => { + it("verifies provider and target artifact files contain valid OpenAPI structure", () => { + const providerArtifactPath = path.join(repoRoot, "openapi/components/rerum-shared-components.openapi.yaml") + const targetArtifactPath = path.join(repoRoot, "schemas/openapi/rerum-shared-components.openapi.yaml") + const providerArtifact = fs.readFileSync(providerArtifactPath, "utf8") + const targetArtifact = fs.readFileSync(targetArtifactPath, "utf8") + + for (const artifact of [providerArtifact, targetArtifact]) { + expect(artifact).toContain("openapi: 3.0.3") + expect(artifact).toContain("title: RERUM Shared Components") + expect(artifact).toContain("version: 0.1.0") + expect(artifact).toContain("components:") + expect(artifact).toContain("schemas: {}") + } + }) + + it("verifies the shared artifact sync workflow configuration", () => { + const workflowPath = path.join(repoRoot, ".github/workflows/sync-rerum-shared-openapi.yml") + const workflow = fs.readFileSync(workflowPath, "utf8") + + expect(workflow).toContain("openapi/components/rerum-shared-components.openapi.yaml") + expect(workflow).toContain("sync-provider-artifact.yml") + expect(workflow).toContain("repo: 'rerum_openapi'") + expect(workflow).toContain("target_artifact_path: 'schemas/openapi/rerum-shared-components.openapi.yaml'") + }) +}) diff --git a/openapi/components/rerum-shared-components.openapi.yaml b/openapi/components/rerum-shared-components.openapi.yaml new file mode 100644 index 0000000..42e0b66 --- /dev/null +++ b/openapi/components/rerum-shared-components.openapi.yaml @@ -0,0 +1,13 @@ +openapi: 3.0.3 +info: + title: RERUM Shared Components + version: 0.1.0 + description: Shared reusable OpenAPI components for RERUM v1 contracts. +externalDocs: + description: RERUM API reference + url: https://store.rerum.io/v1/API.html +x-upstream-provider: + name: rerum_server_nodejs + baseUrl: https://store.rerum.io/v1 +components: + schemas: {} diff --git a/schemas/openapi/rerum-shared-components.openapi.yaml b/schemas/openapi/rerum-shared-components.openapi.yaml new file mode 100644 index 0000000..aa3aec3 --- /dev/null +++ b/schemas/openapi/rerum-shared-components.openapi.yaml @@ -0,0 +1,14 @@ +# This file is automatically synced from openapi/components/rerum-shared-components.openapi.yaml. Do not edit manually. +openapi: 3.0.3 +info: + title: RERUM Shared Components + version: 0.1.0 + description: Shared reusable OpenAPI components for RERUM v1 contracts. +externalDocs: + description: RERUM API reference + url: https://store.rerum.io/v1/API.html +x-upstream-provider: + name: rerum_server_nodejs + baseUrl: https://store.rerum.io/v1 +components: + schemas: {}