ControllerApiDescriptionModel.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Abp.Web.Api.Modeling
  5. {
  6. [Serializable]
  7. public class ControllerApiDescriptionModel
  8. {
  9. public string Name { get; }
  10. public IDictionary<string, ActionApiDescriptionModel> Actions { get; }
  11. private ControllerApiDescriptionModel()
  12. {
  13. }
  14. public ControllerApiDescriptionModel(string name)
  15. {
  16. Name = name;
  17. Actions = new Dictionary<string, ActionApiDescriptionModel>();
  18. }
  19. public ActionApiDescriptionModel AddAction(ActionApiDescriptionModel action)
  20. {
  21. if (Actions.ContainsKey(action.Name))
  22. {
  23. throw new AbpException(
  24. $"Can not add more than one action with same name to the same controller. Controller: {Name}, Action: {action.Name}."
  25. );
  26. }
  27. return Actions[action.Name] = action;
  28. }
  29. public ControllerApiDescriptionModel CreateSubModel(string[] actions)
  30. {
  31. var subModel = new ControllerApiDescriptionModel(Name);
  32. foreach (var action in Actions.Values)
  33. {
  34. if (actions == null || actions.Contains(action.Name))
  35. {
  36. subModel.AddAction(action);
  37. }
  38. }
  39. return subModel;
  40. }
  41. }
  42. }