private OpenApiPathItem Add(string method, string permission, string path, Action <OpenApiOperation> updater) { var operations = document.Paths.GetOrAddNew($"{appPath}/{schemaPath}{path}"); var operation = new OpenApiOperation { Security = new List <OpenApiSecurityRequirement> { new OpenApiSecurityRequirement { [Constants.SecurityDefinition] = new[] { Permissions.ForApp(permission, appName, schemaPath).Id } } } }; updater(operation); operations[method] = operation; if (path.StartsWith("/{id}", StringComparison.OrdinalIgnoreCase)) { operation.AddPathParameter("id", JsonObjectType.String, $"The id of the {schemaName} content."); operation.AddResponse("404", $"App, schema or {schemaName} content not found."); } return(operations); }
private static void AddErrorResponses(OpenApiOperation operation, JsonSchema errorSchema) { if (!operation.Responses.ContainsKey("500")) { operation.AddResponse("500", "Operation failed", errorSchema); } foreach (var(code, response) in operation.Responses) { if (code != "404" && code.StartsWith("4", StringComparison.OrdinalIgnoreCase) && response.Schema == null) { response.Schema = errorSchema; } } }
private OpenApiPathItem AddOperation(string method, string entityName, string path, Action <OpenApiOperation> updater) { var operations = document.Paths.GetOrAddNew(path); var operation = new OpenApiOperation(); 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); }