private void UpdateUseDtoClassAndDataConversionCodeProperties(IEnumerable <OperationModel> operations)
        {
            foreach (var operation in operations)
            {
                foreach (var parameter in operation.Parameters)
                {
                    if (parameter.IsDictionary)
                    {
                        if (parameter.Schema.AdditionalPropertiesSchema != null)
                        {
                            var itemTypeName = _resolver.Resolve(parameter.Schema.AdditionalPropertiesSchema, false, string.Empty);
                            parameter.UseDtoClass = Settings.TypeScriptGeneratorSettings.GetTypeStyle(itemTypeName) != TypeScriptTypeStyle.Interface &&
                                                    _resolver.HasTypeGenerator(itemTypeName);
                        }
                    }
                    else if (parameter.IsArray)
                    {
                        if (parameter.Schema.Item != null)
                        {
                            var itemTypeName = _resolver.Resolve(parameter.Schema.Item, false, string.Empty);
                            parameter.UseDtoClass = Settings.TypeScriptGeneratorSettings.GetTypeStyle(itemTypeName) != TypeScriptTypeStyle.Interface &&
                                                    _resolver.HasTypeGenerator(itemTypeName);
                        }
                    }
                    else
                    {
                        parameter.UseDtoClass = Settings.TypeScriptGeneratorSettings.GetTypeStyle(parameter.Type) != TypeScriptTypeStyle.Interface &&
                                                _resolver.HasTypeGenerator(parameter.Type);
                    }
                }

                foreach (var response in operation.Responses.Where(r => r.HasType))
                {
                    response.UseDtoClass        = Settings.TypeScriptGeneratorSettings.GetTypeStyle(response.Type) != TypeScriptTypeStyle.Interface;
                    response.DataConversionCode = DataConversionGenerator.RenderConvertToClassCode(new DataConversionParameters
                    {
                        Variable           = "result" + response.StatusCode,
                        Value              = "resultData" + response.StatusCode,
                        Schema             = response.ActualResponseSchema,
                        IsPropertyNullable = response.IsNullable,
                        TypeNameHint       = string.Empty,
                        Resolver           = _resolver
                    });
                }

                if (operation.HasDefaultResponse && operation.DefaultResponse.HasType)
                {
                    operation.DefaultResponse.UseDtoClass        = Settings.TypeScriptGeneratorSettings.GetTypeStyle(operation.DefaultResponse.Type) != TypeScriptTypeStyle.Interface;
                    operation.DefaultResponse.DataConversionCode = DataConversionGenerator.RenderConvertToClassCode(new DataConversionParameters
                    {
                        Variable           = "result",
                        Value              = "resultData",
                        Schema             = operation.DefaultResponse.ActualResponseSchema,
                        IsPropertyNullable = operation.DefaultResponse.IsNullable,
                        TypeNameHint       = string.Empty,
                        Resolver           = _resolver
                    });
                }
            }
        }
Example #2
0
        private void UpdateUseDtoClassAndDataConversionCodeProperties(IEnumerable <TypeScriptOperationModel> operations)
        {
            // TODO: Remove this method => move to appropriate location

            foreach (var operation in operations)
            {
                foreach (var response in operation.Responses.Where(r => r.HasType))
                {
                    response.DataConversionCode = DataConversionGenerator.RenderConvertToClassCode(new DataConversionParameters
                    {
                        Variable           = "result" + response.StatusCode,
                        Value              = "resultData" + response.StatusCode,
                        Schema             = response.ResolvableResponseSchema,
                        CheckNewableObject = response.IsNullable,
                        IsPropertyNullable = response.IsNullable,
                        TypeNameHint       = string.Empty,
                        Settings           = Settings.TypeScriptGeneratorSettings,
                        Resolver           = _resolver,
                        NullValue          = TypeScriptNullValue.Null
                    });
                }

                if (operation.HasDefaultResponse && operation.DefaultResponse.HasType)
                {
                    operation.DefaultResponse.DataConversionCode = DataConversionGenerator.RenderConvertToClassCode(new DataConversionParameters
                    {
                        Variable           = "result" + operation.DefaultResponse.StatusCode,
                        Value              = "resultData" + operation.DefaultResponse.StatusCode,
                        Schema             = operation.DefaultResponse.ResolvableResponseSchema,
                        CheckNewableObject = operation.DefaultResponse.IsNullable,
                        IsPropertyNullable = operation.DefaultResponse.IsNullable,
                        TypeNameHint       = string.Empty,
                        Settings           = Settings.TypeScriptGeneratorSettings,
                        Resolver           = _resolver,
                        NullValue          = TypeScriptNullValue.Null
                    });
                }
            }
        }