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 }); }
public async Task <bool> PerformTest() { try { var metadata = await _retriever.LoadMetadata(); var t = new[] { "Resources", "Descriptors" }; foreach (var key in metadata.Keys.Where(k => t.Contains(k))) { var doc = metadata[key]; _swaggerDocuments[key] = doc; var uniqueSchemaNames = doc.paths.Keys .Select(GetSchemaNameFromPath) .Distinct() .ToList(); foreach (var path in doc.paths) { if (_resources.ContainsKey(path.Key)) { continue; } _resources[path.Key] = new Resource { Name = GetResoucePath(path.Key, path.Value), BasePath = doc.basePath, Path = path.Value, Schema = GetSchemaNameFromPath(path.Key), Definition = doc .definitions .FirstOrDefault( d => TypeNameHelper.CompareTypeNames(path.Key, d.Key, "_", uniqueSchemaNames)) .Value }; } foreach (var definition in doc.definitions) { if (_entities.ContainsKey(definition.Key)) { continue; } string[] nameParts = definition.Key.Split('_'); _entities[definition.Key] = new Entity { Name = definition.Key.Replace("_", string.Empty), Schema = nameParts[0], Definition = definition.Value }; } foreach (var schemaName in uniqueSchemaNames) { if (!_schemaNames.Contains(schemaName)) { _schemaNames.Add(schemaName); } } Log.Info("Success"); } return(true); } catch (Exception ex) { Log.Error(ex); throw; } }