public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription) { // stripping the name string operationName = operation.operationId; if (!string.IsNullOrEmpty(operationName)) { // swashbuckle adds controller name, stripping that int index = operationName.IndexOf("_", 0); if (index >= 0 && (index + 1) < operationName.Length) { operation.operationId = operationName.Substring(index + 1); } } // operation response change IDictionary<string, Response> responses = operation.responses; if (responses != null && !responses.ContainsKey(defaultResponseCode)) { try { string successResponseCode = JsonSwaggerGenerator.GetReturnCodeForSuccess(responses.Keys); Response successResponse = responses[successResponseCode]; Response defaultResponse = new Response(); defaultResponse.description = Resources.DefaultResponseDescription; defaultResponse.schema = null; responses.Add(defaultResponseCode, defaultResponse); } catch(InvalidOperationException) { throw new Exception("No success code found, not adding default response code"); } } }
private static void ApplyResponseComments(Operation operation, XPathNavigator methodNode) { var responseNodes = methodNode.Select(ResponseTag); if (responseNodes.Count > 0) { var successResponse = operation.responses.First().Value; operation.responses.Clear(); while (responseNodes.MoveNext()) { var statusCode = responseNodes.Current.GetAttribute("code", ""); var description = responseNodes.Current.ExtractContent(); var response = new Response { description = description, schema = statusCode.StartsWith("2") ? successResponse.schema : null }; operation.responses[statusCode] = response; } } }