/// <summary>Gets the operation name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The operation name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var clientName = GetClientName(operation); var operationName = GetOperationName(operation); var hasOperationWithSameName = document.Operations .Where(o => o.Operation != operation) .Any(o => GetClientName(o.Operation) == clientName && GetOperationName(o.Operation) == operationName); if (hasOperationWithSameName) { if (operationName.ToLowerInvariant().StartsWith("get")) { var isArrayResponse = operation.Responses.ContainsKey("200") && operation.Responses["200"].ActualResponseSchema != null && operation.Responses["200"].ActualResponseSchema.Type.HasFlag(JsonObjectType.Array); if (isArrayResponse) { return("GetAll" + operationName.Substring(3)); } } } return(operationName); }
/// <summary>Gets the client name for a given operation (may be empty).</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(path .Split('/') .Where(p => !p.Contains("{") && !string.IsNullOrWhiteSpace(p)) .Reverse() .FirstOrDefault() ?? "Index"); }
/// <summary> /// Create a new <see cref="JabApiOperation"/> /// </summary> /// <param name="service"></param> /// <param name="path"></param> /// <param name="method"></param> /// <param name="operation"></param> public JabApiOperation(SwaggerService service, string path, SwaggerOperationMethod method, SwaggerOperation operation) { Service = service; Path = path; Method = method; Operation = operation; }
internal void AddSwaggerOperationFunc(string path, SwaggerOperationMethod method, Func <ISchemaRegistry, Operation> addSwaggerOperation) { SwaggerOperationFuncs.Add(new SwaggerOperationFunc { Path = TopPath + path, Method = method, AddSwaggerOperation = addSwaggerOperation }); }
/// <summary>Gets the client name for a given operation (may be empty).</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public virtual string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(path .Split('/') .Where(p => !p.Contains("{") && !string.IsNullOrWhiteSpace(p)) .Reverse() .Skip(1) .FirstOrDefault() ?? string.Empty); }
public RequestDelegate GetValidatorDelegate(SwaggerOperationMethod method, SwaggerOperation operation) { var parameterValidator = new SwaggerValidator(); return(context => { var errors = parameterValidator.Validate(context, operation); if (errors.Any()) { context.Response.StatusCode = StatusCodes.Status400BadRequest; return context.Response.WriteAsync(JsonConvert.SerializeObject(errors)); } return context.Response.WriteAsync(@"{ ""status"": ""ok""}"); }); }
/// <summary>Gets the client name for a given operation (may be empty).</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var operationName = ConvertPathToName(path); var hasNameConflict = document.Paths .SelectMany(pair => pair.Value.Select(p => new { Path = pair.Key.Trim('/'), HttpMethod = p.Key, Operation = p.Value })) .Where(op => GetClientName(document, op.Path, op.HttpMethod, op.Operation) == GetClientName(document, path, httpMethod, operation) && ConvertPathToName(op.Path) == operationName ) .ToList().Count > 1; if (hasNameConflict) { operationName += CapitalizeFirst(httpMethod.ToString()); } return(operationName); }
private SwaggerOperations AddOperation(SwaggerOperationMethod method, string entityName, string path, Action <SwaggerOperation> updater) { var operations = document.Paths.GetOrAddNew(path); var operation = new SwaggerOperation(); updater(operation); operations[method] = operation; if (entityName != null) { operation.AddPathParameter("id", JsonObjectType.String, $"The id of the {entityName} content (GUID)."); operation.AddResponse("404", $"App, schema or {entityName} content not found."); } return(operations); }
internal Operation CreateOperation(string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(new Operation() { Name = operation.OperationId, Summary = operation.Summary, Path = path, HttpMethod = GetHttpMethod(httpMethod), Parameters = operation.ActualParameters.Select(parameter => new OperationParameter() { Name = parameter.Name, Description = parameter.Description, Location = GetOperationParameterLocation(parameter.Kind), Type = GetType(parameter.Kind == SwaggerParameterKind.Body ? parameter.Schema : parameter), IsRequired = parameter.IsRequired }).ToList(), ResponseType = operation.Responses .Where(response => response.Key == "200") .Select(response => response.Value.Schema) .Select(schema => schema == null ? null : GetType(schema)) .FirstOrDefault() }); }
private static RequestMethod GetHttpMethod(SwaggerOperationMethod method) { switch (method) { case SwaggerOperationMethod.Undefined: throw new ArgumentException(nameof(method)); case SwaggerOperationMethod.Get: return(RequestMethod.Get); case SwaggerOperationMethod.Post: return(RequestMethod.Post); case SwaggerOperationMethod.Put: return(RequestMethod.Put); case SwaggerOperationMethod.Delete: return(RequestMethod.Delete); case SwaggerOperationMethod.Options: return(RequestMethod.Options); case SwaggerOperationMethod.Head: return(RequestMethod.Head); case SwaggerOperationMethod.Patch: return(RequestMethod.Patch); default: throw new NotImplementedException(); } }
/// <summary>Gets the operation name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The operation name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var clientName = GetClientName(operation); var operationName = GetOperationName(operation); var hasOperationWithSameName = document.Operations .Where(o => o.Operation != operation) .Any(o => GetClientName(o.Operation) == clientName && GetOperationName(o.Operation) == operationName); if (hasOperationWithSameName) { if (operationName.ToLowerInvariant().StartsWith("get")) { var isArrayResponse = operation.Responses.ContainsKey("200") && operation.Responses["200"].Schema != null && operation.Responses["200"].Schema.Type.HasFlag(JsonObjectType.Array); if (isArrayResponse) return "GetAll" + operationName.Substring(3); } } return operationName; }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray(); return pathSegments.Length >= 2 ? pathSegments[1] : string.Empty; }
private ApplicationAPIModel GenerateBasicModel(SwaggerOperation Operation, SwaggerOperationMethod method, ref bool supportBody, string path) { ApplicationAPIModel AAM = new ApplicationAPIModel(); System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("{[a-zA-Z]*}"); foreach (var Match in reg.Matches(path)) { string modal = "<" + Match.ToString().ToUpper() + ">"; path = path.Replace(Match.ToString(), modal); AAM.AppModelParameters.Add(new AppModelParameter(modal, Match.ToString() + "in url", "", "", new ObservableList <OptionalValue>())); } AAM.EndpointURL = Swaggerdoc.BaseUrl + path; AAM.APIType = ApplicationAPIUtils.eWebApiType.REST; AAM.Name = Operation.Summary; if (string.IsNullOrWhiteSpace(AAM.Name)) { AAM.Name = Operation.OperationId; } AAM.URLDomain = Swaggerdoc.BaseUrl; supportBody = true; switch (method) { case SwaggerOperationMethod.Get: AAM.RequestType = ApplicationAPIUtils.eRequestType.GET; supportBody = false; break; case SwaggerOperationMethod.Delete: AAM.RequestType = ApplicationAPIUtils.eRequestType.DELETE; break; case SwaggerOperationMethod.Head: AAM.RequestType = ApplicationAPIUtils.eRequestType.Head; break; case SwaggerOperationMethod.Options: AAM.RequestType = ApplicationAPIUtils.eRequestType.Options; break; case SwaggerOperationMethod.Patch: AAM.RequestType = ApplicationAPIUtils.eRequestType.PATCH; break; case SwaggerOperationMethod.Post: AAM.RequestType = ApplicationAPIUtils.eRequestType.POST; break; case SwaggerOperationMethod.Put: AAM.RequestType = ApplicationAPIUtils.eRequestType.PUT; break; case SwaggerOperationMethod.Trace: AAM.RequestType = ApplicationAPIUtils.eRequestType.POST; break; case SwaggerOperationMethod.Undefined: AAM.RequestType = ApplicationAPIUtils.eRequestType.POST; break; } foreach (SwaggerParameter param in Operation.Parameters) { if (param.Kind == SwaggerParameterKind.Header) { string modelName = "<" + param.Name + ">"; APIModelKeyValue header = new APIModelKeyValue(); header.ItemName = param.Name; header.Param = param.Name; header.Value = modelName; AAM.AppModelParameters.Add(new AppModelParameter(modelName, param.Name + " in headers", "", "", new ObservableList <OptionalValue>())); AAM.HttpHeaders.Add(header); } } return(AAM); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray(); return(pathSegments.First()); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray(); return(pathSegments.Length >= 2 ? pathSegments[1] : string.Empty); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray(); return pathSegments.First(); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="service">The Swagger service.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerService service, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { var pathSegments = path.Split('/').Where(p => !p.Contains("{")).Reverse().ToArray(); return(pathSegments.Length >= 1 ? pathSegments[0] : "Unknown"); }
public static HttpMethod ToHttpMethod(this SwaggerOperationMethod method) => _methodMappings[method];
public override string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { if (operation.Tags?.Count == 1) { return(operation.Tags[0]); } return(base.GetClientName(document, path, httpMethod, operation)); }
/// <summary>Gets the client name for a given operation (may be empty).</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(operation.OperationId); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="service">The Swagger service.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetClientName(SwaggerService service, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(GetClientName(operation)); }
/// <summary> /// Gets the operation name for a given operation. /// </summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns> /// The operation name. /// </returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return("assadasdasd"); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="service">The Swagger service.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerService service, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(operation.OperationId); }
private static Operation GetSwaggerOperation(IEnumerable <SwaggerOperationFunc> g, ISchemaRegistry schemaRegistry, SwaggerOperationMethod method) { return(g.FirstOrDefault(sof => sof.Method == method)?.AddSwaggerOperation(schemaRegistry)); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return GetClientName(operation); }
/// <summary> /// 获取方法对应的类名 /// </summary> /// <param name="document"></param> /// <param name="path"></param> /// <param name="httpMethod"></param> /// <param name="operation"></param> /// <returns></returns> public override string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(operation.Tags.FirstOrDefault()); }
/// <summary>Gets the client name for a given operation (may be empty).</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(GetClientName(operation)); }
/// <summary>Gets the client name for a given operation (may be empty).</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public virtual string GetClientName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return(string.Empty); }
/// <summary>Gets the client name for a given operation.</summary> /// <param name="document">The Swagger document.</param> /// <param name="path">The HTTP path.</param> /// <param name="httpMethod">The HTTP method.</param> /// <param name="operation">The operation.</param> /// <returns>The client name.</returns> public string GetOperationName(SwaggerDocument document, string path, SwaggerOperationMethod httpMethod, SwaggerOperation operation) { return operation.OperationId; }