Can this logic be moved out of the REST endpoint into the API function? The API function can then decide which documentation to return.