-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Management API: Add JSON Schema support for data types and content types #21771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,881
−44
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d2441d7
Basic implementaion
Migaroez 8d8b8cf
Tests and schema validation
Migaroez 25972a2
Attemp refactor
Migaroez 1a7b745
Fix json single parent bug
Migaroez a68d392
Surface doctype schema validation to management api
Migaroez a520af8
Improve block schema and make validation errors less verbose
Migaroez f647403
fix validation error cleanup
Migaroez d6fd40d
Improved GUID handling | added schema for all propertyEditors
Migaroez 697c101
Add ContentTypeInputSchema
Migaroez 55bab09
move contenttype schemas to be actual jsonschemas
Migaroez c206e73
Fix block limit on blocklist and grid
Migaroez 1509980
add datatype schema batch
Migaroez a2d019a
Refactoring blocks json schema generation and add to richtext
Migaroez 7e2394f
Package version update and more tests!
Migaroez bdb9dd5
ConvertToJsonNode optimization
Migaroez 225f0e7
async refactor
Migaroez 57eae20
Add editorUiAlias to x-umbraco-properties and make DataType ref route…
Migaroez fd96649
Removed JsonSchema.net due to possible license issues
Migaroez 93c3635
Merge branch 'main' into v17/task/property-editor-schemas
nielslyngsoe c27e287
Merge branch 'main' into v17/task/property-editor-schemas
Migaroez 2baa4fb
Use void editor in the noop schema test
Migaroez 36300a7
Merge branch 'v17/task/property-editor-schemas' of https://github.com…
Migaroez 17dd7c1
Merge branch 'main' into v17/task/property-editor-schemas
AndyButland 7a268b6
Cleanup leftovers from Schema validation removal
Migaroez b23b94b
Move batch logic into batchcontroller
Migaroez 903036b
Update src/Umbraco.Infrastructure/PropertyEditors/BlockJsonSchemaHelp…
Migaroez 7ba2085
Update src/Umbraco.Cms.Api.Management/Services/ContentTypeJsonSchemaS…
Migaroez 5b596c7
Merge branch 'v17/task/property-editor-schemas' of https://github.com…
Migaroez 3599c5b
Merge branch 'v17/task/property-editor-schemas' of https://github.com…
AndyButland a5a4cfa
Fixed build error.
AndyButland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Umbraco.Cms.Api.Management/Controllers/DataType/BatchSchemasDataTypeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.ViewModels; | ||
| using Umbraco.Cms.Api.Management.ViewModels.DataType; | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.DataType; | ||
|
|
||
| /// <summary> | ||
| /// Controller for retrieving multiple data type value schemas in a single request. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class BatchSchemasDataTypeController : DataTypeControllerBase | ||
| { | ||
| private readonly IPropertyEditorSchemaService _schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="BatchSchemasDataTypeController"/> class. | ||
| /// </summary> | ||
| /// <param name="schemaService">The property editor schema service.</param> | ||
| public BatchSchemasDataTypeController(IPropertyEditorSchemaService schemaService) | ||
| => _schemaService = schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Gets the value schemas for multiple data types. | ||
| /// </summary> | ||
| /// <param name="cancellationToken">A cancellation token.</param> | ||
| /// <param name="ids">The unique identifiers of the data types.</param> | ||
| /// <returns>The schema information for the requested data types.</returns> | ||
| /// <remarks> | ||
| /// Returns schema information for property editors that implement <c>IValueSchemaProvider</c>. | ||
| /// Each item includes an error field if the schema could not be retrieved (e.g., data type not found or schema not supported). | ||
| /// </remarks> | ||
| [HttpGet("schemas/batch")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(FetchResponseModel<DataTypeSchemaItemResponseModel>), StatusCodes.Status200OK)] | ||
| public async Task<IActionResult> GetSchemas( | ||
| CancellationToken cancellationToken, | ||
| [FromQuery(Name = "id")] Guid[] ids) | ||
| { | ||
| Guid[] requestedIds = [.. ids.Distinct()]; | ||
|
|
||
| if (requestedIds.Length == 0) | ||
| { | ||
| return Ok(new FetchResponseModel<DataTypeSchemaItemResponseModel>()); | ||
| } | ||
|
|
||
| var items = new List<DataTypeSchemaItemResponseModel>(); | ||
|
|
||
| foreach (Guid id in requestedIds) | ||
| { | ||
| Attempt<PropertyValueSchema, PropertyEditorSchemaOperationStatus> attempt = await _schemaService.GetSchemaAsync(id); | ||
| items.Add(new DataTypeSchemaItemResponseModel | ||
| { | ||
| Id = id, | ||
| ValueTypeName = attempt.Success ? attempt.Result.ValueType?.FullName : null, | ||
| JsonSchema = attempt.Success ? attempt.Result.JsonSchema : null, | ||
| Error = attempt.Success ? null : attempt.Status.ToString(), | ||
| }); | ||
| } | ||
|
|
||
| return Ok(new FetchResponseModel<DataTypeSchemaItemResponseModel> | ||
| { | ||
| Total = items.Count, | ||
| Items = items, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Umbraco.Cms.Api.Management/Controllers/DataType/SchemaDataTypeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.ViewModels.DataType; | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.DataType; | ||
|
|
||
| /// <summary> | ||
| /// Controller for retrieving data type value schemas. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class SchemaDataTypeController : DataTypeControllerBase | ||
| { | ||
| private readonly IPropertyEditorSchemaService _schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SchemaDataTypeController"/> class. | ||
| /// </summary> | ||
| /// <param name="schemaService">The property editor schema service.</param> | ||
| public SchemaDataTypeController(IPropertyEditorSchemaService schemaService) | ||
| => _schemaService = schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Gets the value schema for a data type. | ||
| /// </summary> | ||
| /// <param name="id">The unique identifier of the data type.</param> | ||
| /// <returns>The schema information for the data type's values.</returns> | ||
| /// <remarks> | ||
| /// Returns schema information for property editors that implement <c>IValueSchemaProvider</c>. | ||
| /// Returns 404 if the data type is not found or doesn't support schema information. | ||
| /// </remarks> | ||
| [HttpGet("{id:guid}/schema")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(DataTypeSchemaResponseModel), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| public async Task<IActionResult> Schema(Guid id) | ||
| { | ||
| Attempt<PropertyValueSchema, PropertyEditorSchemaOperationStatus> attempt = await _schemaService.GetSchemaAsync(id); | ||
| if (attempt.Success is false) | ||
| { | ||
| return PropertyEditorSchemaOperationStatusResult(attempt.Status); | ||
| } | ||
|
|
||
| PropertyValueSchema result = attempt.Result; | ||
| return Ok(new DataTypeSchemaResponseModel | ||
| { | ||
| ValueTypeName = result.ValueType?.FullName, | ||
| JsonSchema = result.JsonSchema, | ||
| }); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Umbraco.Cms.Api.Management/Controllers/DocumentType/SchemaDocumentTypeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System.Text.Json.Nodes; | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.DocumentType; | ||
|
|
||
| /// <summary> | ||
| /// Controller for retrieving document type JSON schemas. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class SchemaDocumentTypeController : DocumentTypeControllerBase | ||
| { | ||
| private readonly IContentTypeJsonSchemaService _schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SchemaDocumentTypeController"/> class. | ||
| /// </summary> | ||
| public SchemaDocumentTypeController(IContentTypeJsonSchemaService schemaService) | ||
| => _schemaService = schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Gets a JSON Schema for a specific document type. | ||
| /// </summary> | ||
| /// <param name="id">The unique identifier of the document type.</param> | ||
| /// <returns>A JSON Schema describing the document creation/update payload structure.</returns> | ||
| /// <remarks> | ||
| /// The returned JSON Schema references data type schemas via external <c>$ref</c> URIs. | ||
| /// Tooling should resolve these references by making HTTP requests to the data type schema endpoints. | ||
| /// </remarks> | ||
| [HttpGet("{id:guid}/schema")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(JsonObject), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| public async Task<IActionResult> GetSchema(Guid id) | ||
| { | ||
| JsonObject? schema = await _schemaService.GetDocumentTypeSchemaAsync(id); | ||
| return schema is not null | ||
| ? Ok(schema) | ||
| : OperationStatusResult(ContentTypeOperationStatus.NotFound); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Umbraco.Cms.Api.Management/Controllers/MediaType/SchemaMediaTypeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System.Text.Json.Nodes; | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.MediaType; | ||
|
|
||
| /// <summary> | ||
| /// Controller for retrieving media type JSON schemas. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class SchemaMediaTypeController : MediaTypeControllerBase | ||
| { | ||
| private readonly IContentTypeJsonSchemaService _schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SchemaMediaTypeController"/> class. | ||
| /// </summary> | ||
| public SchemaMediaTypeController(IContentTypeJsonSchemaService schemaService) | ||
| => _schemaService = schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Gets a JSON Schema for a specific media type. | ||
| /// </summary> | ||
| /// <param name="id">The unique identifier of the media type.</param> | ||
| /// <returns>A JSON Schema describing the media creation/update payload structure.</returns> | ||
| /// <remarks> | ||
| /// The returned JSON Schema references data type schemas via external <c>$ref</c> URIs. | ||
| /// Tooling should resolve these references by making HTTP requests to the data type schema endpoints. | ||
| /// </remarks> | ||
| [HttpGet("{id:guid}/schema")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(JsonObject), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| public async Task<IActionResult> GetSchema(Guid id) | ||
| { | ||
| JsonObject? schema = await _schemaService.GetMediaTypeSchemaAsync(id); | ||
| return schema is not null | ||
| ? Ok(schema) | ||
| : OperationStatusResult(ContentTypeOperationStatus.NotFound); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Umbraco.Cms.Api.Management/Controllers/MemberType/SchemaMemberTypeController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System.Text.Json.Nodes; | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Controllers.MemberType; | ||
|
|
||
| /// <summary> | ||
| /// Controller for retrieving member type JSON schemas. | ||
| /// </summary> | ||
| [ApiVersion("1.0")] | ||
| public class SchemaMemberTypeController : MemberTypeControllerBase | ||
| { | ||
| private readonly IContentTypeJsonSchemaService _schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="SchemaMemberTypeController"/> class. | ||
| /// </summary> | ||
| public SchemaMemberTypeController(IContentTypeJsonSchemaService schemaService) | ||
| => _schemaService = schemaService; | ||
|
|
||
| /// <summary> | ||
| /// Gets a JSON Schema for a specific member type. | ||
| /// </summary> | ||
| /// <param name="id">The unique identifier of the member type.</param> | ||
| /// <returns>A JSON Schema describing the member creation/update payload structure.</returns> | ||
| /// <remarks> | ||
| /// The returned JSON Schema references data type schemas via external <c>$ref</c> URIs. | ||
| /// Tooling should resolve these references by making HTTP requests to the data type schema endpoints. | ||
| /// </remarks> | ||
| [HttpGet("{id:guid}/schema")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(typeof(JsonObject), StatusCodes.Status200OK)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] | ||
| public async Task<IActionResult> GetSchema(Guid id) | ||
| { | ||
| JsonObject? schema = await _schemaService.GetMemberTypeSchemaAsync(id); | ||
| return schema is not null | ||
| ? Ok(schema) | ||
| : OperationStatusResult(ContentTypeOperationStatus.NotFound); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Umbraco.Cms.Api.Management/Routing/IManagementApiRouteBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Linq.Expressions; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Routing; | ||
|
|
||
| /// <summary> | ||
| /// Provides URL generation for Management API controllers from non-controller contexts. | ||
| /// </summary> | ||
| public interface IManagementApiRouteBuilder | ||
| { | ||
| /// <summary> | ||
| /// Generates a path to an action on a Management API controller. | ||
| /// </summary> | ||
| /// <typeparam name="TController">The controller type.</typeparam> | ||
| /// <param name="action">Expression selecting the action name (e.g., c => nameof(c.Schema)).</param> | ||
| /// <param name="routeValues">Route values (e.g., new { id = guid }).</param> | ||
| /// <returns>The generated path, or null if the route could not be found.</returns> | ||
| string? GetPathByAction<TController>( | ||
| Expression<Func<TController, string>> action, | ||
| object? routeValues = null); | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/Umbraco.Cms.Api.Management/Routing/ManagementApiRouteBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using System.Linq.Expressions; | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Routing; | ||
| using Microsoft.Extensions.Options; | ||
| using Umbraco.Cms.Api.Management.Controllers; | ||
|
|
||
| namespace Umbraco.Cms.Api.Management.Routing; | ||
|
|
||
| /// <summary> | ||
| /// Provides URL generation for Management API controllers using LinkGenerator. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This service mirrors the CreatedAtId pattern used in ManagementApiControllerBase | ||
| /// but works in non-controller contexts where IUrlHelper is not available. | ||
| /// </remarks> | ||
| internal sealed class ManagementApiRouteBuilder : IManagementApiRouteBuilder | ||
| { | ||
| private readonly LinkGenerator _linkGenerator; | ||
| private readonly ApiVersioningOptions _apiVersioningOptions; | ||
|
|
||
| public ManagementApiRouteBuilder( | ||
| LinkGenerator linkGenerator, | ||
| IOptions<ApiVersioningOptions> apiVersioningOptions) | ||
| { | ||
| _linkGenerator = linkGenerator; | ||
| _apiVersioningOptions = apiVersioningOptions.Value; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public string? GetPathByAction<TController>( | ||
| Expression<Func<TController, string>> action, | ||
| object? routeValues = null) | ||
| { | ||
| if (action.Body is not ConstantExpression constantExpression) | ||
| { | ||
| throw new ArgumentException("Expression must be a constant expression.", nameof(action)); | ||
| } | ||
|
|
||
| var controllerName = ManagementApiRegexes.ControllerTypeToNameRegex() | ||
| .Replace(typeof(TController).Name, string.Empty); | ||
| var actionName = constantExpression.Value?.ToString() | ||
| ?? throw new ArgumentException("Expression does not have a value.", nameof(action)); | ||
|
|
||
| // Merge provided route values with the required API version | ||
| var allRouteValues = new RouteValueDictionary(routeValues) | ||
| { | ||
| ["version"] = _apiVersioningOptions.DefaultApiVersion.MajorVersion?.ToString(), | ||
| }; | ||
|
|
||
| return _linkGenerator.GetPathByAction(actionName, controllerName, allRouteValues); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.