Skip to content

Commit 8cf1c31

Browse files
committed
Added Python and Ruby spec validators.
Signed-off-by: dblock <[email protected]>
1 parent 1db1840 commit 8cf1c31

12 files changed

+592
-2
lines changed

.cspell

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Oversample
134134
performanceanalyzer
135135
permissionsinfo
136136
pipefail
137+
pipenv
137138
preconfigure
138139
preconfigured
139140
prefilter
File renamed without changes.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Validate Spec (Python)
2+
3+
on: [pull_request,push]
4+
5+
jobs:
6+
validate-spec-py:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout the repo
10+
uses: actions/checkout@v4
11+
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: '20'
16+
17+
- name: Build
18+
run: npm ci && npm run merge
19+
20+
- name: Set Up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.12'
24+
25+
- name: Install Dependencies
26+
working-directory: tools/src/validate-spec-py
27+
run: |
28+
pip install --user pipenv
29+
pipenv install
30+
31+
- name: Validate Spec
32+
working-directory: tools/src/validate-spec-py
33+
run: |
34+
pipenv run python validate.py ../../../build/opensearch-openapi.yaml
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Validate Spec (Ruby)
2+
3+
on: [pull_request,push]
4+
5+
jobs:
6+
validate-spec-ruby:
7+
runs-on: ubuntu-latest
8+
env:
9+
BUNDLE_GEMFILE: ${{ github.workspace }}/tools/src/validate-spec-ruby/Gemfile
10+
steps:
11+
- name: Checkout the repo
12+
uses: actions/checkout@v4
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: '20'
18+
19+
- name: Build
20+
run: npm ci && npm run merge
21+
22+
- uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: '3.3'
25+
bundler-cache: true
26+
27+
- name: Validate Spec
28+
run: |

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
107107
- Added API spec for `adjust_pure_negative` for bool queries ([#641](https://github.com/opensearch-project/opensearch-api-specification/pull/641))
108108
- Added a spec style checker [#620](https://github.com/opensearch-project/opensearch-api-specification/pull/620).
109109
- Added `remote_store` to node `Stats` ([#643](https://github.com/opensearch-project/opensearch-api-specification/pull/643))
110+
- Added Python and Ruby spec validators ([#646](https://github.com/opensearch-project/opensearch-api-specification/pull/646))
110111

111112
### Changed
112113

DEVELOPER_GUIDE.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
- [Comment on PR](#comment-on-pr)
2727
- [Test Tools (Unit)](#test-tools-unit)
2828
- [Test Tools (Integration)](#test-tools-integration)
29-
- [Validate Spec](#validate-spec)
29+
- [Validate Spec (Lint)](#validate-spec-lint)
30+
- [Validate Spec (Python)](#validate-spec-python)
3031
<!-- TOC -->
3132

3233
# Developer Guide
@@ -375,6 +376,10 @@ This workflow runs on PRs to invoke the [tools' unit tests](tools/tests), upload
375376

376377
This workflow runs on PRs to invoke the [tools' integration tests](tools/tests) that require a running instance of OpenSearch to ensure there are no breakages in behavior.
377378

378-
### [Validate Spec](.github/workflows/validate-spec.yml)
379+
### [Validate Spec (Lint)](.github/workflows/validate-spec-lint.yml)
379380

380381
This workflow runs on PRs to invoke the [spec linter](#spec-linter) and ensure the multi-file spec is correct and follows the design guidelines.
382+
383+
### [Validate Spec (Python)](.github/workflows/validate-spec-py.yml)
384+
385+
This workflow runs on PRs to invoke the [Python openapi-spec-validator](https://pypi.org/project/openapi-spec-validator/) to ensure that the resulting spec can be loaded by Python tools.

tools/src/validate-spec-py/Pipfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
openapi_spec_validator = "*"
8+
9+
[dev-packages]
10+
11+
[requires]
12+
python_version = "3"

tools/src/validate-spec-py/Pipfile.lock

+455
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
from openapi_spec_validator import validate
4+
from openapi_spec_validator.readers import read_from_filename
5+
from openapi_spec_validator.validation.exceptions import OpenAPIValidationError
6+
7+
if len(sys.argv) < 2:
8+
print("syntax: validate.py [spec]")
9+
exit(1)
10+
11+
spec = sys.argv[1]
12+
print(f'Validating {spec} ...')
13+
14+
spec_dict, base_uri = read_from_filename(spec)
15+
16+
try:
17+
validate(spec_dict)
18+
except OpenAPIValidationError as err:
19+
print(err)
20+
exit(2)

tools/src/validate-spec-ruby/Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'openapi3_parser'
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
commonmarker (0.23.10)
5+
openapi3_parser (0.9.2)
6+
commonmarker (~> 0.17)
7+
8+
PLATFORMS
9+
arm64-darwin-21
10+
ruby
11+
12+
DEPENDENCIES
13+
openapi3_parser
14+
15+
BUNDLED WITH
16+
2.5.2
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'openapi3_parser'
2+
3+
raise "syntax: validate [spec]" unless ARGV.length >= 1
4+
5+
spec = ARGV[0]
6+
puts "Validating #{spec} ..."
7+
8+
parsed_spec = Openapi3Parser.load_file(spec)
9+
exit 0 if parsed_spec.valid?
10+
11+
parsed_spec.errors.each do |error|
12+
puts "#{error.context}: #{error}"
13+
end
14+
15+
exit 1

0 commit comments

Comments
 (0)