What are JSONPath Expressions?
JSONPath expressions provide a powerful tool for querying and manipulating JSON data in your OpenAPI specifications. By using JSONPath, you can selectively target specific nodes in your API spec and apply modifications without altering the base structure
Example JSONPath Expressions
- All Post or Get Operations
- Operations with a Request Body
- Operations with a Specific Visibility Notation
- Inject Annotations as Siblings
All Post or Get Operations
This expression selects all paths that contain either POST or GET operations. It's useful when you want to apply changes or add annotations specifically to these HTTP methods.
JSONPath Target
$.paths.*[?("post","get")]
Overlay Action
actions: - target: $.paths.*[?("post","get")] update: x-apiture-logging: true description: "Logging enabled for all POST and GET operations."
Operations with a Request Body
This targets all operations that include a request body. It's ideal for adding descriptions, examples, or additional schema validations to request bodies.
JSONPath Target
$.paths.*[?(@.requestBody)]
Overlay Action
actions: - target: $.paths.*[?(@.requestBody)] update: x-custom-validation: "custom-validation-schema" description: "Custom validations applied to request bodies."
Operations with a Specific Visibility Notation
This expression is used to find all operations marked with 'admin' visibility. It can be used to apply additional security measures or modify documentation for admin-only endpoints.
JSONPath Target
$.paths.*[?(@["x-visibility"] == "admin")]
Overlay Action
actions: - target: $.paths.*[?(@["x-visibility"] == "admin")] update: x-custom-security: "enhanced" description: "Enhanced security for admin endpoints."
Inject Annotations as Siblings
This expression targets all operations within an OpenAPI specification that have an operationId
property.
JSONPath Target
$.paths.*.*[?(@.operationId)]
Overlay Action
actions: - target: $.paths.*.*[?(@.operationId)] update: x-detailed-logging: "enabled" log_level: "verbose" description: "Verbose logging enabled for this operation to track detailed performance metrics."