
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
openapi-refinements
Advanced tools
Refine OpenAPI schemas to valid sub-OpenAPI scheams.
Imagine that you had the following bit of JSON schema.
type: string
enum: [foo, bar, baz]
A valid refinement would be the following.
type: string
enum: [foo, baz]
In general a refinement is any Schema that produces a subset of the behavior of another Schema. In this case, because we are dealing with OpenAPI, an API behaving according to the refined OpenAPI schema will only produce outcomes that would have been possible with the original OpenAPI schema, but not vice-versa.
includeCodes and removeCodesincludeCodes(
info: [string | RegExp, Meth] | string | RegExp,
r: (keyof Responses)[]
) => (o: OpenAPIObject): OpenAPIObject
Produce an OpenAPI schema to OpenAPI schema mapping that includes codes in r (ie 200, 404, default) for a path (string or RegExp) and possibly an operation (Meth).
To produce an OpenAPI schema to OpenAPI schema mapping that only includes the default response for every possible path, use the following.
const mapping = includeCodes(new RegExp("[a-zA-Z0-9/{}]*"), ["default"]);
To produice an OpenAPI schema to OpenAPI schema mapping that removes "200" and "default" from the get method of the path /foo, use the following.
const mapping = removeCodes(["/foo", "get"], ["200", "default"]);
All changes to parameters, request bodies and response bodies represent first the change in a schema (here, "schema" means the Schema object in an OpenAPI Schema, which is effectively JSON schema) followed by instructions on how to reach the Schema.
For example, the signature for changeMaxItems is the following.
const changeMaxItems = (i: number) =>
(
traversal: (o: OpenAPIObject) => Traversal<OpenAPIObject, Schema | Reference>,
path: (string | typeof Arr)[]
) => (o: OpenAPIObject) => OpenAPIObject
i represents the change to maxNumbers. traversal represents the path we take to get the the Schema we want to change, and path represents the path we take once we are in the Schema. Then, like includeCodes above, an OpenAPI Schema to OpenAPI Schema mapping is returned.
Another example is changeToConst.
const changeToConst = (val: JSONValue) =>
(
traversal: (o: OpenAPIObject) => Traversal<OpenAPIObject, Schema | Reference>,
path: (string | typeof Arr)[]
) => (o: OpenAPIObject) => OpenAPIObject
The signature is almost exactly the same as above save the first element val, which is the constant value we are changing. For all of the following functions, the first part of the signature will be different whereas the last three parts will be the same. As a result, this section will be broken into two parts. First, we will explain the traversal and path, and then, we will explain the various actions like changeMinItems or changeEnum.
traversal and pathtraversal represents a monocle-ts traversal down to an object in an OpenAPI structure. You do not have to define your own traversals - rather, there are pre-defined traversal creators that will do this for you.
pathParameter is a traversal to a parameter in a pathmethodParameter is a traversal to a parameter in a methodrequestBody is a traversal to a parameter in a request bodyresponseBody is a traversal to a parameter in a response bodyThe tests show various examples of all of these traversals.
path represents a path within the object. For example, if the object is:
type: object
properties:
foo:
type: object
additionalProperties:
type: array
items:
type: array
items: [{type: string}, {type: integer}]
Then the path to access the second element of all the arrays of any additional property of foo would be ["foo", Addl, Arr, 1], where Arr is a special symbol meaning all elements in an array and Addl is a special symbol meaning any additional property.
The following methods are defined for schema changes.
changeMinItemchangeMaxItemchangeToConstchangeEnumchangeListToTupleanyOfKeepanyOfRejectoneOfKeeponeOfRejectFAQs
Refine OpenAPI schemas to valid sub-OpenAPI scheams.
We found that openapi-refinements demonstrated a not healthy version release cadence and project activity because the last version was released 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.