11using Azure . Core . Pipeline ;
2- using Flurl ;
32using System ;
43using System . Collections . Immutable ;
5- using System . IO ;
64using System . Linq ;
75using System . Text . Json . Nodes ;
86using System . Text . Json . Serialization ;
@@ -260,35 +258,6 @@ public record WsdlSelectorContract
260258 }
261259}
262260
263- public static class ApiRevisionModule
264- {
265- private const string separator = ";rev=" ;
266-
267- public static bool IsRootName ( ResourceName name ) =>
268- Parse ( name ) . IsNone ;
269-
270- public static ResourceName GetRootName ( ResourceName name ) =>
271- Parse ( name ) . Map ( x => x . RootName )
272- . IfNone ( ( ) => name ) ;
273-
274- public static Option < ( ResourceName RootName , int Revision ) > Parse ( ResourceName name ) =>
275- name . ToString ( ) . Split ( separator ) . ToArray ( ) switch
276- {
277- [ var first , var second ] => from rootName in ResourceName . From ( first ) . ToOption ( )
278- from revision in int . TryParse ( second , out var revision )
279- ? Option . Some ( revision )
280- : Option . None
281- select ( rootName , revision ) ,
282- _ => Option . None
283- } ;
284-
285- public static ResourceName Combine ( ResourceName rootName , int revision ) =>
286- revision < 1
287- ? throw new InvalidOperationException ( $ "Revision must be positive.")
288- : ResourceName . From ( $ "{ rootName } { separator } { revision } ")
289- . IfErrorThrow ( ) ;
290- }
291-
292261public static partial class ResourceModule
293262{
294263 private static async ValueTask PutApiInApim ( ResourceName name , JsonObject dto , GetResourceDtoFromApim getApimDto , HttpPipeline pipeline , ServiceUri serviceUri , CancellationToken cancellationToken )
@@ -298,11 +267,12 @@ private static async ValueTask PutApiInApim(ResourceName name, JsonObject dto, G
298267
299268 var uri = resource . GetUri ( name , parentChain , serviceUri ) ;
300269 var formattedDto = await formatDto ( ) ;
301- var result = await pipeline . PutJson ( uri , formattedDto , cancellationToken ) ;
270+
271+ var result = await pipeline . PutJson ( uri , formattedDto , cancellationToken ) ;
302272 result . IfErrorThrow ( ) ;
303273
304274 // Non-current revisions are not allowed to update certain properties.
305- // Replace them with the existing revision properties if necessary.
275+ // Replace them with the current revision's properties if necessary.
306276 async ValueTask < JsonObject > formatDto ( )
307277 {
308278 // If this is the current revision, return the DTO as-is.
@@ -312,9 +282,10 @@ async ValueTask<JsonObject> formatDto()
312282 return dto ;
313283 }
314284
315- // Otherwise, update the DTO with the appropriate current revision properties .
285+ // Otherwise, get the current revision's DTO from APIM.. .
316286 var existingDto = await getApimDto ( resource , rootName , parentChain , cancellationToken ) ;
317287
288+ // ...and use its properties to format the new revision's DTO.
318289 var result = from existingDtoObject in JsonNodeModule . To < ApiDto > ( existingDto , resource . SerializerOptions )
319290 from newDtoObject in JsonNodeModule . To < ApiDto > ( dto , resource . SerializerOptions )
320291 let formattedDtoObject = newDtoObject with
@@ -354,20 +325,4 @@ private static JsonObject FormatInformationFileDto(this ApiResource resource, Js
354325 return JsonObjectModule . From ( dto , serializerOptions )
355326 . IfErrorThrow ( ) ;
356327 }
357-
358- private static Option < ( ResourceName Name , ParentChain Ancestors ) > ParseSpecificationFile ( this ApiResource resource , FileInfo ? file , ServiceDirectory serviceDirectory )
359- {
360- if ( file is null )
361- {
362- return Option . None ;
363- }
364-
365- var specificationFileNames = specifications . Select ( GetSpecificationFileName ) ;
366- if ( specificationFileNames . Contains ( file . Name ) is false )
367- {
368- return Option . None ;
369- }
370-
371- return resource . ParseDirectory ( file . Directory , serviceDirectory ) ;
372- }
373328}
0 commit comments