From 9fc1d7871dbf8787f6b5a3988a0b28efba01561e Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 1 Feb 2022 17:28:27 +0100 Subject: [PATCH] Feature/more openapi tests (#837) * More OpenAPI tests * Open API improvements. --- .../FieldDescriptions.Designer.cs | 8 +++--- .../FieldDescriptions.resx | 6 ++-- .../GenerateJsonSchema/ContentJsonSchema.cs | 5 ++-- .../Controllers/Contents/Generator/Builder.cs | 4 +-- .../Generator/SchemasOpenApiGenerator.cs | 4 +-- .../TestSuite.ApiTests/OpenApiTests.cs | 28 ++++++++++++++++--- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.Designer.cs b/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.Designer.cs index 09453fc43..f0e515514 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.Designer.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.Designer.cs @@ -448,11 +448,11 @@ namespace Squidex.Domain.Apps.Core { } /// - /// Looks up a localized string similar to The name of the schema.. + /// Looks up a localized string similar to The display name of the schema.. /// - public static string ContentSchema { + public static string ContentSchemaDisplayName { get { - return ResourceManager.GetString("ContentSchema", resourceCulture); + return ResourceManager.GetString("ContentSchemaDisplayName", resourceCulture); } } @@ -466,7 +466,7 @@ namespace Squidex.Domain.Apps.Core { } /// - /// Looks up a localized string similar to The display name of the schema.. + /// Looks up a localized string similar to The name of the schema.. /// public static string ContentSchemaName { get { diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.resx b/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.resx index 52c42058d..b8d8bf241 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.resx +++ b/backend/src/Squidex.Domain.Apps.Core.Model/FieldDescriptions.resx @@ -246,14 +246,14 @@ The status for the content. - - The name of the schema. + + The display name of the schema. The ID of the schema. - The display name of the schema. + The name of the schema. The contents. diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/ContentJsonSchema.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/ContentJsonSchema.cs index 90956f2ab..9e41129c2 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/ContentJsonSchema.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/GenerateJsonSchema/ContentJsonSchema.cs @@ -37,8 +37,9 @@ namespace Squidex.Domain.Apps.Core.GenerateJsonSchema if (extended) { jsonSchema.Properties["newStatusColor"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentNewStatusColor, false); - jsonSchema.Properties["schema"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentSchema, true); - jsonSchema.Properties["SchemaName"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentSchemaName, true); + jsonSchema.Properties["schemaId"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentSchemaId, true); + jsonSchema.Properties["schemaName"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentSchemaName, true); + jsonSchema.Properties["schemaDisplayName"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentSchemaDisplayName, true); jsonSchema.Properties["statusColor"] = JsonTypeBuilder.StringProperty(FieldDescriptions.ContentStatusColor, true); } diff --git a/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/Builder.cs b/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/Builder.cs index 5d29b61b2..ae88b8e7b 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/Builder.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/Builder.cs @@ -60,7 +60,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator return BuildResult(contentSchema); }); - var path = $"/content/{AppName}"; + var path = $"api/content/{AppName}"; var builder = new OperationsBuilder { @@ -108,7 +108,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator return BuildResult(contentSchema); }); - var path = $"/content/{AppName}/{schema.Name}"; + var path = $"api/content/{AppName}/{schema.Name}"; var builder = new OperationsBuilder { diff --git a/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs b/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs index 4a43323ee..f788eace3 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Contents/Generator/SchemasOpenApiGenerator.cs @@ -110,7 +110,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator .Describe(Resources.OpenApiSchemaQuery) .HasQueryOptions(true) .Responds(200, "Content items retrieved.", builder.ContentsSchema) - .Responds(400, "Query not valid."); + .Responds(400, "Content query not valid."); builder.AddOperation(OpenApiOperationMethod.Get, "/{id}") .RequirePermission(Permissions.AppContentsReadOwn) @@ -121,7 +121,7 @@ namespace Squidex.Areas.Api.Controllers.Contents.Generator builder.AddOperation(OpenApiOperationMethod.Get, "/{id}/{version}") .RequirePermission(Permissions.AppContentsReadOwn) - .Operation("Get") + .Operation("GetVersioned") .OperationSummary("Get a [schema] content item by id and version.") .HasPath("version", JsonObjectType.Number, "The version of the content item.") .HasId() diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs index 199287f27..be3d2ac67 100644 --- a/backend/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs +++ b/backend/tools/TestSuite/TestSuite.ApiTests/OpenApiTests.cs @@ -13,17 +13,17 @@ using Xunit; namespace TestSuite.ApiTests { - public class OpenApiTests : IClassFixture + public class OpenApiTests : IClassFixture { - public ClientManagerFixture _ { get; } + public ContentFixture _ { get; } - public OpenApiTests(ClientManagerFixture fixture) + public OpenApiTests(ContentFixture fixture) { _ = fixture; } [Fact] - public async Task Should_provide_spec() + public async Task Should_provide_general_spec() { var url = $"{_.ClientManager.Options.Url}/api/swagger/v1/swagger.json"; @@ -31,5 +31,25 @@ namespace TestSuite.ApiTests Assert.NotNull(document); } + + [Fact] + public async Task Should_provide_content_spec() + { + var url = $"{_.ClientManager.Options.Url}/api/content/{_.AppName}/swagger/v1/swagger.json"; + + var document = await OpenApiDocument.FromUrlAsync(url); + + Assert.NotNull(document); + } + + [Fact] + public async Task Should_provide_flat_content_spec() + { + var url = $"{_.ClientManager.Options.Url}/api/content/{_.AppName}/flat/swagger/v1/swagger.json"; + + var document = await OpenApiDocument.FromUrlAsync(url); + + Assert.NotNull(document); + } } }