Right on! There are many reasons to swerve: roadkill, running critters, shiny (probably sharp!) debris, grease, rocks, holes, rails, sticks, bricks, etc.
When you see something in your lane that you do not want to hit or run over, you swerve. No explanation is needed, because you are riding legally.