post_process
post_process
Post process code generated by OpenAPI Generator.
Often, you want to slightly modify the code generated by OpenAPI Generator with a few find and replace tasks.
post_process
automates this process with a configuration file.
It might support more task types in the future.
Installation
Install from Git
Add the following to shard.yaml
development_dependencies:
post_process:
github: cyangle/post_process
version: ~> 0.2.3
Usage
Run post_process
binary within your project to find and replace strings with regex patterns.
Configuration
Default configuration file is .post_process.yml
. It allows to configure multiple find and replace tasks.
All changes are applied sequentially in the order specified in the configuration file.
Example configuration file:
tasks: # Required, an array of find and replace tasks.
- name: "update api files" # Required, name of the task.
file_glob: './src/google_drive/api/*.cr' # Required, file path glob pattern for the files to be processed.
changes: # Required, an array of changes you want to make to the files
-
name: 'Remove common method prefix "drive_[api_name]_"' # Required, name of the change
pattern: 'drive_%{api_name}_' # Required, string template for the regex pattern to find strings to change, supports interpolation.
new_value: '' # Required, string template for the new string to replace the ones found by the pattern, supports interpolation.
multi_line: false # Optional, whether to match multiple lines, default to false.
-
name: 'Restore operation name' # Required, name of the change
pattern: 'operation: "%{capitalized_api_name}Api.' # Required, string template for the regex pattern to find strings to change, supports interpolation.
new_value: 'operation: "%{capitalized_api_name}Api.drive_%{api_name}_' # Required, string template for the new string to replace the ones found by the pattern, supports interpolation.
For each file, before processing, pattern
and new_value
would be interpolated with below two variables:
api_name
capitalized_api_name
Given example file path src/google_drive/api/files_api.cr
, the api_name
for this file is files
, and the capitalized_api_name
for this file is Files
.
the above configuration file after interpolation:
tasks: # Required, an array of find and replace tasks.
- name: "update api files" # Required, name of the task.
file_glob: './src/google_drive/api/files_api.cr' # Required, file path glob pattern for the files to be processed.
changes: # Required, an array of changes you want to make to the files
-
name: 'Remove common method prefix "drive_[api_name]_"' # Required, name of the change
pattern: 'drive_files_' # Required, string template for the regex pattern to find strings to change, supports interpolation.
new_value: '' # Required, string template for the new string to replace the ones found by the pattern, supports interpolation.
multi_line: false # Optional, whether to match multiple lines, default to false.
-
name: 'Restore operation name' # Required, name of the change
pattern: 'operation: "FilesApi.' # Required, string template for the regex pattern to find strings to change, supports interpolation.
new_value: 'operation: "FilesApi.drive_files_' # Required, string template for the new string to replace the ones found by the pattern, supports interpolation.
Development
Install dependencies
shards
Run the tests:
crystal spec
Run lints
./bin/ameba
crystal tool format --check
Contributing
- Fork it (https://github.com/cyangle/post_process/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Chao Yang - creator and maintainer
post_process
- 0
- 0
- 0
- 6
- 1
- about 1 year ago
- November 26, 2021
MIT License
Fri, 22 Nov 2024 12:22:06 GMT