@@ -150,6 +150,42 @@ private static void ConfigureMappings()
150
150
? src . SubscriptionKeyParameterNames . Query
151
151
: null ) ) ;
152
152
153
+ cfg
154
+ . CreateMap < PsApiManagementApi , ApiContract > ( )
155
+ . ForMember ( dest => dest . Id , opt => opt . MapFrom ( src => src . Id ) )
156
+ . ForMember ( dest => dest . Name , opt => opt . MapFrom ( src => src . ApiId ) )
157
+ . ForMember ( dest => dest . DisplayName , opt => opt . MapFrom ( src => src . Name ) )
158
+ . ForMember ( dest => dest . Description , opt => opt . MapFrom ( src => src . Description ) )
159
+ . ForMember ( dest => dest . Path , opt => opt . MapFrom ( src => src . Path ) )
160
+ . ForMember ( dest => dest . ServiceUrl , opt => opt . MapFrom ( src => src . ServiceUrl ) )
161
+ . ForMember ( dest => dest . ApiRevision , opt => opt . MapFrom ( src => src . ApiRevision ) )
162
+ . ForMember ( dest => dest . ApiVersion , opt => opt . MapFrom ( src => src . ApiVersion ?? string . Empty ) )
163
+ . ForMember ( dest => dest . ApiType , opt => opt . MapFrom ( src => src . ApiType ?? ApiType . Http ) )
164
+ . ForMember ( dest => dest . IsCurrent , opt => opt . MapFrom ( src => src . IsCurrent ) )
165
+ . ForMember ( dest => dest . IsOnline , opt => opt . MapFrom ( src => src . IsOnline ) )
166
+ . ForMember ( dest => dest . Protocols , opt => opt . MapFrom ( src => src . Protocols . ToArray ( ) ) )
167
+ . AfterMap ( ( src , dest ) =>
168
+ dest . AuthenticationSettings = ToAuthenticationSettings ( src ) )
169
+ . AfterMap ( ( src , dest ) =>
170
+ dest . SubscriptionKeyParameterNames = ToSubscriptionKeyParameterNamesContract ( src ) ) ;
171
+
172
+ cfg
173
+ . CreateMap < PsApiManagementApi , ApiCreateOrUpdateParameter > ( )
174
+ . ForMember ( dest => dest . DisplayName , opt => opt . MapFrom ( src => src . Name ) )
175
+ . ForMember ( dest => dest . Description , opt => opt . MapFrom ( src => src . Description ) )
176
+ . ForMember ( dest => dest . Path , opt => opt . MapFrom ( src => src . Path ) )
177
+ . ForMember ( dest => dest . ServiceUrl , opt => opt . MapFrom ( src => src . ServiceUrl ) )
178
+ . ForMember ( dest => dest . ApiRevision , opt => opt . MapFrom ( src => src . ApiRevision ) )
179
+ . ForMember ( dest => dest . ApiVersion , opt => opt . MapFrom ( src => src . ApiVersion ?? string . Empty ) )
180
+ . ForMember ( dest => dest . ApiType , opt => opt . MapFrom ( src => src . ApiType ?? ApiType . Http ) )
181
+ . ForMember ( dest => dest . IsCurrent , opt => opt . MapFrom ( src => src . IsCurrent ) )
182
+ . ForMember ( dest => dest . IsOnline , opt => opt . MapFrom ( src => src . IsOnline ) )
183
+ . ForMember ( dest => dest . Protocols , opt => opt . MapFrom ( src => src . Protocols . ToArray ( ) ) )
184
+ . AfterMap ( ( src , dest ) =>
185
+ dest . AuthenticationSettings = ToAuthenticationSettings ( src ) )
186
+ . AfterMap ( ( src , dest ) =>
187
+ dest . SubscriptionKeyParameterNames = ToSubscriptionKeyParameterNamesContract ( src ) ) ;
188
+
153
189
cfg . CreateMap < ApiContract , ApiCreateOrUpdateParameter > ( ) ;
154
190
cfg . CreateMap < RequestContract , PsApiManagementRequest > ( ) ;
155
191
cfg . CreateMap < ResponseContract , PsApiManagementResponse > ( ) ;
@@ -590,13 +626,14 @@ public PsApiManagementApi ApiSet(
590
626
string subscriptionKeyQueryParamName ,
591
627
PsApiManagementApi apiObject )
592
628
{
593
- ApiContract apiContract ;
629
+ ApiCreateOrUpdateParameter api ;
594
630
if ( apiObject == null )
595
631
{
596
- apiContract = Client . Api . Get (
632
+ var apiContract = Client . Api . Get (
597
633
resourceGroupName ,
598
634
servicename ,
599
635
id ) ;
636
+ api = Mapper . Map < ApiCreateOrUpdateParameter > ( apiContract ) ;
600
637
}
601
638
else
602
639
{
@@ -605,17 +642,33 @@ public PsApiManagementApi ApiSet(
605
642
{
606
643
id = apiObject . ApiId . ApiRevisionIdentifier ( apiObject . ApiRevision ) ;
607
644
}
608
- apiContract = Mapper . Map < ApiContract > ( apiObject ) ;
645
+ api = Mapper . Map < ApiCreateOrUpdateParameter > ( apiObject ) ;
609
646
}
610
647
611
- var api = new ApiCreateOrUpdateParameter
648
+ if ( ! string . IsNullOrEmpty ( name ) )
612
649
{
613
- DisplayName = name ?? apiContract . Name ,
614
- Description = description ?? apiContract . Description ,
615
- ServiceUrl = serviceUrl ?? apiContract . ServiceUrl ,
616
- Path = urlSuffix ?? apiContract . Path ,
617
- Protocols = urlSchema != null ? Mapper . Map < IList < Protocol ? > > ( urlSchema ) : apiContract . Protocols
618
- } ;
650
+ api . DisplayName = name ;
651
+ }
652
+
653
+ if ( ! string . IsNullOrEmpty ( description ) )
654
+ {
655
+ api . Description = description ;
656
+ }
657
+
658
+ if ( ! string . IsNullOrEmpty ( serviceUrl ) )
659
+ {
660
+ api . ServiceUrl = serviceUrl ;
661
+ }
662
+
663
+ if ( ! string . IsNullOrEmpty ( urlSuffix ) )
664
+ {
665
+ api . Path = urlSuffix ;
666
+ }
667
+
668
+ if ( urlSchema != null )
669
+ {
670
+ api . Protocols = Mapper . Map < IList < Protocol ? > > ( urlSchema ) ;
671
+ }
619
672
620
673
if ( authorizationServerId != null )
621
674
{
@@ -628,10 +681,6 @@ public PsApiManagementApi ApiSet(
628
681
}
629
682
} ;
630
683
}
631
- else
632
- {
633
- api . AuthenticationSettings = apiContract . AuthenticationSettings ;
634
- }
635
684
636
685
if ( ! string . IsNullOrWhiteSpace ( subscriptionKeyHeaderName ) || ! string . IsNullOrWhiteSpace ( subscriptionKeyQueryParamName ) )
637
686
{
@@ -641,10 +690,6 @@ public PsApiManagementApi ApiSet(
641
690
Query = subscriptionKeyQueryParamName
642
691
} ;
643
692
}
644
- else
645
- {
646
- api . SubscriptionKeyParameterNames = apiContract . SubscriptionKeyParameterNames ;
647
- }
648
693
649
694
var updatedApiContract = Client . Api . CreateOrUpdate (
650
695
resourceGroupName ,
@@ -923,7 +968,10 @@ public void UpdateApiRelease(
923
968
apiId ,
924
969
releaseId ) ;
925
970
926
- apiReleaseContract . Notes = notes ;
971
+ if ( ! string . IsNullOrEmpty ( notes ) )
972
+ {
973
+ apiReleaseContract . Notes = notes ;
974
+ }
927
975
928
976
Client . ApiRelease . Update (
929
977
resourceGroupName ,
@@ -2933,6 +2981,45 @@ static IList<ParameterContract> ToParameterContract(PsApiManagementParameter[] p
2933
2981
return parameterList ;
2934
2982
}
2935
2983
2984
+ static AuthenticationSettingsContract ToAuthenticationSettings ( PsApiManagementApi psApiManagementApi )
2985
+ {
2986
+ if ( psApiManagementApi == null ||
2987
+ string . IsNullOrWhiteSpace ( psApiManagementApi . AuthorizationServerId ) ||
2988
+ string . IsNullOrEmpty ( psApiManagementApi . AuthorizationScope ) )
2989
+ {
2990
+ return null ;
2991
+ }
2992
+
2993
+ var settings = new AuthenticationSettingsContract ( )
2994
+ {
2995
+ OAuth2 = new OAuth2AuthenticationSettingsContract ( )
2996
+ {
2997
+ AuthorizationServerId = psApiManagementApi . AuthorizationServerId ,
2998
+ Scope = psApiManagementApi . AuthorizationScope
2999
+ }
3000
+ } ;
3001
+
3002
+ return settings ;
3003
+ }
3004
+
3005
+ static SubscriptionKeyParameterNamesContract ToSubscriptionKeyParameterNamesContract ( PsApiManagementApi psApiManagementApi )
3006
+ {
3007
+ if ( psApiManagementApi == null ||
3008
+ ( string . IsNullOrWhiteSpace ( psApiManagementApi . SubscriptionKeyHeaderName ) &&
3009
+ string . IsNullOrEmpty ( psApiManagementApi . SubscriptionKeyQueryParamName ) ) )
3010
+ {
3011
+ return null ;
3012
+ }
3013
+
3014
+ var subscriptionKeyParameters = new SubscriptionKeyParameterNamesContract ( )
3015
+ {
3016
+ Header = psApiManagementApi . SubscriptionKeyHeaderName ,
3017
+ Query = psApiManagementApi . SubscriptionKeyQueryParamName
3018
+ } ;
3019
+
3020
+ return subscriptionKeyParameters ;
3021
+ }
3022
+
2936
3023
static PsApiManagementParameter [ ] ToParameterContract ( IList < ParameterContract > parameters )
2937
3024
{
2938
3025
if ( parameters == null || ! parameters . Any ( ) )
0 commit comments