diff --git a/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolver.cs b/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolver.cs index d2784729..ab77d6ae 100644 --- a/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolver.cs +++ b/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolver.cs @@ -20,15 +20,18 @@ protected ActionTargetDefinitionResolver(ISchemaRegistry schemaRegistry, ILogger #endregion #region Abstract Methods - public abstract bool TryResolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary readOnlyDictionary, ICollection bodyParameters, out T actionTargetDefinition) where T : ActionTargetDefinition, new(); + public abstract bool TryResolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary readOnlyDictionary, ICollection bodyParameters, ActionRequestBody requestBody, out T actionTargetDefinition) where T : ActionTargetDefinition, new(); #endregion #region Protected Methods - protected T CreateActionTargetDefinition(ActionTarget actionTarget, IReadOnlyDictionary pathParameters) where T : ActionTargetDefinition, new() + protected T CreateActionTargetDefinition(ActionTarget actionTarget, IReadOnlyDictionary pathParameters, ActionRequestBody requestBody) where T : ActionTargetDefinition, new() { T actionTargetDefinition = new T(); actionTargetDefinition.Target = actionTarget; actionTargetDefinition.PathParameters.AddRange(pathParameters); + if (requestBody?.Contract != null) + actionTargetDefinition.Parameters.Add(new ActionParameter("body", "body", requestBody.Contract, ActionParameterLocation.Body, isRequired: true, isOutput: false, defaultValue: null, sourceLocation: requestBody.Contract.Location, source: null)); + return actionTargetDefinition; } diff --git a/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolverFacade.cs b/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolverFacade.cs index 266e501f..a0bd1821 100644 --- a/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolverFacade.cs +++ b/src/Dibix.Sdk.CodeGeneration/Lookup/ActionTargetDefinitionResolverFacade.cs @@ -34,11 +34,11 @@ string productName }; } - public T Resolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters) where T : ActionTargetDefinition, new() + public T Resolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, ActionRequestBody requestBody) where T : ActionTargetDefinition, new() { foreach (ActionTargetDefinitionResolver resolver in this._resolvers) { - if (resolver.TryResolve(targetName, sourceLocation, explicitParameters, pathParameters, bodyParameters, out T definition)) + if (resolver.TryResolve(targetName, sourceLocation, explicitParameters, pathParameters, bodyParameters, requestBody, out T definition)) return definition; } diff --git a/src/Dibix.Sdk.CodeGeneration/Lookup/ExternalReflectionActionTargetDefinitionResolver.cs b/src/Dibix.Sdk.CodeGeneration/Lookup/ExternalReflectionActionTargetDefinitionResolver.cs index e93b3669..d2ce595f 100644 --- a/src/Dibix.Sdk.CodeGeneration/Lookup/ExternalReflectionActionTargetDefinitionResolver.cs +++ b/src/Dibix.Sdk.CodeGeneration/Lookup/ExternalReflectionActionTargetDefinitionResolver.cs @@ -15,7 +15,7 @@ public ExternalReflectionActionTargetDefinitionResolver(ISchemaRegistry schemaRe this._lockEntryManager = lockEntryManager; } - public override bool TryResolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, out T actionTargetDefinition) + public override bool TryResolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, ActionRequestBody requestBody, out T actionTargetDefinition) { string[] parts = targetName.Split(','); if (parts.Length != 2) @@ -57,7 +57,7 @@ public override bool TryResolve(string targetName, SourceLocation sourceLocat */ ActionTarget actionTarget = new ReflectionActionTarget(assemblyName, typeName, methodName, isAsync: false, hasRefParameters: false, sourceLocation); - actionTargetDefinition = CreateActionTargetDefinition(actionTarget, pathParameters); + actionTargetDefinition = CreateActionTargetDefinition(actionTarget, pathParameters, requestBody); ActionParameterRegistry parameterRegistry = new ActionParameterRegistry(actionTargetDefinition, pathParameters); foreach (ExplicitParameter parameter in explicitParameters.Values) { diff --git a/src/Dibix.Sdk.CodeGeneration/Lookup/IActionTargetDefinitionResolverFacade.cs b/src/Dibix.Sdk.CodeGeneration/Lookup/IActionTargetDefinitionResolverFacade.cs index b79b7128..82e9c289 100644 --- a/src/Dibix.Sdk.CodeGeneration/Lookup/IActionTargetDefinitionResolverFacade.cs +++ b/src/Dibix.Sdk.CodeGeneration/Lookup/IActionTargetDefinitionResolverFacade.cs @@ -4,6 +4,6 @@ namespace Dibix.Sdk.CodeGeneration { internal interface IActionTargetDefinitionResolverFacade { - T Resolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters) where T : ActionTargetDefinition, new(); + T Resolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, ActionRequestBody requestBody) where T : ActionTargetDefinition, new(); } } \ No newline at end of file diff --git a/src/Dibix.Sdk.CodeGeneration/Lookup/SqlStatementDefinitionActionTargetDefinitionResolver.cs b/src/Dibix.Sdk.CodeGeneration/Lookup/SqlStatementDefinitionActionTargetDefinitionResolver.cs index 78afbab4..570a0c19 100644 --- a/src/Dibix.Sdk.CodeGeneration/Lookup/SqlStatementDefinitionActionTargetDefinitionResolver.cs +++ b/src/Dibix.Sdk.CodeGeneration/Lookup/SqlStatementDefinitionActionTargetDefinitionResolver.cs @@ -32,7 +32,7 @@ string productName #endregion #region Overrides - public override bool TryResolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, out T actionTargetDefinition) + public override bool TryResolve(string targetName, SourceLocation sourceLocation, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, ActionRequestBody requestBody, out T actionTargetDefinition) { if (!TryGetStatementDefinitionByProbing(targetName, out SqlStatementDefinition statementDefinition)) { @@ -47,7 +47,7 @@ public override bool TryResolve(string targetName, SourceLocation sourceLocat bool isAsync = statementDefinition.Async; bool hasRefParameters = statementDefinition.Parameters.Any(x => x.IsOutput); ActionTarget actionTarget = new LocalActionTarget(statementDefinition, localAccessorFullName, externalAccessorFullName, definitionName, isAsync, hasRefParameters, sourceLocation); - actionTargetDefinition = CreateActionTargetDefinition(actionTarget, pathParameters); + actionTargetDefinition = CreateActionTargetDefinition(actionTarget, pathParameters, requestBody); ActionParameterRegistry parameterRegistry = new ActionParameterRegistry(actionTargetDefinition, pathParameters); foreach (SqlQueryParameter parameter in statementDefinition.Parameters) { diff --git a/src/Dibix.Sdk.CodeGeneration/Output/ApiControllerClassWriter.cs b/src/Dibix.Sdk.CodeGeneration/Output/ApiControllerClassWriter.cs index 953c20df..3095662e 100644 --- a/src/Dibix.Sdk.CodeGeneration/Output/ApiControllerClassWriter.cs +++ b/src/Dibix.Sdk.CodeGeneration/Output/ApiControllerClassWriter.cs @@ -64,7 +64,7 @@ private static void AddMethods(CSharpClass @class, CodeGenerationContext context CSharpMethod method; if (isImplementation) { - ICollection parameterNames = parameters.Select(x => x.InternalParameterName).ToList(); + IList parameterNames = parameters.Select(x => x.InternalParameterName).ToList(); parameterNames.Add("cancellationToken"); string body = $"return {methodImplementationName}({String.Join(", ", parameterNames)});"; method = @class.AddMethod(name: methodName, returnType: returnTypeName, body); diff --git a/src/Dibix.Sdk.CodeGeneration/Registration/ControllerDefinitionProvider.cs b/src/Dibix.Sdk.CodeGeneration/Registration/ControllerDefinitionProvider.cs index fa0c646f..91260b35 100644 --- a/src/Dibix.Sdk.CodeGeneration/Registration/ControllerDefinitionProvider.cs +++ b/src/Dibix.Sdk.CodeGeneration/Registration/ControllerDefinitionProvider.cs @@ -120,7 +120,7 @@ private void ReadControllerAction(ControllerDefinition controller, JObject actio IReadOnlyDictionary explicitParameters = CollectExplicitParameters(action, requestBody, pathParameters); // Resolve action target, parameters and create action definition - ActionDefinition actionDefinition = CreateActionDefinition(action, explicitParameters, pathParameters, bodyParameters); + ActionDefinition actionDefinition = CreateActionDefinition(action, explicitParameters, pathParameters, bodyParameters, requestBody); if (actionDefinition == null) return; @@ -531,7 +531,7 @@ private void CollectAuthorization(JProperty templateProperty, JObject authorizat IReadOnlyDictionary explicitParameters = CollectExplicitParameters(authorization, requestBody: null, pathParameters); ICollection bodyParameters = new Collection(); - actionDefinition.Authorization = CreateActionDefinition(authorization, explicitParameters, pathParameters, bodyParameters); + actionDefinition.Authorization = CreateActionDefinition(authorization, explicitParameters, pathParameters, bodyParameters, requestBody: null); } private JObject ApplyAuthorizationTemplate(JProperty templateNameProperty, JObject authorizationTemplateReference) @@ -564,11 +564,11 @@ private JObject ApplyAuthorizationTemplate(JProperty templateNameProperty, JObje return mergedAuthorization; } - private T CreateActionDefinition(JObject action, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters) where T : ActionTargetDefinition, new() + private T CreateActionDefinition(JObject action, IReadOnlyDictionary explicitParameters, IReadOnlyDictionary pathParameters, ICollection bodyParameters, ActionRequestBody requestBody) where T : ActionTargetDefinition, new() { JValue targetValue = (JValue)action.Property("target").Value; SourceLocation sourceInfo = targetValue.GetSourceInfo(); - T actionDefinition = _actionTargetResolver.Resolve(targetName: (string)targetValue, sourceInfo, explicitParameters, pathParameters, bodyParameters); + T actionDefinition = _actionTargetResolver.Resolve(targetName: (string)targetValue, sourceInfo, explicitParameters, pathParameters, bodyParameters, requestBody); return actionDefinition; } #endregion