/// <inheritdoc /> public override string GetPathItemName(OpenApiConvertSettings settings, HashSet <string> parameters) { Utils.CheckArgumentNull(settings, nameof(settings)); // Use the output key/template mapping if (KeyMappings != null) { if (KeyMappings.Count == 1) { var key = KeyMappings.First(); return($"{{{key.Value}}}"); } else { IList <string> keyStrings = new List <string>(); foreach (var key in KeyMappings) { keyStrings.Add(key.Key + "={" + key.Value + "}"); } return(String.Join(",", keyStrings)); } } IList <IEdmStructuralProperty> keys = EntityType.Key().ToList(); if (keys.Count() == 1) { string keyName = keys.First().Name; if (settings.PrefixEntityTypeNameBeforeKey) { string name = Utils.GetUniqueName(EntityType.Name + "-" + keyName, parameters); return("{" + name + "}"); } else { string name = Utils.GetUniqueName(keyName, parameters); return("{" + name + "}"); } } else { IList <string> keyStrings = new List <string>(); foreach (var keyProperty in keys) { string name = Utils.GetUniqueName(keyProperty.Name, parameters); keyStrings.Add(keyProperty.Name + "={" + name + "}"); } return(String.Join(",", keyStrings)); } }
/// <inheritdoc /> public override string GetPathItemName(OpenApiConvertSettings settings, HashSet <string> parameters) { Utils.CheckArgumentNull(settings, nameof(settings)); // Use the output key/template mapping if (KeyMappings != null) { if (KeyMappings.Count == 1) { var key = KeyMappings.First(); return($"{{{key.Value}}}"); } else { return(string.Join(",", KeyMappings.Select(x => x.Key + "='{" + x.Value + "}'"))); } } IList <IEdmStructuralProperty> keys = EntityType.Key().ToList(); if (keys.Count() == 1) { string keyName = keys.First().Name; if (settings.PrefixEntityTypeNameBeforeKey) { string name = Utils.GetUniqueName(EntityType.Name + "-" + keyName, parameters); return("{" + name + "}"); } else { string name = Utils.GetUniqueName(keyName, parameters); return("{" + name + "}"); } } else { IList <string> keyStrings = new List <string>(); foreach (var keyProperty in keys) { string name = Utils.GetUniqueName(keyProperty.Name, parameters); var quote = keyProperty.Type.Definition.ShouldPathParameterBeQuoted(settings) ? "'" : string.Empty; keyStrings.Add($"{keyProperty.Name}={quote}{{{name}}}{quote}"); } return(String.Join(",", keyStrings)); } }
/// <summary> /// Initializes a new instance of the <see cref="KeySegmentTemplate" /> class. /// </summary> /// <param name="segment">The key segment, it should be a template key segment.</param> public KeySegmentTemplate(KeySegment segment) { if (segment == null) { throw Error.ArgumentNull(nameof(segment)); } NavigationSource = segment.NavigationSource; EntityType = segment.EdmType as IEdmEntityType; KeyMappings = BuildKeyMappings(segment.Keys, EntityType); Literal = KeyMappings.Count == 1 ? $"{{{KeyMappings.First().Value}}}" : string.Join(",", KeyMappings.Select(a => $"{a.Key}={{{a.Value}}}")); }
/// <summary> /// Initializes a new instance of the <see cref="KeySegmentTemplate" /> class. /// </summary> /// <param name="keys">The input key mappings, the key string is case-sensitive, the value string should wrapper with { and }.</param> /// <param name="entityType">The declaring type containes the key.</param> /// <param name="navigationSource">The navigation source. It could be null.</param> public KeySegmentTemplate(IDictionary <string, string> keys, IEdmEntityType entityType, IEdmNavigationSource navigationSource) { if (keys == null) { throw Error.ArgumentNull(nameof(keys)); } EntityType = entityType ?? throw Error.ArgumentNull(nameof(entityType)); NavigationSource = navigationSource; KeyMappings = BuildKeyMappings(keys.Select(kvp => new KeyValuePair <string, object>(kvp.Key, kvp.Value)), entityType); Literal = KeyMappings.Count == 1 ? $"{{{KeyMappings.First().Value}}}" : string.Join(",", KeyMappings.Select(a => $"{a.Key}={{{a.Value}}}")); }
/// <summary> /// Initializes a new instance of the <see cref="KeySegmentTemplate" /> class. /// </summary> /// <param name="segment">The key segment, it should be a template key segment.</param> public KeySegmentTemplate(KeySegment segment) { if (segment == null) { throw Error.ArgumentNull(nameof(segment)); } NavigationSource = segment.NavigationSource; EntityType = segment.EdmType as IEdmEntityType; KeyProperties = EntityType.Key().ToDictionary(k => k.Name, k => (IEdmProperty)k); KeyMappings = BuildKeyMappings(segment.Keys, EntityType, KeyProperties); _keyLiteral = KeyMappings.Count == 1 ? $"{{{KeyMappings.First().Value}}}" : string.Join(",", KeyMappings.Select(a => $"{a.Key}={{{a.Value}}}")); }