
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
openapi_slicer
is a Ruby gem designed to extract specific parts of an OpenAPI specification (either in JSON or YAML format) based on a regular expression. It slices paths from the spec that match the given regex and ensures that all necessary tag and component dependencies are included in the result. You can export the filtered OpenAPI spec to a file in JSON or YAML format.
Add this line to your application's Gemfile:
gem 'openapi_slicer'
Then execute:
bundle install
Or install it yourself as:
gem install openapi_slicer
First, initialize an OpenapiSlicer
instance by providing the path to a JSON or YAML OpenAPI spec file.
require 'openapi_slicer'
slicer = OpenapiSlicer.new(file_path: 'path/to/openapi_spec.yaml')
To filter the OpenAPI spec based on a regular expression, use the filter
method:
# Filter the spec for all paths under '/pets'
filtered_spec = slicer.filter(%r{^/pets})
This will return a new spec that contains only the paths that match /pets
, along with all the necessary components, tags, and other dependencies.
You can also directly export the filtered spec to a file using the export
method:
# Export the filtered spec to a new JSON file
slicer.export(%r{^/pets}, 'filtered_spec.json')
# Or export to a YAML file
slicer.export(%r{^/pets}, 'filtered_spec.yaml')
Suppose you have the following paths in your OpenAPI spec:
/pets
/pets/{petId}
/pets/{petId}/health
/owners/{ownerId}
Using the filter
method, you can slice out only the paths under /pets
:
filtered_spec = slicer.filter(%r{^/pets})
This will return a spec containing:
/pets
/pets/{petId}
/pets/{petId}/health
Any necessary $ref
components or tag dependencies will also be included in the filtered spec.
After checking out the repo, run bin/setup
to install dependencies. Then, run the tests using:
rake test
To install this gem onto your local machine, run:
bundle exec rake install
To use the CLI, run the ruby scripts/openapi_slicer
command with the following options:
-i
, --input FILE
: Required. The path to the input OpenAPI specification file (in JSON or YAML format).-r
, --regex REGEX
: Required. A regular expression used to filter the paths from the OpenAPI file.-o
, --output FILE
: (Optional) The path where the filtered output will be saved. If not provided, the filtered result will be printed to the console.-h
, --help
: Displays help information for the available options.Filter an OpenAPI spec file and print the result to the console:
ruby scripts/openapi_slicer -i openapi.json -r '/api/v1/users'
Filter an OpenAPI spec file and save the result to an output file:
ruby scripts/openapi_slicer -i openapi.json -r '/api/v1/users' -o filtered_spec.json
If required options are missing, the CLI will display an error message and terminate.
Bug reports and pull requests are welcome on GitHub at https://github.com/thescubageek/openapi_slicer.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that openapi_slicer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.