npm run generate:api

find ./src/app/core/api/v1/model -type f -exec sed -i '' -e '' -e "s/hydramember/'hydra:member'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e '' -e "s/hydratotalItems/'hydra:totalItems'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydraview/'hydra:view'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydrasearch/'hydra:search'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydratemplate/'hydra:template'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydravariableRepresentation/'hydra:variableRepresentation'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydramapping/'hydra:mapping'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydrafirst/'hydra:first'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydralast/'hydra:last'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydranext/'hydra:next'/g" {} +
find ./src/app/core/api/v1/model -type f -exec sed -i '' -e "s/hydraprevious/'hydra:previous'/g" {} +

# Entferne "context?: ..."
find ./src/app/core/api/v1/model -type f -name '*.ts' -exec sed -i '' '/context\?: .*;/d' {} +

# Ersetze in jeder Datei nur das erste Vorkommen von "readonly type?: string;"
# durch "readonly xType?: string;"
find ./src/app/core/api/v1/model -type f -name '*.ts' -exec perl -i -pe 'if($.==1){$x=0} if(!$x && /^(\s*)readonly type\?: string;/){ $x=1; s//$1readonly xType?: string;/ }' {} \;


# https://dev.to/martinmcwhorter/generate-angular-reactiveforms-from-swagger-openapi-35h9 -> alternative
# https://github.com/Humbertda/ngx-openapi-form-generator -> alternative
# https://github.com/verizonconnect/ngx-form-generator -> we use this one

cat openapi.json | jq 'walk(if type == "object" then with_entries(select(.key | test("^@") | not)) else . end)' > openapi_no_hydra.json
npx ngx-form-generator -i openapi_no_hydra.json -o src/app/_forms/ -f apiForms.ts

rm openapi_no_hydra.json