Browse Source

Fix OpenAPI for version endpoint and introduce new endpoint.

pull/935/head
Sebastian 4 years ago
parent
commit
fecb3d7d44
  1. 42
      backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs
  2. 8
      backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs

42
backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs

@ -218,6 +218,41 @@ namespace Squidex.Areas.Api.Controllers.Contents
return Ok(response);
}
/// <summary>
/// Get a content by version V2.
/// </summary>
/// <param name="app">The name of the app.</param>
/// <param name="schema">The name of the schema.</param>
/// <param name="id">The ID of the content to fetch.</param>
/// <param name="version">The version fo the content to fetch.</param>
/// <returns>
/// 200 => Content version returned.
/// 404 => Content, schema or app not found.
/// </returns>
/// <remarks>
/// You can read the generated documentation for your app at /api/content/{appName}/docs.
/// </remarks>
[HttpGet]
[Route("content/{app}/{schema}/{id}/v/{version}/")]
[ApiPermissionOrAnonymous(PermissionIds.AppContentsReadOwn)]
[ApiCosts(1)]
public async Task<IActionResult> GetContentVersionV2(string app, string schema, DomainId id, int version)
{
var content = await contentQuery.FindAsync(Context, schema, id, version, HttpContext.RequestAborted);
if (content == null)
{
return NotFound();
}
var response = Deferred.Response(() =>
{
return ContentDto.FromDomain(content, Resources);
});
return Ok(response);
}
/// <summary>
/// Get a content by version.
/// </summary>
@ -245,9 +280,12 @@ namespace Squidex.Areas.Api.Controllers.Contents
return NotFound();
}
var response = ContentDto.FromDomain(content, Resources);
var response = Deferred.Response(() =>
{
return ContentDto.FromDomain(content, Resources).Data;
});
return Ok(response.Data);
return Ok(response);
}
/// <summary>

8
backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs

@ -142,6 +142,14 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator
.OperationSummary("Get a [schema] content item by id and version.")
.HasPath("version", JsonObjectType.Number, FieldDescriptions.EntityVersion)
.HasId()
.Responds(200, "Content item returned.", builder.DataSchema);
builder.AddOperation(OpenApiOperationMethod.Get, "/{id}/v/{version}")
.RequirePermission(PermissionIds.AppContentsReadOwn)
.Operation("GetVersionedV2")
.OperationSummary("Get a [schema] content item by id and version.")
.HasPath("version", JsonObjectType.Number, FieldDescriptions.EntityVersion)
.HasId()
.Responds(200, "Content item returned.", builder.ContentSchema);
builder.AddOperation(OpenApiOperationMethod.Get, "/{id}/validity")

Loading…
Cancel
Save