From f90ccde96a38e4172485552f8c7c38790d4fba53 Mon Sep 17 00:00:00 2001 From: Andrei Kononov Date: Wed, 24 Jul 2024 15:02:03 +0400 Subject: [PATCH] Sort operations before building spec to ensure same order in spec regardless of the order they added to router --- okapi-operation/src/builder.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/okapi-operation/src/builder.rs b/okapi-operation/src/builder.rs index f13f26e..fe4a0ae 100644 --- a/okapi-operation/src/builder.rs +++ b/okapi-operation/src/builder.rs @@ -146,6 +146,12 @@ impl OpenApiBuilder { pub fn build(&mut self) -> Result { let mut spec = self.spec.clone(); + self.operations.sort_by(|lkey, _, rkey, _| { + let lkey_str = (&lkey.0, lkey.1.as_str()); + let rkey_str = (&rkey.0, rkey.1.as_str()); + lkey_str.cmp(&rkey_str) + }); + for ((path, method), generator) in &self.operations { try_add_path( &mut spec,