/// <summary> /// Maps the specified API version to the configured controller action. /// </summary> /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> to map to the action.</param> /// <returns>The original <see cref="ActionApiVersionConventionBuilder"/>.</returns> public virtual ActionApiVersionConventionBuilder MapToApiVersion(ApiVersion apiVersion) { Arg.NotNull(apiVersion, nameof(apiVersion)); Contract.Ensures(Contract.Result <ActionApiVersionConventionBuilder>() != null); MappedVersions.Add(apiVersion); return(this); }
/// <summary> /// Applies the builder conventions to the specified controller action. /// </summary> /// <param name="actionModel">The <see cref="ActionModel">action model</see> to apply the conventions to.</param> public virtual void ApplyTo(ActionModel actionModel) { Arg.NotNull(actionModel, nameof(actionModel)); MappedVersions.AddRange(from provider in actionModel.Attributes.OfType <IApiVersionProvider>() where !provider.AdvertiseOnly && !provider.Deprecated from version in provider.Versions select version); var controllerVersionInfo = actionModel.GetProperty <ControllerVersionInfo>(); var versionModel = new ApiVersionModel( declaredVersions: MappedVersions, supportedVersions: controllerVersionInfo.Item1, deprecatedVersions: controllerVersionInfo.Item2, advertisedVersions: controllerVersionInfo.Item3, deprecatedAdvertisedVersions: controllerVersionInfo.Item4); actionModel.SetProperty(versionModel); }
/// <summary> /// Applies the builder conventions to the specified controller action. /// </summary> /// <param name="actionModel">The <see cref="ActionModel">action model</see> to apply the conventions to.</param> public virtual void ApplyTo(ActionModel actionModel) { Arg.NotNull(actionModel, nameof(actionModel)); MappedVersions.AddRange(from provider in actionModel.Attributes.OfType <IApiVersionProvider>() where !provider.AdvertiseOnly && !provider.Deprecated from version in provider.Versions select version); var(supportedVersions, deprecatedVersions, advertisedVersions, deprecatedAdvertisedVersions) = actionModel.GetProperty <Tuple <IEnumerable <ApiVersion>, IEnumerable <ApiVersion>, IEnumerable <ApiVersion>, IEnumerable <ApiVersion> > >(); var versionModel = new ApiVersionModel( declaredVersions: MappedVersions, supportedVersions, deprecatedVersions, advertisedVersions, deprecatedAdvertisedVersions); actionModel.SetProperty(versionModel); }