How rest-api-spec is being generated?

In this PR – I see the rest-api-spec JSON files being added. Are they written manually or automatically? I am very suspicious they are generated automatically. Could someone point me to the code that gets them generated?

They often receive a fair bit of copy and paste but they are written by
hand. They exist so elasticsearch can share tests with its clients.

Thank you Nik.