Example #1
0
        private void AddApiDescriptionToModel(ApiDescription apiDescription, ApplicationApiDescriptionModel model)
        {
            var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
            var setting        = FindSetting(controllerType);

            var moduleModel = model.GetOrAddModule(GetRootPath(controllerType, setting));

            var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);

            var method = apiDescription.ActionDescriptor.GetMethodInfo();

            var uniqueMethodName = GetUniqueActionName(method);

            if (controllerModel.Actions.ContainsKey(uniqueMethodName))
            {
                Logger.LogWarning($"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " + method);
                return;
            }

            Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");
            var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
                                                            uniqueMethodName,
                                                            method,
                                                            apiDescription.RelativePath,
                                                            apiDescription.HttpMethod,
                                                            GetSupportedVersions(controllerType, method, setting)
                                                            ));

            AddParameterDescriptionsToModel(actionModel, method, apiDescription);
        }
Example #2
0
        private void AddApiDescriptionToModel(ApiDescription apiDescription, ApplicationApiDescriptionModel model)
        {
            var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
            var setting        = FindSetting(controllerType);

            var moduleModel = model.GetOrAddModule(GetRootPath(controllerType, setting));

            var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);

            var method = apiDescription.ActionDescriptor.GetMethodInfo();

            var uniqueMethodName = GetUniqueActionName(method);

            if (controllerModel.Actions.ContainsKey(uniqueMethodName))
            {
                Logger.LogWarning($"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " + method);
                return;
            }

            var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
                                                            uniqueMethodName,
                                                            method,
                                                            apiDescription.RelativePath,
                                                            apiDescription.HttpMethod,
                                                            setting?.ApiVersions.Select(v => v.ToString()).ToList() ?? new List <string>() //TODO: Also get from ApiVersion attributes if available..?
                                                            ));

            AddParameterDescriptionsToModel(actionModel, method, apiDescription);
        }
        private void AddApiDescriptionToModel(
            ApiDescription apiDescription,
            ApplicationApiDescriptionModel applicationModel,
            ApplicationApiDescriptionModelRequestDto input)
        {
            var controllerType = apiDescription
                                 .ActionDescriptor
                                 .AsControllerActionDescriptor()
                                 .ControllerTypeInfo;

            var setting = FindSetting(controllerType);

            var moduleModel = applicationModel.GetOrAddModule(
                GetRootPath(controllerType, setting),
                GetRemoteServiceName(controllerType, setting)
                );

            var controllerModel = moduleModel.GetOrAddController(
                controllerType.FullName,
                _options.ControllerNameGenerator(controllerType, setting),
                controllerType,
                _modelOptions.IgnoredInterfaces
                );

            var method = apiDescription.ActionDescriptor.GetMethodInfo();

            var uniqueMethodName = _options.ActionNameGenerator(method);

            if (controllerModel.Actions.ContainsKey(uniqueMethodName))
            {
                Logger.LogWarning(
                    $"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " +
                    method);
                return;
            }

            Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");

            var actionModel = controllerModel.AddAction(
                uniqueMethodName,
                ActionApiDescriptionModel.Create(
                    uniqueMethodName,
                    method,
                    apiDescription.RelativePath,
                    apiDescription.HttpMethod,
                    GetSupportedVersions(controllerType, method, setting)
                    )
                );

            if (input.IncludeTypes)
            {
                AddCustomTypesToModel(applicationModel, method);
            }

            AddParameterDescriptionsToModel(actionModel, method, apiDescription);
        }
    private void AddApiDescriptionToModel(
        ApiDescription apiDescription,
        ApplicationApiDescriptionModel applicationModel,
        ApplicationApiDescriptionModelRequestDto input)
    {
        var controllerType = apiDescription
                             .ActionDescriptor
                             .AsControllerActionDescriptor()
                             .ControllerTypeInfo;

        var setting = FindSetting(controllerType);

        var moduleModel = applicationModel.GetOrAddModule(
            GetRootPath(controllerType, setting),
            GetRemoteServiceName(controllerType, setting)
            );

        var controllerModel = moduleModel.GetOrAddController(
            _options.ControllerNameGenerator(controllerType, setting),
            FindGroupName(controllerType) ?? apiDescription.GroupName,
            controllerType,
            _modelOptions.IgnoredInterfaces
            );

        var method = apiDescription.ActionDescriptor.GetMethodInfo();

        var uniqueMethodName = _options.ActionNameGenerator(method);

        if (controllerModel.Actions.ContainsKey(uniqueMethodName))
        {
            Logger.LogWarning(
                $"Controller '{controllerModel.ControllerName}' contains more than one action with name '{uniqueMethodName}' for module '{moduleModel.RootPath}'. Ignored: " +
                method);
            return;
        }

        Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");

        bool?allowAnonymous = null;

        if (apiDescription.ActionDescriptor.EndpointMetadata.Any(x => x is IAllowAnonymous))
        {
            allowAnonymous = true;
        }
        else if (apiDescription.ActionDescriptor.EndpointMetadata.Any(x => x is IAuthorizeData))
        {
            allowAnonymous = false;
        }

        var implementFrom = controllerType.FullName;

        var interfaceType = controllerType.GetInterfaces().FirstOrDefault(i => i.GetMethods().Any(x => x.ToString() == method.ToString()));

        if (interfaceType != null)
        {
            implementFrom = TypeHelper.GetFullNameHandlingNullableAndGenerics(interfaceType);
        }

        var actionModel = controllerModel.AddAction(
            uniqueMethodName,
            ActionApiDescriptionModel.Create(
                uniqueMethodName,
                method,
                apiDescription.RelativePath,
                apiDescription.HttpMethod,
                GetSupportedVersions(controllerType, method, setting),
                allowAnonymous,
                implementFrom
                )
            );

        if (input.IncludeTypes)
        {
            AddCustomTypesToModel(applicationModel, method);
        }

        AddParameterDescriptionsToModel(actionModel, method, apiDescription);
    }