Browse Source

Just renamed a test and some minor refactorings

pull/1/head
Sebastian 9 years ago
parent
commit
ec5993f3b7
  1. 101
      src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs
  2. 17
      src/Squidex/Pipeline/Swagger/SwaggerHelper.cs
  3. 2
      src/Squidex/app/features/dashboard/pages/dashboard-page.component.html
  4. 6
      src/Squidex/app/features/dashboard/pages/dashboard-page.component.ts
  5. 2
      tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs

101
src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs

@ -35,7 +35,7 @@ namespace Squidex.Controllers.ContentApi.Generator
private const string BodyDescription = private const string BodyDescription =
@"The data of the {0} to be created or updated. @"The data of the {0} to be created or updated.
Please not that each field is an object with one entry per language. Please note that each field is an object with one entry per language.
If the field is not localizable you must use iv (Invariant Language) as a key. If the field is not localizable you must use iv (Invariant Language) as a key.
When you change the field to be localizable the value will become the value for the master language, depending what the master language is at this point of time."; When you change the field to be localizable the value will become the value for the master language, depending what the master language is at this point of time.";
@ -179,13 +179,15 @@ When you change the field to be localizable the value will become the value for
Name = schemaName, Description = $"API to managed {schemaName} content elements." Name = schemaName, Description = $"API to managed {schemaName} content elements."
}); });
var dataSchem = AppendSchema($"{schema.Name}Dto", schema.BuildSchema(languages, AppendSchema));
var schemaOperations = new List<SwaggerOperations> var schemaOperations = new List<SwaggerOperations>
{ {
GenerateSchemaQueryOperation(schema, schemaName), GenerateSchemaQueryOperation(schema, schemaName, dataSchem),
GenerateSchemaCreateOperation(schema, schemaName), GenerateSchemaCreateOperation(schema, schemaName, dataSchem),
GenerateSchemaGetOperation(schema, schemaName), GenerateSchemaGetOperation(schema, schemaName, dataSchem),
GenerateSchemaUpdateOperation(schema, schemaName), GenerateSchemaUpdateOperation(schema, schemaName, dataSchem),
GenerateSchemaPatchOperation(schema, schemaName), GenerateSchemaPatchOperation(schema, schemaName, dataSchem),
GenerateSchemaPublishOperation(schema, schemaName), GenerateSchemaPublishOperation(schema, schemaName),
GenerateSchemaUnpublishOperation(schema, schemaName), GenerateSchemaUnpublishOperation(schema, schemaName),
GenerateSchemaDeleteOperation(schema, schemaName) GenerateSchemaDeleteOperation(schema, schemaName)
@ -197,79 +199,68 @@ When you change the field to be localizable the value will become the value for
} }
} }
private SwaggerOperations GenerateSchemaQueryOperation(Schema schema, string schemaName) private SwaggerOperations GenerateSchemaQueryOperation(Schema schema, string schemaName, JsonSchema4 dataSchem)
{ {
return AddOperation(SwaggerOperationMethod.Get, null, $"{appBasePath}/{schema.Name}", operation => return AddOperation(SwaggerOperationMethod.Get, null, $"{appBasePath}/{schema.Name}", operation =>
{ {
operation.Summary = $"Queries {schemaName} content elements."; operation.Summary = $"Queries {schemaName} content elements.";
operation.Parameters.AddQueryParameter("$top", JsonObjectType.Number, "The number of elements to take."); operation.AddQueryParameter("$top", JsonObjectType.Number, "The number of elements to take.");
operation.Parameters.AddQueryParameter("$skip", JsonObjectType.Number, "The number of elements to skip."); operation.AddQueryParameter("$skip", JsonObjectType.Number, "The number of elements to skip.");
operation.Parameters.AddQueryParameter("$filter", JsonObjectType.String, "Optional filter."); operation.AddQueryParameter("$filter", JsonObjectType.String, "Optional filter.");
operation.Parameters.AddQueryParameter("$search", JsonObjectType.String, "Optional full text query skip."); operation.AddQueryParameter("$search", JsonObjectType.String, "Optional full text query string.");
var responseSchema = CreateContentsSchema(schema.BuildSchema(languages, AppendSchema), schemaName, schema.Name); var responseSchema = CreateContentsSchema(schemaName, schema.Name, dataSchem);
operation.Responses.Add("200", operation.AddResponse("200", $"{schemaName} content elements retrieved.", responseSchema);
new SwaggerResponse { Description = $"{schemaName} content elements retrieved.", Schema = responseSchema });
}); });
} }
private SwaggerOperations GenerateSchemaGetOperation(Schema schema, string schemaName) private SwaggerOperations GenerateSchemaGetOperation(Schema schema, string schemaName, JsonSchema4 dataSchema)
{ {
return AddOperation(SwaggerOperationMethod.Get, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation => return AddOperation(SwaggerOperationMethod.Get, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation =>
{ {
operation.Summary = $"Get a {schemaName} content element."; operation.Summary = $"Get a {schemaName} content element.";
var responseSchema = CreateContentSchema(schema.BuildSchema(languages, AppendSchema), schemaName, schema.Name); var responseSchema = CreateContentSchema(schemaName, schema.Name, dataSchema);
operation.Responses.Add("200", operation.AddResponse("200", $"{schemaName} element found.", responseSchema);
new SwaggerResponse { Description = $"{schemaName} element found.", Schema = responseSchema });
}); });
} }
private SwaggerOperations GenerateSchemaCreateOperation(Schema schema, string schemaName) private SwaggerOperations GenerateSchemaCreateOperation(Schema schema, string schemaName, JsonSchema4 dataSchema)
{ {
return AddOperation(SwaggerOperationMethod.Post, null, $"{appBasePath}/{schema.Name}", operation => return AddOperation(SwaggerOperationMethod.Post, null, $"{appBasePath}/{schema.Name}", operation =>
{ {
operation.Summary = $"Create a {schemaName} content element."; operation.Summary = $"Create a {schemaName} content element.";
var bodySchema = AppendSchema($"{schema.Name}Dto", schema.BuildSchema(languages, AppendSchema)); operation.AddBodyParameter(dataSchema, "data", string.Format(BodyDescription, schemaName));
operation.Parameters.AddBodyParameter(bodySchema, "data", string.Format(BodyDescription, schemaName));
operation.Responses.Add("201", operation.AddResponse("201", $"{schemaName} created.", entityCreatedDtoSchema);
new SwaggerResponse { Description = $"{schemaName} created.", Schema = entityCreatedDtoSchema });
}); });
} }
private SwaggerOperations GenerateSchemaUpdateOperation(Schema schema, string schemaName) private SwaggerOperations GenerateSchemaUpdateOperation(Schema schema, string schemaName, JsonSchema4 dataSchema)
{ {
return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation => return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation =>
{ {
operation.Summary = $"Update a {schemaName} content element."; operation.Summary = $"Update a {schemaName} content element.";
var bodySchema = AppendSchema($"{schema.Name}Dto", schema.BuildSchema(languages, AppendSchema)); operation.AddBodyParameter(dataSchema, "data", string.Format(BodyDescription, schemaName));
operation.Parameters.AddBodyParameter(bodySchema, "data", string.Format(BodyDescription, schemaName)); operation.AddResponse("204", $"{schemaName} element updated.");
operation.Responses.Add("204",
new SwaggerResponse { Description = $"{schemaName} element updated." });
}); });
} }
private SwaggerOperations GenerateSchemaPatchOperation(Schema schema, string schemaName) private SwaggerOperations GenerateSchemaPatchOperation(Schema schema, string schemaName, JsonSchema4 dataSchema)
{ {
return AddOperation(SwaggerOperationMethod.Patch, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation => return AddOperation(SwaggerOperationMethod.Patch, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation =>
{ {
operation.Summary = $"Update a {schemaName} content element partially."; operation.Summary = $"Patchs a {schemaName} content element.";
var bodySchema = AppendSchema($"{schema.Name}Dto", schema.BuildSchema(languages, AppendSchema));
operation.Parameters.AddBodyParameter(bodySchema, "data", string.Format(BodyDescription, schemaName)); operation.AddBodyParameter(dataSchema, "data", string.Format(BodyDescription, schemaName));
operation.Responses.Add("204", operation.AddResponse("204", $"{schemaName} element updated.");
new SwaggerResponse { Description = $"{schemaName} element updated." });
}); });
} }
@ -279,8 +270,7 @@ When you change the field to be localizable the value will become the value for
{ {
operation.Summary = $"Publish a {schemaName} content element."; operation.Summary = $"Publish a {schemaName} content element.";
operation.Responses.Add("204", operation.AddResponse("204", $"{schemaName} element published.");
new SwaggerResponse { Description = $"{schemaName} element published." });
}); });
} }
@ -290,8 +280,7 @@ When you change the field to be localizable the value will become the value for
{ {
operation.Summary = $"Unpublish a {schemaName} content element."; operation.Summary = $"Unpublish a {schemaName} content element.";
operation.Responses.Add("204", operation.AddResponse("204", $"{schemaName} element unpublished.");
new SwaggerResponse { Description = $"{schemaName} element unpublished." });
}); });
} }
@ -301,8 +290,7 @@ When you change the field to be localizable the value will become the value for
{ {
operation.Summary = $"Delete a {schemaName} content element."; operation.Summary = $"Delete a {schemaName} content element.";
operation.Responses.Add("204", operation.AddResponse("204", $"{schemaName} element deleted.");
new SwaggerResponse { Description = $"{schemaName} element deleted." });
}); });
} }
@ -317,18 +305,17 @@ When you change the field to be localizable the value will become the value for
if (entityName != null) if (entityName != null)
{ {
operation.Parameters.AddPathParameter("id", JsonObjectType.String, $"The id of the {entityName} (GUID)."); operation.AddPathParameter("id", JsonObjectType.String, $"The id of the {entityName} (GUID).");
operation.Responses.Add("404", operation.AddResponse("404", $"App, schema or {entityName} not found.");
new SwaggerResponse { Description = $"App, schema or {entityName} not found." });
} }
return operations; return operations;
} }
private JsonSchema4 CreateContentsSchema(JsonSchema4 dataSchema, string schemaName, string id) private JsonSchema4 CreateContentsSchema(string schemaName, string id, JsonSchema4 dataSchema)
{ {
var contentSchema = CreateContentSchema(dataSchema, schemaName, id); var contentSchema = CreateContentSchema(schemaName, id, dataSchema);
var schema = new JsonSchema4 var schema = new JsonSchema4
{ {
@ -340,10 +327,7 @@ When you change the field to be localizable the value will become the value for
}, },
["items"] = new JsonProperty ["items"] = new JsonProperty
{ {
IsRequired = true, Type = JsonObjectType.Array, IsRequired = true, Item = contentSchema, Description = $"The item of {schemaName} content elements."
Item = contentSchema,
Type = JsonObjectType.Array,
Description = $"The item of {schemaName} content elements."
} }
}, },
Type = JsonObjectType.Object Type = JsonObjectType.Object
@ -352,15 +336,14 @@ When you change the field to be localizable the value will become the value for
return schema; return schema;
} }
private JsonSchema4 CreateContentSchema(JsonSchema4 dataSchema, string schemaName, string id) private JsonSchema4 CreateContentSchema(string schemaName, string id, JsonSchema4 dataSchema)
{ {
var CreateProperty = var CreateProperty =
new Func<string, string, JsonProperty>((d, f) => new Func<string, string, JsonProperty>((d, f) =>
new JsonProperty { Description = d, Format = f, IsRequired = true, Type = JsonObjectType.String }); new JsonProperty { Description = d, Format = f, IsRequired = true, Type = JsonObjectType.String });
var dataProperty = new JsonProperty { Type = JsonObjectType.Object, IsRequired = true, Description = "The data of the content element" }; var dataDescription = $"The data of the {schemaName} content element";
var dataProperty = new JsonProperty { Description = dataDescription, Type = JsonObjectType.Object, IsRequired = true, SchemaReference = dataSchema };
dataProperty.AllOf.Add(dataSchema);
var schema = new JsonSchema4 var schema = new JsonSchema4
{ {
@ -371,11 +354,7 @@ When you change the field to be localizable the value will become the value for
["created"] = CreateProperty($"The date and time when the {schemaName} content element has been created.", "date-time"), ["created"] = CreateProperty($"The date and time when the {schemaName} content element has been created.", "date-time"),
["createdBy"] = CreateProperty($"The user that has created the {schemaName} content element.", null), ["createdBy"] = CreateProperty($"The user that has created the {schemaName} content element.", null),
["lastModified"] = CreateProperty($"The date and time when the {schemaName} content element has been modified last.", "date-time"), ["lastModified"] = CreateProperty($"The date and time when the {schemaName} content element has been modified last.", "date-time"),
["lastModifiedBy"] = CreateProperty($"The user that has updated the {schemaName} content element.", null), ["lastModifiedBy"] = CreateProperty($"The user that has updated the {schemaName} content element.", null)
["nonPublished"] = new JsonProperty
{
Description = $"Indicates if the {schemaName} content element is publihed.", IsRequired = true, Type = JsonObjectType.Boolean
}
}, },
Type = JsonObjectType.Object Type = JsonObjectType.Object
}; };

17
src/Squidex/Pipeline/Swagger/SwaggerHelper.cs

@ -46,9 +46,9 @@ namespace Squidex.Pipeline.Swagger
}; };
} }
public static void AddQueryParameter(this ICollection<SwaggerParameter> parameters, string name, JsonObjectType type, string description) public static void AddQueryParameter(this SwaggerOperation operation, string name, JsonObjectType type, string description)
{ {
parameters.Add( operation.Parameters.Add(
new SwaggerParameter new SwaggerParameter
{ {
Type = type, Type = type,
@ -58,9 +58,9 @@ namespace Squidex.Pipeline.Swagger
}); });
} }
public static void AddPathParameter(this ICollection<SwaggerParameter> parameters, string name, JsonObjectType type, string description) public static void AddPathParameter(this SwaggerOperation operation, string name, JsonObjectType type, string description)
{ {
parameters.Add( operation.Parameters.Add(
new SwaggerParameter new SwaggerParameter
{ {
Type = type, Type = type,
@ -72,9 +72,9 @@ namespace Squidex.Pipeline.Swagger
}); });
} }
public static void AddBodyParameter(this ICollection<SwaggerParameter> parameters, JsonSchema4 schema, string name, string description) public static void AddBodyParameter(this SwaggerOperation operation, JsonSchema4 schema, string name, string description)
{ {
parameters.Add( operation.Parameters.Add(
new SwaggerParameter new SwaggerParameter
{ {
Name = name, Name = name,
@ -85,5 +85,10 @@ namespace Squidex.Pipeline.Swagger
Description = description Description = description
}); });
} }
public static void AddResponse(this SwaggerOperation operation, string statusCode, string description, JsonSchema4 schema = null)
{
operation.Responses.Add(statusCode, new SwaggerResponse { Description = description, Schema = schema });
}
} }
} }

2
src/Squidex/app/features/dashboard/pages/dashboard-page.component.html

@ -1,6 +1,6 @@
<sqx-title message="{app} | Dashboard" parameter1="app" value1="{{appName() | async}}"></sqx-title> <sqx-title message="{app} | Dashboard" parameter1="app" value1="{{appName() | async}}"></sqx-title>
<div class="dashboard"> <div class="dashboard" [@fade]>
<div> <div>
<h1>Hi {{profileDisplayName}}</h1> <h1>Hi {{profileDisplayName}}</h1>

6
src/Squidex/app/features/dashboard/pages/dashboard-page.component.ts

@ -12,6 +12,7 @@ import {
AppComponentBase, AppComponentBase,
AppsStoreService, AppsStoreService,
AuthService, AuthService,
fadeAnimation,
NotificationService, NotificationService,
UsersProviderService UsersProviderService
} from 'shared'; } from 'shared';
@ -21,7 +22,10 @@ declare var _urq: any;
@Component({ @Component({
selector: 'sqx-dashboard-page', selector: 'sqx-dashboard-page',
styleUrls: ['./dashboard-page.component.scss'], styleUrls: ['./dashboard-page.component.scss'],
templateUrl: './dashboard-page.component.html' templateUrl: './dashboard-page.component.html',
animations: [
fadeAnimation
]
}) })
export class DashboardPageComponent extends AppComponentBase { export class DashboardPageComponent extends AppComponentBase {
private authenticationSubscription: Subscription; private authenticationSubscription: Subscription;

2
tests/Squidex.Infrastructure.Tests/Reflection/PropertiesTypeAccessorTests.cs

@ -97,7 +97,7 @@ namespace Squidex.Infrastructure.Reflection
} }
[Fact] [Fact]
public void Should_throw_if_getting_readonly() public void Should_throw_if_getting_readonly_property()
{ {
Assert.Throws<NotSupportedException>(() => accessor.GetValue(target, "Write")); Assert.Throws<NotSupportedException>(() => accessor.GetValue(target, "Write"));
} }

Loading…
Cancel
Save