### Installing Dependencies for openapi-modifier Example (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-json-config/README.md This command installs all necessary Node.js package dependencies defined in the `package.json` file, which are required to run the `openapi-modifier` example. ```bash npm install ``` -------------------------------- ### Installing Dependencies (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command installs all necessary project dependencies listed in the `package.json` file, preparing the environment for development and building. ```bash npm install ``` -------------------------------- ### Installing Dependencies for openapi-modifier Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-json/README.md This command installs all necessary project dependencies, typically defined in the `package.json` file, required to run the `openapi-modifier` example. ```bash npm install ``` -------------------------------- ### Installing Project Dependencies (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-yaml-to-json/README.md This command installs all necessary project dependencies defined in `package.json` using npm, preparing the environment for running the OpenAPI conversion. ```bash npm install ``` -------------------------------- ### Installing Dependencies for openapi-modifier (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-yaml/README.md This command installs all necessary project dependencies defined in `package.json`. It's the first step to set up the project before running the modifier. ```bash npm install ``` -------------------------------- ### Installing Project Dependencies (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-generate-api-types/README.md This command installs all necessary project dependencies defined in the `package.json` file. It is a prerequisite for running any other scripts in the project. ```bash npm install ``` -------------------------------- ### Installing Dependencies for OpenAPI Modifier Example (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-generate-api-types/README.md This command installs all necessary project dependencies, including `openapi-modifier` for specification modification and `dtsgenerator` for TypeScript type generation, as defined in the `package.json` file. It is a prerequisite for running the API modification and type generation process. ```bash npm install ``` -------------------------------- ### Running openapi-modifier via npm script (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-json-config/README.md This command executes the `openapi-modifier` using a predefined `start` script in `package.json`, typically configured to apply the modifications to the OpenAPI specification. ```bash npm start ``` -------------------------------- ### Installing and Using OpenAPI Modifier CLI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/ru/readme.md This snippet demonstrates how to install the `openapi-modifier` package as a development dependency using npm and provides a basic command-line example for modifying an OpenAPI specification. It shows how to specify input, output, and configuration files. ```Shell npm i --save-dev openapi-modifier openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.js ``` -------------------------------- ### Initial OpenAPI Schema for /pets GET Endpoint (Replacement Example) - YAML Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-response-schema/README.md This YAML snippet presents the initial OpenAPI schema for the `/pets` GET endpoint, which will be completely replaced by a new schema structure in the subsequent modification example. ```yaml paths: /pets: get: summary: List all pets responses: 200: content: 'application/json': schema: type: 'object' properties: items: type: 'array' items: type: 'object' properties: id: { type: 'string' } name: { type: 'string' } ``` -------------------------------- ### Running OpenAPI Conversion via npm Script (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-yaml-to-json/README.md This command executes the `start` script defined in `package.json`, which typically wraps the `openapi-modifier` CLI command to perform the OpenAPI YAML to JSON conversion with applied modifications. ```bash npm start ``` -------------------------------- ### Running openapi-modifier via npm script (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-yaml/README.md This command executes the `start` script defined in `package.json`, which typically wraps the `openapi-modifier` command with predefined input, output, and configuration paths. It's a convenient way to run the modification process. ```bash npm start ``` -------------------------------- ### Installing Project Dependencies (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/contributing.md Installs all necessary project dependencies using npm. This command should be run after cloning the repository to set up the development environment. ```bash npm install ``` -------------------------------- ### Simple Component Descriptor Usage Examples (TypeScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/descriptor.md Provides various examples of valid Simple Component Descriptor strings in TypeScript. These examples demonstrate how to specify just a component name, a component with a property path, or paths involving array elements and 'allOf', 'oneOf', or 'anyOf' elements. ```typescript "TestDto" // Just component name "TestDto.foo.bar" // Component with property path "TestDto.foo.bar[].test" // Component with array element path "TestDto.allOf[2].foo" // Component with allOf element path "TestDto.oneOf[2].foo" // Component with oneOf element path "TestDto.anyOf[2].foo" // Component with anyOf element path ``` -------------------------------- ### Installing Project Dependencies (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-package-openapi-yaml/README.md This command installs all necessary project dependencies defined in the `package.json` file. It is a crucial first step before running any scripts. ```bash npm install ``` -------------------------------- ### Project Structure for openapi-modifier Example Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-npx/README.md This section illustrates the directory layout for the `example-cli-simple-npx` project, detailing the locations for the input OpenAPI file, the generated output file, the `openapi-modifier` configuration, and the `package.json`. ```plaintext example-cli-simple-npx/ ├── input/ │ └── openapi.yml # Input OpenAPI file ├── output/ │ └── openapi.yml # Output OpenAPI file (will be created) ├── openapi-modifier.config.js # Modifier configuration └── package.json # npm configuration ``` -------------------------------- ### Running openapi-modifier Example via npm (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-npx/README.md This command initiates the `openapi-modifier` process. It reads the `input/openapi.yml` file, applies the configured modification rules, and then saves the resulting modified OpenAPI specification to `output/openapi.yml`. ```bash npm start ``` -------------------------------- ### Configuring Basic OpenAPI Spec Merging in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/merge-openapi-spec/docs/en/_config.md This configuration example demonstrates how to merge an OpenAPI specification from a relative path. It uses the `merge-openapi-spec` rule and specifies the `path` to the YAML file to be merged into the current specification. This is a basic setup without explicit collision handling. ```javascript module.exports = { pipeline: [ // ... other rules { rule: "merge-openapi-spec", config: { path: 'temp-openapi-specs/new-list-endpoints.yaml' // specify path to specification file to merge } } // ... other rules ] } ``` -------------------------------- ### Simple Descriptor Usage Examples (TypeScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/descriptor.md Provides various examples of valid simple descriptor strings in TypeScript, demonstrating how to specify just a component name, a property path, an array element path, or paths within allOf, oneOf, or anyOf elements. ```typescript // Examples of valid values: "TestDto" // Just component name "TestDto.foo.bar" // Component with property path "TestDto.foo.bar[].test" // Component with array element path "TestDto.allOf[2].foo" // Component with allOf element path "TestDto.oneOf[2].foo" // Component with oneOf element path "TestDto.anyOf[2].foo" // Component with anyOf element path ``` -------------------------------- ### Installing and Using OpenAPI Modifier via CLI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/readme.md This snippet demonstrates how to install `openapi-modifier` as a development dependency using npm and then how to execute it from the command line. It specifies input and output OpenAPI files and a configuration file for modifications. ```shell npm i --save-dev openapi-modifier openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.js ``` -------------------------------- ### Object Component Descriptor Usage Examples (JSON) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/descriptor.md Illustrates valid Object Component Descriptor JSON structures. These examples show how to define a component name and optional explicit correction paths for properties or array items, without automatic path transformation. ```json { "componentName": "TestDto" } { "componentName": "TestDto", "correction": "properties.foo.properties.bar" } { "componentName": "TestDto", "correction": "items.properties.foo" } ``` -------------------------------- ### Installing openapi-modifier CLI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/simple-text-file-modifier.md This command installs the `openapi-modifier` package as a development dependency using npm. It provides the `simple-text-file-modifier` CLI tool for text file manipulation. ```bash npm install --save-dev openapi-modifier ``` -------------------------------- ### Defining a Simple String in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example demonstrates how to define a basic string type in OpenAPI, including properties like description, minimum and maximum length, pattern validation, and format (e.g., email). ```json { "type": "string", "description": "Field description", "minLength": 1, "maxLength": 100, "pattern": "^[A-Za-z0-9]+$", "format": "email" } ``` -------------------------------- ### Referencing a Schema Definition in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example illustrates how to use a JSON reference (`$ref`) to point to an existing schema definition within the OpenAPI components section, promoting reusability and modularity. ```json { "$ref": "#/components/schemas/User" } ``` -------------------------------- ### Building the Project (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command compiles the project source code, typically TypeScript, into executable JavaScript, preparing it for deployment or testing. ```bash npm run build ``` -------------------------------- ### Configuring patch-endpoint-schema with Security Patch (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-schema/README.md This example demonstrates how to configure the `patch-endpoint-schema` rule to add a security section to an endpoint's schema. It targets the 'GET /pets' endpoint and uses the 'merge' patch method to apply the `bearerAuth` security requirement. ```JavaScript module.exports = { pipeline: [ { rule: "patch-endpoint-schema", config: { endpointDescriptor: "GET /pets", // specify the endpoint to modify patchMethod: "merge", // use merge method to apply changes schemaDiff: { "security": [ // add security section to the schema { "bearerAuth": [] } ] } } } ] } ``` -------------------------------- ### Running Tests (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command executes the project's test suite, ensuring that all components function as expected and validating code changes. ```bash npm test ``` -------------------------------- ### Installing and Running OpenAPI Modifier via npm CLI Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This snippet shows how to install `openapi-modifier` as a development dependency using `npm` and then execute it from the command line. It takes an input OpenAPI specification, produces an output file, and uses a specified configuration file. ```shell npm i --save-dev openapi-modifier openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.js ``` -------------------------------- ### Defining an Array Type in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example demonstrates how to define an array in OpenAPI, specifying the type of its items, minimum and maximum item counts, and uniqueness constraints for the elements. ```json { "type": "array", "description": "Array of elements", "items": { "type": "string", "description": "Array element" }, "minItems": 1, "maxItems": 10, "uniqueItems": true } ``` -------------------------------- ### Formatting Code (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command applies code formatting rules to the project's source files, ensuring consistent style across the codebase. ```bash npm run format ``` -------------------------------- ### Running openapi-modifier Directly with Configuration (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-json-config/README.md This command directly invokes the `openapi-modifier` executable, specifying the input OpenAPI file, the output file for the modified specification, and the JSON configuration file to apply the desired transformations. ```bash openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.json ``` -------------------------------- ### Configuring Basic Endpoint Parameter Schema Patching (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-parameter-schema/README.md This configuration example demonstrates how to use the `patch-endpoint-parameter-schema` rule to modify an endpoint's query parameter. It specifies the target endpoint (`GET /api/list`), the parameter by name and `in` location (`test`, `query`), and adds an `enum` to its schema. ```javascript module.exports = { pipeline: [ // ... other rules { rule: "patch-endpoint-parameter-schema", config: { endpointDescriptor: 'GET /api/list', // specify the endpoint to modify parameterDescriptor: { name: 'test', // specify parameter name in: 'query', // specify that parameter is in query }, schemaDiff: { enum: ['foo', 'bar'], // add enum to parameter } }, } // ... other rules ] } ``` -------------------------------- ### Generating README Documentation (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command executes a tool to automatically generate or update the project's README file, often based on source code comments or configuration. ```bash npm run tools:generate-readme ``` -------------------------------- ### Running OpenAPI Modification Script Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-json/README.md This command executes the predefined 'start' script in `package.json`, which in turn runs the `openapi-modifier` with specified input, output, and configuration files. It initiates the OpenAPI file modification process. ```bash npm start ``` -------------------------------- ### Installing openapi-modifier via npm Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/simple-text-file-modifier.md This command installs the `openapi-modifier` package as a development dependency using npm. It's required to use the `simple-text-file-modifier` CLI tool for text file modifications. ```bash npm install --save-dev openapi-modifier ``` -------------------------------- ### Defining an Object Type in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example shows how to define a complex object in OpenAPI, including its properties, required fields, behavior for additional properties, and limits on the number of properties. ```json { "type": "object", "description": "Complex object", "properties": { "name": { "type": "string", "description": "Object name" }, "value": { "type": "number", "description": "Object value" } }, "required": ["name"], "additionalProperties": false, "minProperties": 1, "maxProperties": 5 } ``` -------------------------------- ### Running OpenAPI Specification Modification and Type Generation (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-simple-generate-api-types/README.md This command initiates the main process, which first modifies the input OpenAPI file using `openapi-modifier` based on the `openapi-modifier.config.ts` rules, and then generates TypeScript types from the modified OpenAPI file using `dtsgenerator`. It orchestrates the entire workflow described in the example. ```bash npm start ``` -------------------------------- ### Object Descriptor Usage Examples (TypeScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/descriptor.md Illustrates valid object descriptor configurations in TypeScript, showing how to define a component with or without a correction path, and how to specify paths for nested properties or array items explicitly. ```typescript // Examples of valid values: { "componentName": "TestDto" } { "componentName": "TestDto", "correction": "properties.foo.properties.bar" } { "componentName": "TestDto", "correction": "items.properties.foo" } ``` -------------------------------- ### Implementing Conditional Fields in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example shows how to define conditional schema logic using `if`, `then`, and `else` keywords in OpenAPI, making certain fields required or optional based on other property values. ```json { "type": "object", "properties": { "type": { "type": "string", "enum": ["user", "admin"] }, "permissions": { "type": "array", "items": { "type": "string" } } }, "if": { "properties": { "type": { "const": "admin" } } }, "then": { "required": ["permissions"] } } ``` -------------------------------- ### Combining Types with oneOf in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example demonstrates how to use `oneOf` in OpenAPI to specify that a value can conform to exactly one of several provided schemas, allowing for flexible data types. ```json { "oneOf": [ { "type": "string" }, { "type": "number" } ], "description": "Value can be either a string or a number" } ``` -------------------------------- ### Generating Rule Types (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command runs a utility to generate TypeScript type definitions for rules, which can improve type safety and developer experience. ```bash npm run tools:generate-rule-types ``` -------------------------------- ### Configuring Endpoint Parameter Schema Patching in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This example demonstrates a basic configuration for patching an endpoint's parameter schema using the `patch-endpoint-parameter-schema` rule. It specifies the target endpoint (`GET /api/list`), the parameter to modify (`test` in `query`), and adds an `enum` constraint to its schema. ```javascript module.exports = { pipeline: [ // ... other rules { rule: "patch-endpoint-parameter-schema", config: { endpointDescriptor: 'GET /api/list', // specify the endpoint to modify parameterDescriptor: { name: 'test', // specify parameter name in: 'query', // specify that parameter is in query }, schemaDiff: { enum: ['foo', 'bar'], // add enum to parameter } }, } // ... other rules ] } ``` -------------------------------- ### Configuring Basic OpenAPI Spec Merge in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/merge-openapi-spec/README.md This configuration example demonstrates how to merge an OpenAPI specification from a relative path. It specifies the `rule` as 'merge-openapi-spec' and provides the `path` to the YAML specification file to be merged into the current pipeline. ```JavaScript module.exports = { pipeline: [ // ... other rules { rule: "merge-openapi-spec", config: { path: 'temp-openapi-specs/new-list-endpoints.yaml' // specify path to specification file to merge } } // ... other rules ] } ``` -------------------------------- ### Initial OpenAPI Schema for /pets GET Endpoint - YAML Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-response-schema/README.md This YAML snippet shows the initial OpenAPI schema for the `/pets` GET endpoint, defining an array of pet objects with `id` and `name` properties, before any modifications are applied. ```yaml paths: /pets: get: summary: List all pets responses: 200: content: 'application/json': schema: type: 'object' properties: items: type: 'array' items: type: 'object' properties: id: { type: 'string' } name: { type: 'string' } ``` -------------------------------- ### Configuring File Modifications in TypeScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/simple-text-file-modifier.md This TypeScript configuration example provides rules for modifying a text file. It prepends a warning comment, appends an end-of-file marker, and replaces 'Components.' with 'ApiComponents.' using a regular expression, similar to the JavaScript example. ```typescript export default { addBefore: "// This file was auto-generated. Do not edit manually.\n", addAfter: "\n// End of auto-generated file", replace: [ { searchValue: /Components\./g, replaceValue: 'ApiComponents.' } ] }; ``` -------------------------------- ### Configuring `change-content-type` Rule with Multiple Content Type Mappings in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/change-content-type/README.md This example illustrates a more detailed configuration for the `change-content-type` rule. It shows how to map specific content types like `application/xml` and `text/plain` to `application/json`, in addition to a wildcard replacement for any other content types. ```JavaScript module.exports = { pipeline: [ // ... other rules { rule: "change-content-type", config: { map: { "application/xml": "application/json", // replace application/xml with application/json "text/plain": "application/json", // replace text/plain with application/json "*/*": "application/json" // replace all other content types with application/json } }, } // ... other rules ] } ``` -------------------------------- ### Defining a Number Type in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example illustrates how to define a numeric type in OpenAPI, including constraints like minimum, maximum, exclusive bounds, multipleOf, and format (e.g., float, double, int32, int64). ```json { "type": "number", "description": "Numeric value", "minimum": 0, "maximum": 100, "exclusiveMinimum": true, "exclusiveMaximum": true, "multipleOf": 0.5, "format": "float" } ``` -------------------------------- ### Defining a String Enum in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/schema-diff.md This example shows how to create a string enumeration in OpenAPI, allowing only a predefined set of values and specifying a default value for the field. ```json { "type": "string", "enum": ["a", "b", "c"], "description": "Choose one of the allowed values", "default": "a" } ``` -------------------------------- ### Configuring Endpoint Schema Patching with Security (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This example demonstrates a basic configuration for the `patch-endpoint-schema` rule. It specifies modifying the 'GET /pets' endpoint using the 'merge' patch method and adds a 'security' section with 'bearerAuth' to its schema. This configuration is used to apply security definitions to a specific API endpoint. ```javascript module.exports = { pipeline: [ { rule: "patch-endpoint-schema", config: { endpointDescriptor: "GET /pets", // specify the endpoint to modify patchMethod: "merge", // use merge method to apply changes schemaDiff: { "security": [ // add security section to the schema { "bearerAuth": [] } ] } } } ] } ``` -------------------------------- ### Running OpenAPI Conversion Directly with CLI (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-yaml-to-json/README.md This command directly invokes the `openapi-modifier` command-line interface. It specifies `input/openapi.yml` as the source OpenAPI file and `output/openapi.json` as the destination for the converted and modified JSON output. ```bash openapi-modifier --input=input/openapi.yml --output=output/openapi.json ``` -------------------------------- ### Cleaning Build Directories (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/contributing.md This command removes generated build artifacts and temporary files, ensuring a clean state for new builds. ```bash npm run clear ``` -------------------------------- ### Configuring patch-component-schema Rule in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-component-schema/README.md This example demonstrates a basic configuration for the `patch-component-schema` rule within a JavaScript pipeline. It targets the 'TestDTO' component and modifies its type to 'string', illustrating a simple schema update. ```javascript module.exports = { pipeline: [ // ... other rules { rule: "patch-component-schema", config: { descriptor: 'TestDTO', // specify the component to modify schemaDiff: { type: 'string', // change component type to string }, }, } // ... other rules ] } ``` -------------------------------- ### Configuring Endpoint Response Schema Patching (Basic) - JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This configuration example demonstrates how to use the `patch-endpoint-response-schema` rule to modify a specific endpoint's response schema. It targets the `GET /api/list` endpoint and adds an `enum` constraint to the `status` field within an array in the response. ```javascript module.exports = { pipeline: [ // ... other rules { rule: "patch-endpoint-response-schema", config: { endpointDescriptor: 'GET /api/list', // specify the endpoint to modify correction: '[].status', // specify path to status field in response array schemaDiff: { enum: ['foo', 'bar'], // add enum to status field }, }, } // ... other rules ] } ``` -------------------------------- ### Installing OpenAPI Modifier via npm Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/readme.md This command installs the `openapi-modifier` package as a development dependency in your project. Using `--save-dev` ensures it's listed in your `package.json` under `devDependencies`, indicating it's required for development but not for production. ```Bash npm install --save-dev openapi-modifier ``` -------------------------------- ### Configuring patch-endpoint-schema for Response Schema Correction (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-schema/README.md This example shows a more detailed configuration for `patch-endpoint-schema`, targeting a specific field within a response schema. It modifies the schema of the 'GET /pets' endpoint's 200 OK response content to include an `enum` array, using `endpointDescriptorCorrection` to pinpoint the exact location. ```JavaScript module.exports = { pipeline: [ { rule: "patch-endpoint-schema", config: { patchMethod: 'merge', endpointDescriptor: "GET /pets", endpointDescriptorCorrection: 'responses.200.content.*/*.schema', schemaDiff: { enum: ['3', '4'], }, } } ] } ``` -------------------------------- ### Detailed Configuration for `change-endpoints-basepath` Rule in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/change-endpoints-basepath/README.md This snippet provides a more comprehensive configuration example for the `change-endpoints-basepath` rule. It illustrates how to replace a specific prefix (`/public/v1/service/api`) with a new one (`/api`) and explicitly sets `ignoreOperationCollisions` to `false` to ensure conflict checking. ```js module.exports = { pipeline: [ // ... other rules { rule: "change-endpoints-basepath", config: { map: { '/public/v1/service/api': '/api', // replace the prefix /public/v1/service/api with /api }, ignoreOperationCollisions: false, // do not ignore operation conflicts when replacing paths }, } // ... other rules ] } ``` -------------------------------- ### Configuring Endpoint Filtering with `enabled` in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/filter-endpoints/docs/en/_config.md This configuration example demonstrates how to use the `enabled` parameter to explicitly keep a specific endpoint. Only the `GET /foo/ping` endpoint will be included in the OpenAPI specification, while all other endpoints will be removed. This is useful for whitelisting a small set of desired endpoints. ```javascript module.exports = { pipeline: [ // ... other rules { rule: "filter-endpoints", config: { enabled: [ 'GET /foo/ping' // keep only GET /foo/ping endpoint, all others will be removed ], }, } // ... other rules ] } ``` -------------------------------- ### Defining a Simple String in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/schema-diff.md This snippet defines an OpenAPI schema for a basic string type, including common constraints such as minimum and maximum length, a regular expression pattern for validation, and a format hint like 'email'. ```json { "type": "string", "description": "Field description", "minLength": 1, "maxLength": 100, "pattern": "^[A-Za-z0-9]+$", "format": "email" // Supported formats: email, date, date-time, uri, uuid, etc. } ``` -------------------------------- ### Example of Operation Collision in OpenAPI YAML Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/change-endpoints-basepath/docs/en/_notes.md This YAML snippet illustrates an operation collision scenario where two distinct API paths, `/api/v1/pets` and `/v1/pets`, both define a GET operation. If `/api/v1` is replaced with `/v1`, both paths would resolve to `/v1/pets`, causing a conflict. The snippet shows the original conflicting paths. ```YAML paths: /api/v1/pets: get: summary: List all pets /v1/pets: get: summary: Get pet by id ``` -------------------------------- ### Detailed Endpoint Schema Patching with Enum Correction (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This more detailed configuration example for the `patch-endpoint-schema` rule targets the 'GET /pets' endpoint. It uses the 'merge' method and specifies `endpointDescriptorCorrection` to apply a schema difference (adding an `enum` property with values '3' and '4') to a specific part of the response schema, such as `responses.200.content.*/*.schema`. ```javascript module.exports = { pipeline: [ { rule: "patch-endpoint-schema", config: { patchMethod: 'merge', endpointDescriptor: "GET /pets", endpointDescriptorCorrection: 'responses.200.content.*/*.schema', schemaDiff: { enum: ['3', '4'], }, } } ] } ``` -------------------------------- ### Running Complete API Type Generation Workflow (npm) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-generate-api-types/README.md This command executes the entire API type generation workflow sequentially, including OpenAPI specification modification, TypeScript type generation, and patching of the generated types. It orchestrates all defined scripts. ```bash npm run start ``` -------------------------------- ### Initial OpenAPI YAML for Pet Name Description Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-request-body-schema/docs/en/_motivation.md This snippet displays the initial OpenAPI 3.0 YAML definition for the `/pets` POST endpoint, focusing on the `name` property within the `requestBody` schema. It includes an initial `description` for the `name` field. ```yaml paths: /pets: post: requestBody: content: application/json: schema: type: object properties: name: type: string description: Pet name ``` -------------------------------- ### OpenAPI Specification After Unused Component Removal (YAML) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/remove-unused-components/README.md This YAML snippet illustrates the OpenAPI specification after the `remove-unused-components` rule has been applied with the configuration from the previous example. It demonstrates that `UnusedSchema` and `UnusedResponse` have been successfully removed, while `User` and `NotFound` (which were explicitly ignored) remain, resulting in a cleaner and more concise specification. ```yaml components: schemas: User: type: object properties: name: type: string responses: NotFound: description: Not found ``` -------------------------------- ### Excluding Internal Endpoints in OpenAPI Modifier (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/filter-endpoints/README.md This JavaScript configuration for the 'openapi-modifier-config.js' file applies the 'filter-endpoints' rule to remove all endpoints whose paths start with '/internal'. This is a practical example of how to use `disabledPathRegExp` to clean up an OpenAPI specification by excluding internal or private API routes. ```JavaScript module.exports = { pipeline: [ { rule: "filter-endpoints", config: { disabledPathRegExp: [/^/internal/] } } ] } ``` -------------------------------- ### Referencing an OpenAPI Schema Definition Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/schema-diff.md This snippet illustrates how to reference an existing schema definition within an OpenAPI specification using the '$ref' keyword. This mechanism promotes reusability and modularity by allowing schemas to be defined once and referenced multiple times. ```json { "$ref": "#/components/schemas/User" } ``` -------------------------------- ### Advanced Configuration for remove-unused-components Rule (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/remove-unused-components/README.md This example illustrates a more detailed configuration for the `remove-unused-components` rule. It demonstrates how to use the `ignore` parameter to specify components (by name or regular expression) that should not be removed, and the `printDeletedComponents` parameter to log the list of components that were deleted to the console. This allows for fine-grained control over the cleanup process. ```js module.exports = { pipeline: [ // ... other rules { rule: "remove-unused-components", config: { ignore: [ "NotFoundDTO", /^Error.*/, // ignore all components starting with Error /.*Response$/ // ignore all components ending with Response ], printDeletedComponents: true // print list of deleted components to console }, } // ... other rules ] } ``` -------------------------------- ### Installing OpenAPI Modifier via npm Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This command demonstrates how to install the `openapi-modifier` package as a development dependency using npm. The `--save-dev` flag ensures it's added to the `devDependencies` section of the `package.json` file, indicating it's required for development but not for production. ```Bash npm install --save-dev openapi-modifier ``` -------------------------------- ### Directly Running openapi-modifier with CLI Arguments (Bash) Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-yaml/README.md This command directly invokes the `openapi-modifier` CLI tool, specifying the input OpenAPI file, the desired output file, and the configuration file. This provides explicit control over the modification process without relying on `package.json` scripts. ```bash openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.ts ``` -------------------------------- ### Removing Unused Endpoint Parameter using openapi-modifier (YAML, JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/remove-parameter/docs/en/_motivation.md This example demonstrates how to remove an unused query parameter (`version`) from a specific endpoint (`GET /pets/{petId}`) in an OpenAPI specification using the `openapi-modifier` tool. It shows the OpenAPI definition before and after the modification, along with the JavaScript configuration required for the `remove-parameter` rule. ```yaml paths: /pets/{petId}: get: summary: Get pet by ID parameters: - name: petId in: path required: true schema: type: string - name: version in: query required: false schema: type: string ``` ```javascript module.exports = { pipeline: [ { rule: "remove-parameter", config: { endpointDescriptor: "GET /pets/{petId}", parameterDescriptor: { name: "version", in: "query" } } } ] } ``` ```yaml paths: /pets/{petId}: get: summary: Get pet by ID parameters: - name: petId in: path required: true schema: type: string ``` -------------------------------- ### Running OpenAPI Modifier via NPX CLI Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This command demonstrates how to execute the `openapi-modifier` tool using `npx`. It specifies the input OpenAPI specification file, the desired output file, and the path to a configuration file. This is a quick way to run the tool without global installation. ```shell npx openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.js ``` -------------------------------- ### Detailed Configuration for Patching Endpoint Response Schema - JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-response-schema/docs/en/_config.md This example provides a more detailed configuration for the `patch-endpoint-response-schema` rule. It specifically targets the `GET /api/list` endpoint's 200 OK response with `application/json` content type. The `status` field is updated with an `enum`, and the `deepmerge` method is explicitly used for applying the schema changes, allowing for more complex merging behavior. ```JavaScript module.exports = { pipeline: [ // ... other rules { rule: "patch-endpoint-response-schema", config: { endpointDescriptor: 'GET /api/list', // specify the endpoint to modify correction: '[].status', // specify path to status field in response array code: 200, // specify response code to apply changes to contentType: 'application/json', // specify content type to apply changes to schemaDiff: { enum: ['foo', 'bar'], // add enum to status field }, patchMethod: 'deepmerge' // use deepmerge method for deep merging changes }, } // ... other rules ] } ``` -------------------------------- ### Replaced OpenAPI Schema for /pets GET Endpoint - YAML Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/patch-endpoint-response-schema/README.md This YAML snippet displays the OpenAPI schema for the `/pets` GET endpoint after applying the `patch-endpoint-response-schema` rule with the `replace` method. It shows the new `data` array structure, which has completely replaced the original `items` array. ```yaml paths: /pets: get: summary: List all pets responses: 200: content: 'application/json': schema: type: 'object' properties: data: type: 'array' items: type: 'object' properties: id: { type: 'string' } name: { type: 'string' } description: { type: 'string' } ``` -------------------------------- ### Configuring File Modifications in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/simple-text-file-modifier.md This JavaScript configuration example defines rules for modifying a text file. It adds a warning comment to the beginning, an end-of-file marker, and replaces all occurrences of 'Components.' with 'ApiComponents.' using a regular expression. ```javascript module.exports = { addBefore: "// This file was auto-generated. Do not edit manually.\n", addAfter: "\n// End of auto-generated file", replace: [ { searchValue: /Components\./g, replaceValue: 'ApiComponents.' } ] }; ``` -------------------------------- ### OpenAPI YAML Before Base Path Modification Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/change-endpoints-basepath/README.md This YAML snippet shows an example of an OpenAPI `paths` definition before applying the `change-endpoints-basepath` rule. It illustrates an endpoint with a long base path (`/public/api/v1/pets`) that needs to be shortened. ```yaml paths: /public/api/v1/pets: get: summary: List all pets ``` -------------------------------- ### Defining Main OpenAPI Specification (openapi.yaml) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/merge-openapi-spec/README.md This YAML snippet defines the primary OpenAPI specification for a 'Main API', including a '/pets' endpoint with a GET method. It serves as the base specification to which other API definitions will be merged. ```yaml openapi: 3.0.0 info: title: Main API paths: /pets: get: summary: List all pets responses: 200: content: 'application/json': schema: type: 'object' ``` -------------------------------- ### Using OpenAPI Modifier CLI with npx Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/readme.md This command demonstrates how to execute the `openapi-modifier` command-line interface using `npx`. It specifies the `--input` OpenAPI file, the `--output` path for the modified file, and the `--config` file that defines the modification rules. This is a common way to run Node.js package executables without globally installing them. ```Shell npx openapi-modifier --input=input/openapi.yml --output=output/openapi.yml --config=openapi-modifier.config.js ``` -------------------------------- ### Defining a Number Type in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/schema-diff.md This snippet illustrates how to define an OpenAPI schema for a numeric type, including constraints such as minimum and maximum values, exclusive bounds, multiples, and a format hint like 'float' or 'int32'. ```json { "type": "number", "description": "Numeric value", "minimum": 0, "maximum": 100, "exclusiveMinimum": true, "exclusiveMaximum": true, "multipleOf": 0.5, "format": "float" // Supported formats: float, double, int32, int64 } ``` -------------------------------- ### Removing Common Parameter Component using openapi-modifier (YAML, JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/remove-parameter/docs/en/_motivation.md This example illustrates how to remove a globally defined parameter component (`ApiKeyHeader`) from the `components.parameters` section of an OpenAPI specification. This is useful for cleaning up definitions that interfere with type generation. The example includes the OpenAPI definition before and after the modification, along with the `openapi-modifier` JavaScript configuration. ```yaml components: parameters: ApiKeyHeader: name: X-API-Key in: header required: true schema: type: string ``` ```javascript module.exports = { pipeline: [ { rule: "remove-parameter", config: { parameterDescriptor: { name: "X-API-Key", in: "header" } } } ] } ``` ```yaml components: parameters: {} ``` -------------------------------- ### Configuring `remove-unused-components` Rule (Detailed) - JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This snippet provides a more detailed configuration example for the `remove-unused-components` rule. It illustrates how to use the `ignore` array to specify components or regular expressions to exclude from removal, and how to enable `printDeletedComponents` to log the removed components to the console. ```js module.exports = { pipeline: [ // ... other rules { rule: "remove-unused-components", config: { ignore: [ "NotFoundDTO", /^Error.*/, // ignore all components starting with Error /.*Response$/ // ignore all components ending with Response ], printDeletedComponents: true // print list of deleted components to console } } // ... other rules ] } ``` -------------------------------- ### Configuring File Modifications in JSON Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/simple-text-file-modifier.md This JSON configuration example specifies rules for modifying a text file. It adds a warning comment to the beginning, an end-of-file marker, and performs a string replacement of 'Components.' with 'ApiComponents.'. Note that regular expressions are not directly supported in JSON for `searchValue`. ```json { "addBefore": "// This file was auto-generated. Do not edit manually.\n", "addAfter": "\n// End of auto-generated file", "replace": [ { "searchValue": "Components.", "replaceValue": "ApiComponents." } ] } ``` -------------------------------- ### Configuring remove-min-items Rule (Detailed) - JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This JavaScript configuration shows a more detailed setup for the `remove-min-items` rule. By setting `showUnusedWarning` to `true`, the rule will issue a warning if no schemas containing the `minItems` property are found in the specification. ```JavaScript module.exports = { pipeline: [ // ... other rules { rule: "remove-min-items", config: { showUnusedWarning: true // show warning if no schemas with minItems are found in the specification } } // ... other rules ] } ``` -------------------------------- ### Applying merge Method to OpenAPI Schema (JavaScript) Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/merge-vs-deepmerge.md This example demonstrates the `merge` method's behavior. It shows how top-level properties are overwritten, and nested objects are completely replaced rather than merged, as seen with the `properties` object. ```javascript // Original object { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } } } // Applying merge with: { properties: { name: { type: 'string', format: 'email' } } } // Result: { type: 'object', properties: { name: { type: 'string', format: 'email' } } } ``` -------------------------------- ### OpenAPI Modifier Configuration File Structure Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/ru/readme.md This JavaScript snippet outlines the structure of a configuration file for `openapi-modifier`. It defines optional logger settings (verbose, minLevel), required input and output paths for OpenAPI files, and a `pipeline` array for applying modification rules. An example rule `change-content-type` is included, showing how to disable a rule and configure its specific parameters. ```JavaScript module.exports = { // (optional) Logger settings logger: { verbose: true, // Enable verbose logging minLevel: 0 // Minimum logging level: 0 - trace, 1 - debug, 2 - info, 3 - warn, 4 - error }, // Path to the input OpenAPI specification file input: './openapi.yaml', // Path to the output file output: './modified-openapi.yaml', // Pipeline of rules to apply (see all available rules with configuration examples below) pipeline: [ { rule: "change-content-type", disabled: false, // (optional) Disable rule config: { map: { "*/*": "application/json" } } } // Other rules... ] } ``` -------------------------------- ### Configuring Basic Component Schema Patching in JavaScript Source: https://github.com/itwillwork/openapi-modifier/blob/main/README.md This example demonstrates a basic configuration for the `patch-component-schema` rule. It shows how to specify a component using a simple descriptor (`TestDTO`) and change its type to `string` using `schemaDiff`. This configuration applies a simple merge by default. ```js module.exports = { pipeline: [ // ... other rules { rule: "patch-component-schema", config: { descriptor: 'TestDTO', // specify the component to modify schemaDiff: { type: 'string', // change component type to string }, }, } // ... other rules ] } ``` -------------------------------- ### Simple Component Descriptor Format Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/descriptor.md Illustrates the string format used by the simple descriptor, where the component name and correction path are separated by dots. This format is compact and relies on automatic path transformation. ```Configuration String "ComponentName.path.to.property" ``` -------------------------------- ### Defining a String Enum in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/schema-diff.md This snippet demonstrates how to define an OpenAPI schema for a string type that restricts its value to a predefined list of options (enum) and specifies a default value if none is provided. ```json { "type": "string", "enum": ["a", "b", "c"], "description": "Choose one of the allowed values", "default": "a" } ``` -------------------------------- ### OpenAPI Specification with Unused Components (YAML) Source: https://github.com/itwillwork/openapi-modifier/blob/main/src/rules/remove-unused-components/README.md This YAML snippet represents an OpenAPI specification containing both used (`User`, `NotFound`) and unused (`UnusedSchema`, `UnusedResponse`) components. It serves as an input example to demonstrate how the `remove-unused-components` rule identifies and targets components that are not referenced elsewhere in the document for removal. ```yaml components: schemas: User: type: object properties: name: type: string UnusedSchema: type: object properties: field: type: string responses: NotFound: description: Not found UnusedResponse: description: Unused response ``` -------------------------------- ### Executing openapi-modifier CLI Directly Source: https://github.com/itwillwork/openapi-modifier/blob/main/examples/example-cli-openapi-json/README.md This command directly invokes the `openapi-modifier` CLI tool, specifying the input OpenAPI JSON file, the desired output path for the modified file, and the TypeScript configuration file to apply the modification rules. It's the underlying command executed by `npm start`. ```bash openapi-modifier --input=input/openapi.json --output=output/openapi.json --config=openapi-modifier.config.ts ``` -------------------------------- ### Defining Conditional Fields in OpenAPI Source: https://github.com/itwillwork/openapi-modifier/blob/main/docs/drafts/en/schema-diff.md This snippet demonstrates how to use 'if' and 'then' keywords to define conditional schema requirements. It specifies that the 'permissions' field is required only if the 'type' field has a value of 'admin'. ```json { "type": "object", "properties": { "type": { "type": "string", "enum": ["user", "admin"] }, "permissions": { "type": "array", "items": { "type": "string" } } }, "if": { "properties": { "type": { "const": "admin" } } }, "then": { "required": ["permissions"] } } ```