up
This commit is contained in:
36
src/Sdk/StellaOps.Sdk.Generator/postprocess/README.md
Normal file
36
src/Sdk/StellaOps.Sdk.Generator/postprocess/README.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Post-process Scaffold (SDKGEN-62-002)
|
||||
|
||||
These hooks are invoked via OpenAPI Generator's `--enable-post-process-file` option. They are deliberately minimal and deterministic:
|
||||
|
||||
- Normalise line endings to LF and strip trailing whitespace.
|
||||
- Preserve file mode 0644.
|
||||
- Inject a deterministic banner for supported languages (TS/JS/Go/Java/C#/Python/Ruby) when enabled (default on).
|
||||
- Language-specific rewrites (auth/retry/pagination/telemetry) will be added as SDKGEN-62-002 progresses.
|
||||
|
||||
## Usage
|
||||
|
||||
Set the generator's post-process command to this script (example for Bash):
|
||||
|
||||
```bash
|
||||
export STELLA_SDK_POSTPROCESS="$PWD/postprocess/postprocess.sh"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Dorg.openapitools.codegen.utils.postProcessFile=$STELLA_SDK_POSTPROCESS"
|
||||
```
|
||||
|
||||
Or pass via CLI where supported:
|
||||
|
||||
```bash
|
||||
--global-property "postProcessFile=$PWD/postprocess/postprocess.sh"
|
||||
```
|
||||
|
||||
## Determinism
|
||||
- Uses only POSIX tools (`sed`, `perl`) available in build containers.
|
||||
- Does not reorder content; only whitespace/line-ending normalization.
|
||||
- Safe to run multiple times (idempotent).
|
||||
|
||||
## Configuration (optional)
|
||||
- `STELLA_POSTPROCESS_ADD_BANNER` (default `1`): when enabled, injects `Generated by StellaOps SDK generator — do not edit.` at the top of supported source files, idempotently.
|
||||
- Future flags (placeholders until implemented): `STELLA_POSTPROCESS_ENABLE_AUTH`, `STELLA_POSTPROCESS_ENABLE_RETRY`, `STELLA_POSTPROCESS_ENABLE_PAGINATION`, `STELLA_POSTPROCESS_ENABLE_TELEMETRY`.
|
||||
|
||||
## Next steps
|
||||
- Add language-specific post steps (auth helper injection, retry/pagination utilities, telemetry headers) behind flags per language template.
|
||||
- Wire into CI to enforce post-processed trees are clean.
|
||||
36
src/Sdk/StellaOps.Sdk.Generator/postprocess/postprocess.sh
Normal file
36
src/Sdk/StellaOps.Sdk.Generator/postprocess/postprocess.sh
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
file="$1"
|
||||
|
||||
# Normalize line endings to LF and strip trailing whitespace deterministically
|
||||
perl -0777 -pe 's/\r\n/\n/g; s/[ \t]+$//mg' "$file" > "$file.tmp"
|
||||
perm=$(stat -c "%a" "$file" 2>/dev/null || echo 644)
|
||||
mv "$file.tmp" "$file"
|
||||
chmod "$perm" "$file"
|
||||
|
||||
# Optional banner injection for traceability (idempotent)
|
||||
ADD_BANNER="${STELLA_POSTPROCESS_ADD_BANNER:-1}"
|
||||
if [ "$ADD_BANNER" = "1" ]; then
|
||||
ext="${file##*.}"
|
||||
case "$ext" in
|
||||
ts|js) prefix="//" ;;
|
||||
go) prefix="//" ;;
|
||||
java) prefix="//" ;;
|
||||
cs) prefix="//" ;;
|
||||
py) prefix="#" ;;
|
||||
rb) prefix="#" ;;
|
||||
*) prefix="" ;;
|
||||
esac
|
||||
|
||||
if [ -n "$prefix" ]; then
|
||||
banner="$prefix Generated by StellaOps SDK generator — do not edit."
|
||||
first_line="$(head -n 1 "$file" || true)"
|
||||
if [ "$first_line" != "$banner" ]; then
|
||||
printf "%s\n" "$banner" > "$file.tmp"
|
||||
cat "$file" >> "$file.tmp"
|
||||
mv "$file.tmp" "$file"
|
||||
chmod "$perm" "$file"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
Reference in New Issue
Block a user