-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Python and Ruby spec validators.
Signed-off-by: dblock <dblock@amazon.com>
- Loading branch information
Showing
12 changed files
with
592 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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,34 @@ | ||
name: Validate Spec (Python) | ||
|
||
on: [pull_request,push] | ||
|
||
jobs: | ||
validate-spec-py: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Build | ||
run: npm ci && npm run merge | ||
|
||
- name: Set Up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install Dependencies | ||
working-directory: tools/src/validate-spec-py | ||
run: | | ||
pip install --user pipenv | ||
pipenv install | ||
- name: Validate Spec | ||
working-directory: tools/src/validate-spec-py | ||
run: | | ||
pipenv run python validate.py ../../../build/opensearch-openapi.yaml |
This file contains 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,28 @@ | ||
name: Validate Spec (Ruby) | ||
|
||
on: [pull_request,push] | ||
|
||
jobs: | ||
validate-spec-ruby: | ||
runs-on: ubuntu-latest | ||
env: | ||
BUNDLE_GEMFILE: ${{ github.workspace }}/tools/src/validate-spec-ruby/Gemfile | ||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Build | ||
run: npm ci && npm run merge | ||
|
||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.3' | ||
bundler-cache: true | ||
|
||
- name: Validate Spec | ||
run: | |
This file contains 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 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 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,12 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
openapi_spec_validator = "*" | ||
|
||
[dev-packages] | ||
|
||
[requires] | ||
python_version = "3" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,20 @@ | ||
import sys | ||
|
||
from openapi_spec_validator import validate | ||
from openapi_spec_validator.readers import read_from_filename | ||
from openapi_spec_validator.validation.exceptions import OpenAPIValidationError | ||
|
||
if len(sys.argv) < 2: | ||
print("syntax: validate.py [spec]") | ||
exit(1) | ||
|
||
spec = sys.argv[1] | ||
print(f'Validating {spec} ...') | ||
|
||
spec_dict, base_uri = read_from_filename(spec) | ||
|
||
try: | ||
validate(spec_dict) | ||
except OpenAPIValidationError as err: | ||
print(err) | ||
exit(2) |
This file contains 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,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'openapi3_parser' |
This file contains 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,16 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
commonmarker (0.23.10) | ||
openapi3_parser (0.9.2) | ||
commonmarker (~> 0.17) | ||
|
||
PLATFORMS | ||
arm64-darwin-21 | ||
ruby | ||
|
||
DEPENDENCIES | ||
openapi3_parser | ||
|
||
BUNDLED WITH | ||
2.5.2 |
This file contains 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,15 @@ | ||
require 'openapi3_parser' | ||
|
||
raise "syntax: validate [spec]" unless ARGV.length >= 1 | ||
|
||
spec = ARGV[0] | ||
puts "Validating #{spec} ..." | ||
|
||
parsed_spec = Openapi3Parser.load_file(spec) | ||
exit 0 if parsed_spec.valid? | ||
|
||
parsed_spec.errors.each do |error| | ||
puts "#{error.context}: #{error}" | ||
end | ||
|
||
exit 1 |