-
Notifications
You must be signed in to change notification settings - Fork 8
Align to the official specification #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
09b409d
Add Facility API, demo data, stricter query validation and /api/v1 di…
juztas 3e8b0b2
Make NamedObject reusable
juztas cf79917
Include operation_id for facility (similar to pull request #21)
juztas 0d68a1c
simplified facility endpoint proposal
gabor-lbl ed6befa
Add Facility API, demo data, stricter query validation and /api/v1 di…
juztas 28e5ba7
Remove /api/v1
juztas e8d256b
Refactor shared validators & models to fix import loading issues
juztas 58b9ef8
Github Action to validate api
juztas bc55843
Add custom get extra function
juztas 75a5cb6
Implement opentelemetry. Use UTC in demo adapter
juztas be30570
Rename dependencies to common
juztas 6b85fbf
Do not swallow exceptions
juztas 952aea0
Ensure that computed fields are included in output
juztas a1c4e53
Code base compliant with the official Spec
juztas 6fb8e8b
Fully compliant with official spec
juztas 53bc4c3
Enforce Py 3.14 as used release for everything
juztas 846c1f8
Enable deepsource scanning
juztas 2374d34
Enforce consistent package versions (pin major/minor version)
juztas 2040b48
Update Facility endpoint (based on new Format discussed during the me…
juztas e85c266
Fix operation id: getJob, getJobs
juztas 431da63
Remove resource_uri and event_uris
juztas 8892724
Remove resource_uri and event_uris
juztas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| version = 1 | ||
|
|
||
| [[analyzers]] | ||
| name = "python" | ||
| enabled = true | ||
|
|
||
| [analyzers.meta] | ||
| runtime_version = "3.x.x" | ||
| max_line_length = 200 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| name: API Validation with Schemathesis | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| schemathesis: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Checkout schema validator repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: doe-iri/iri-facility-api-docs | ||
| ref: main | ||
| path: schema-validator | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.14" | ||
|
|
||
| - name: Install uv | ||
| run: pip install uv | ||
|
|
||
| - name: Build an image | ||
| run: docker build --platform=linux/amd64 -t iri-facility-api-base . | ||
|
|
||
| - name: Run Facility API container | ||
| run: | | ||
| docker run -d \ | ||
| -p 8000:8000 \ | ||
| --platform=linux/amd64 \ | ||
| --name iri-facility-api-base \ | ||
| -e IRI_API_ADAPTER_facility=app.demo_adapter.DemoAdapter \ | ||
| -e IRI_API_ADAPTER_status=app.demo_adapter.DemoAdapter \ | ||
| -e IRI_API_ADAPTER_account=app.demo_adapter.DemoAdapter \ | ||
| -e IRI_API_ADAPTER_compute=app.demo_adapter.DemoAdapter \ | ||
| -e IRI_API_ADAPTER_filesystem=app.demo_adapter.DemoAdapter \ | ||
| -e IRI_API_ADAPTER_task=app.demo_adapter.DemoAdapter \ | ||
| -e API_URL_ROOT=http://127.0.0.1:8000 \ | ||
| -e IRI_API_TOKEN=12345 \ | ||
| iri-facility-api-base | ||
|
|
||
| - name: Wait for API to be ready | ||
| run: | | ||
| for i in {1..60}; do | ||
| if curl -fs http://127.0.0.1:8000/openapi.json; then | ||
| echo "API ready" | ||
| exit 0 | ||
| fi | ||
| sleep 2 | ||
| done | ||
| echo "API did not start" | ||
| exit 1 | ||
|
|
||
| - name: Create venv & install validator dependencies | ||
| run: | | ||
| uv venv | ||
| source .venv/bin/activate | ||
| uv pip install -r schema-validator/verification/requirements.txt | ||
|
|
||
| - name: Run Schemathesis validation (local spec) | ||
| id: schemathesis_local | ||
| env: | ||
| IRI_API_TOKEN: "12345" # This is dummy token for testing (mock adapter) | ||
| run: | | ||
| set +e | ||
| source .venv/bin/activate | ||
| python schema-validator/verification/api-validator.py \ | ||
| --baseurl http://127.0.0.1:8000 \ | ||
| --report-name schemathesis-local | ||
| echo "exitcode=$?" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Run Schemathesis validation (official spec) | ||
| id: schemathesis_official | ||
| env: | ||
| IRI_API_TOKEN: "12345" | ||
| run: | | ||
| set +e | ||
| source .venv/bin/activate | ||
| python schema-validator/verification/api-validator.py \ | ||
| --baseurl http://localhost:8000 \ | ||
| --schema-url https://raw.githubusercontent.com/doe-iri/iri-facility-api-docs/refs/heads/main/specification/openapi/openapi_iri_facility_api_v1.json \ | ||
| --report-name schemathesis-official | ||
| echo "exitcode=$?" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Fail if any Schemathesis run failed | ||
| if: always() | ||
| run: | | ||
| if [ "${{ steps.schemathesis_local.outputs.exitcode }}" != "0" ] || \ | ||
| [ "${{ steps.schemathesis_official.outputs.exitcode }}" != "0" ]; then | ||
| echo "One or more Schemathesis validations failed" | ||
| exit 1 | ||
| else | ||
| echo "Both Schemathesis validations passed" | ||
| fi | ||
|
|
||
| - name: Upload Schemathesis report # This only works on git actions | ||
| if: always() && env.ACT != 'true' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| if-no-files-found: warn | ||
| name: schemathesis-report | ||
| path: | | ||
| schemathesis-local.html | ||
| schemathesis-local.xml | ||
| schemathesis-official.html | ||
| schemathesis-official.xml | ||
|
|
||
| - name: Save Schemathesis reports locally # This only works if run locally with act | ||
| if: always() && env.ACT == 'true' | ||
| run: | | ||
| mkdir -p artifacts | ||
| cp schemathesis-local.html schemathesis-local.xml artifacts/ || true | ||
| cp schemathesis-official.html schemathesis-official.xml artifacts/ || true | ||
|
|
||
| - name: Dump API logs | ||
| if: always() | ||
| run: docker logs iri-facility-api-base || true | ||
|
|
||
| - name: Stop container | ||
| if: always() | ||
| run: docker stop iri-facility-api-base || true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # API Validation with Schemathesis | ||
|
|
||
| On every pull request or push to `main` branch, Github Actions run the following steps below that validates an IRI Facility API implementation against OpenAPI spec using Schemathesis. | ||
|
|
||
| 1. Builds the Facility API Docker image from Dockerfile. | ||
| 2. Runs the API container with demo adapter. | ||
| 3. Waits for `/openapi.json` to become available on localhost:8000. | ||
| 4. Runs Schemathesis validation twice: | ||
| - Against Facilities API’s OpenAPI spec. (http://localhost:8000/openapi.json) | ||
| - Against the official IRI Facility API OpenAPI spec. (https://github.com/doe-iri/iri-facility-api-docs/blob/main/specification/openapi/openapi_iri_facility_api_v1.json) | ||
| 5. Fails the workflow if either validation fails. | ||
| 6. Saves Schemathesis HTML/XML reports as artifacts (or saves it locally when run with `act`). | ||
| 7. Dumps API container logs and do clean up to stop container. | ||
|
|
||
| ## Running locally | ||
|
|
||
| ```bash | ||
| act -W .github/workflows/api-validator.yml -s GITHUB_TOKEN=<GITHUB_TOKEN> | ||
| ``` | ||
|
|
||
| ## Known issues | ||
|
|
||
| Python implementation not fully aligns with the official Specification. Running against Official Spec will continue to fail, until Spec or Py implementation is fixed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.