public Parameter GetMetadata(PropertyInfo propInfo)
        {
            string parentTypeName = Inflector.MakeInitialLowerCase(propInfo.DeclaringType?.Name);

            // check if the resource properties are required if they exist.
            // in the case where a child object has no definition (its a ref in the swagger document)
            // then the result will be null.
            // (note this may be a moot point) with the definitions below.
            var parameter = _resourceDictionary.Values.FirstOrDefault(
                r =>
                TypeNameHelper.CompareTypeNames(r.Name, parentTypeName, string.Empty, _schemaNames))
                            ?.Definition
                            .required
                            .FirstOrDefault(
                p => p.Equals(
                    Regex.Replace(propInfo.Name, @"_", string.Empty),
                    StringComparison.InvariantCultureIgnoreCase));

            // check for any definition if we could not find the the property from the resource
            if (parameter == null)
            {
                parameter = _entityDictionary.Values
                            .FirstOrDefault(r => r.Name.Equals(parentTypeName, StringComparison.InvariantCultureIgnoreCase))
                            ?.Definition
                            .required
                            ?.FirstOrDefault(
                    p => p.Equals(
                        Regex.Replace(propInfo.Name, @"_", string.Empty),
                        StringComparison.InvariantCultureIgnoreCase));
            }

            return(new Parameter {
                required = parameter != null
            });
        }
Ejemplo n.º 2
0
        public void MakeInitialLowerCase_test()
        {
            const string source   = "TheQuickBrownFoxJumpedOverTheLazyDog";
            const string expected = "theQuickBrownFoxJumpedOverTheLazyDog";
            var          result   = Inflector.MakeInitialLowerCase(source);

            Assert.AreEqual(expected, result);
        }
        public override bool BuildProperty(object obj, PropertyInfo propertyInfo)
        {
            string parentTypeName = Inflector.MakeInitialLowerCase(propertyInfo.DeclaringType?.Name);

            if (obj.GetType().Name.Contains("EducationOrganizationAddress") && _requiredProperties.Any(x => x.Equals(propertyInfo.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                propertyInfo.SetValue(obj, RandomTestString);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public Task <bool> Process(XmlLookupWorkItem item)
        {
            var match = _lookupRegex.Match(item.LookupXElement.Name.LocalName);

            if (!match.Success)
            {
                return(Task.FromResult(false));
            }

            item.ResourceName     = match.Groups["TypeName"].Value;
            item.IdentityName     = $"{item.ResourceName}Identity";
            item.LookupName       = $"{item.ResourceName}Lookup";
            item.JsonResourceName = Inflector.MakePlural(Inflector.MakeInitialLowerCase(item.ResourceName));
            item.JsonModelName    = Inflector.MakeInitialLowerCase(item.ResourceName);
            return(Task.FromResult(true));
        }
        protected override IEnumerable <MetadataMapping> CreateMappings()
        {
            Log.Info("Creating XSD Resource to Json Identity data mappings");
            var typeNames = XmlMetadata.Select(x => x.Type).Distinct().Where(x => _typeRegex.IsMatch(x));

            var mappings = typeNames.Select(
                x =>
            {
                var typeName = _typeRegex.Match(x).Groups["TypeName"].Value;

                return(new MetadataMapping
                {
                    RootName = typeName, SourceName = x,                  //xml
                    TargetName = Inflector.MakeInitialLowerCase(typeName) //json
                });
            }).ToArray();

            return(mappings);
        }