Skip to content

Commit

Permalink
Use POST instead of GET in validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Aug 31, 2020
1 parent 99d148b commit feb0eeb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deps_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ jobs:

- name: Pass generated OpenAPI schemas through validator.swagger.io
run: |
invoke run-swagger-validator-on-url --url raw.githubusercontent.com/${GITHUB_REPOSITORY}/${GITHUB_SHA}/openapi/openapi.json
invoke run-swagger-validator-on-url --url raw.githubusercontent.com/${GITHUB_REPOSITORY}/${GITHUB_SHA}/openapi/index_openapi.json
invoke run-swagger-validator openapi/openapi.json
invoke run-swagger-validator openapi/index_openapi.json
- name: Upload coverage to Codecov
if: matrix.python-version == 3.8 && github.repository == 'Materials-Consortia/optimade-python-tools'
Expand Down
11 changes: 7 additions & 4 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ def write_file(full_path: Path, content: str):
)


@task(help={"url": "URL of the file to validate"})
def run_swagger_validator_on_url(_, url=None):
""" This task can be used in the CI to test the generated OpenAPI schemas
@task(help={"filename": "The JSON file containing the OpenAPI schema to validate"})
def run_swagger_validator(_, fname):
"""This task can be used in the CI to test the generated OpenAPI schemas
with the online swagger validator.
Returns:
Expand All @@ -310,7 +310,10 @@ def run_swagger_validator_on_url(_, url=None):
import requests

swagger_url = "https://validator.swagger.io/validator/debug"
response = requests.get(f"{swagger_url}/?url={url}")
with open(fname, "r") as f:
schema = json.load(f)
response = requests.post(swagger_url, json=schema)

if response.status_code != 200:
raise RuntimeError(f"Server returned status code {response.status_code}.")

Expand Down

0 comments on commit feb0eeb

Please sign in to comment.