@@ -198,7 +198,7 @@ impl VersionedApiSpecFileName {
198198 /// Returns the path of this file relative to the root of the OpenAPI
199199 /// documents.
200200 pub fn path ( & self ) -> Utf8PathBuf {
201- Utf8PathBuf :: from_iter ( [ self . ident . deref ( ) . clone ( ) , self . basename ( ) ] )
201+ Utf8PathBuf :: from_iter ( [ self . ident . as_str ( ) , & self . basename ( ) ] )
202202 }
203203
204204 /// Returns the base name of this file path.
@@ -216,54 +216,44 @@ impl VersionedApiSpecFileName {
216216 }
217217 }
218218
219- /// Converts this filename to its JSON equivalent.
220- ///
221- /// If already JSON, returns a clone of self.
222- pub fn to_json ( & self ) -> Self {
219+ /// Returns a copy of this filename with the given storage kind.
220+ fn with_kind ( & self , kind : VersionedApiSpecKind ) -> Self {
223221 Self {
224222 ident : self . ident . clone ( ) ,
225223 version : self . version . clone ( ) ,
226224 hash : self . hash . clone ( ) ,
227- kind : VersionedApiSpecKind :: Json ,
225+ kind,
228226 }
229227 }
230228
229+ /// Converts this filename to its JSON equivalent.
230+ ///
231+ /// If already JSON, returns a clone of self.
232+ pub fn to_json ( & self ) -> Self {
233+ self . with_kind ( VersionedApiSpecKind :: Json )
234+ }
235+
231236 /// Converts this filename to its Git stub equivalent.
232237 ///
233238 /// If already a Git stub, returns a clone of self.
234239 pub fn to_git_stub ( & self ) -> Self {
235- Self {
236- ident : self . ident . clone ( ) ,
237- version : self . version . clone ( ) ,
238- hash : self . hash . clone ( ) ,
239- kind : VersionedApiSpecKind :: GitStub ,
240- }
240+ self . with_kind ( VersionedApiSpecKind :: GitStub )
241241 }
242242
243243 /// Returns the basename as a Git stubname.
244244 ///
245245 /// - If already a Git stub, returns `basename()` directly.
246246 /// - If JSON, returns `basename() + ".gitstub"`.
247247 pub fn git_stub_basename ( & self ) -> String {
248- match self . kind {
249- VersionedApiSpecKind :: GitStub => self . basename ( ) ,
250- VersionedApiSpecKind :: Json => {
251- format ! ( "{}.gitstub" , self . basename( ) )
252- }
253- }
248+ self . to_git_stub ( ) . basename ( )
254249 }
255250
256251 /// Returns the basename as a JSON filename.
257252 ///
258253 /// - If already JSON, returns `basename()` directly.
259254 /// - If Git stub, returns the basename without `.gitstub`.
260255 pub fn json_basename ( & self ) -> String {
261- match self . kind {
262- VersionedApiSpecKind :: Json => self . basename ( ) ,
263- VersionedApiSpecKind :: GitStub => {
264- format ! ( "{}-{}-{}.json" , self . ident, self . version, self . hash)
265- }
266- }
256+ self . to_json ( ) . basename ( )
267257 }
268258}
269259
@@ -497,8 +487,10 @@ impl ApiIdent {
497487 }
498488
499489 /// Given an API identifier and a file name, determine if we're looking at
500- /// this API's "latest" symlink
490+ /// this API's "latest" symlink.
501491 pub fn versioned_api_is_latest_symlink ( & self , base_name : & str ) -> bool {
502- base_name == self . versioned_api_latest_symlink ( )
492+ base_name
493+ . strip_prefix ( self . 0 . as_str ( ) )
494+ . is_some_and ( |rest| rest == "-latest.json" )
503495 }
504496}
0 commit comments