The flag flapped violently in the wind.
This is certainly grammatical and idiomatic.
The flag flapped violently under the wind.
While this is grammatical, it doesn't sound entirely right. As it stands, it has a strange interpretation of the flag being spatially underneath an air current that disturbs the air above it. But, if that were the case, then the flag wouldn't be flapping violently.
I would say that this sense could be corrected by adding a word to the end of the sentence. Something like:
The flag flapped violently under the wind's influence.
This changes the sense of under from being one of spatial location to one of control.
It's possible, of course, to understand the intended meaning without the additional context. But I think it would be prudent to make the addition if under is used.