Example #1
0
        private void HandleAsObjectParameters(SwaggerOperation operation, DotvvmTypeScriptOperationModel model, SwaggerToTypeScriptClientGeneratorSettings settings)
        {
            // find groups of parameters that should be treated as one
            var parameters = model.QueryParameters.Where(p => p.Name.Contains('.') && p.Schema.ExtensionData.ContainsKey(ApiConstants.DotvvmWrapperTypeKey));
            var groups     = parameters.GroupBy(p => p.Name.Substring(0, p.Name.IndexOf('.'))).ToList();

            foreach (var group in groups)
            {
                var swaggerParameter = new SwaggerParameter()
                {
                    Name   = group.Key,
                    Schema = new JsonSchema4(),
                    Kind   = SwaggerParameterKind.Query
                };
                var newParameter = new DotvvmTypeScriptParameterModel(group.Key, group.Key, "any", swaggerParameter, operation.Parameters, settings, this, model)
                {
                    ExcludeFromQuery = true
                };
                var targetIndex = group.Min(p => model.Parameters.IndexOf(p));
                foreach (var p in group)
                {
                    ((DotvvmTypeScriptParameterModel)p).CustomInitializer = $"let {p.VariableName} = ({group.Key} !== null && typeof {group.Key} === 'object') ? {p.Name} : null;";
                }
                model.Parameters.Insert(targetIndex, newParameter);
            }
        }
 public DotvvmTypeScriptParameterModel(string parameterName, string variableName, string typeName, SwaggerParameter parameter,
                                       IList <SwaggerParameter> allParameters, SwaggerToTypeScriptClientGeneratorSettings settings, SwaggerToTypeScriptClientGenerator generator,
                                       DotvvmTypeScriptOperationModel operation)
     : base(parameterName, variableName, typeName, parameter, allParameters, settings, generator)
 {
     this.operation = operation;
 }
Example #3
0
        protected override TypeScriptOperationModel CreateOperationModel(SwaggerOperation operation, ClientGeneratorBaseSettings settings)
        {
            var model = new DotvvmTypeScriptOperationModel(operation, Settings, this, resolver);

            HandleAsObjectParameters(operation, model, (SwaggerToTypeScriptClientGeneratorSettings)settings);
            return(model);
        }