Browse Source

More swagger improvements

pull/1/head
Sebastian 10 years ago
parent
commit
ab3681e67d
  1. 6
      src/Squidex.Core/Schemas/Schema.cs
  2. 2
      src/Squidex/Config/Constants.cs
  3. 4
      src/Squidex/Config/Swagger/SwaggerServices.cs
  4. 2
      src/Squidex/Controllers/ContentApi/Generator/SchemasSwaggerGenerator.cs
  5. 7
      src/Squidex/Pipeline/Swagger/SwaggerHelper.cs

6
src/Squidex.Core/Schemas/Schema.cs

@ -289,7 +289,7 @@ namespace Squidex.Core.Schemas
}
}
private void ValidateUnknownFields(ContentData data, IList<ValidationError> errors)
private void ValidateUnknownFields(ContentData data, ICollection<ValidationError> errors)
{
foreach (var fieldData in data)
{
@ -300,7 +300,7 @@ namespace Squidex.Core.Schemas
}
}
private static async Task ValidateLocalizableFieldAsync(ICollection<Language> languages, ContentFieldData fieldData, List<string> fieldErrors, Field field)
private static async Task ValidateLocalizableFieldAsync(ICollection<Language> languages, ContentFieldData fieldData, ICollection<string> fieldErrors, Field field)
{
foreach (var valueLanguage in fieldData.Keys)
{
@ -322,7 +322,7 @@ namespace Squidex.Core.Schemas
}
}
private static async Task ValidateNonLocalizableField(ContentFieldData fieldData, List<string> fieldErrors, Field field)
private static async Task ValidateNonLocalizableField(ContentFieldData fieldData, ICollection<string> fieldErrors, Field field)
{
if (fieldData.Keys.Any(x => x != Language.Invariant.Iso2Code))
{

2
src/Squidex/Config/Constants.cs

@ -10,6 +10,8 @@ namespace Squidex.Config
{
public class Constants
{
public static readonly string SecurityDefinition = "oauth-client-auth";
public static readonly string ApiPrefix = "/api";
public static readonly string ApiScope = "squidex-api";

4
src/Squidex/Config/Swagger/SwaggerServices.cs

@ -43,9 +43,9 @@ namespace Squidex.Config.Swagger
private static SwaggerOwinSettings ConfigureIdentity(this SwaggerOwinSettings settings, MyUrlsOptions urlOptions)
{
settings.DocumentProcessors.Add(
new SecurityDefinitionAppender("OAuth2", SwaggerHelper.CreateOAuthSchema(urlOptions)));
new SecurityDefinitionAppender(Constants.SecurityDefinition, SwaggerHelper.CreateOAuthSchema(urlOptions)));
settings.OperationProcessors.Add(new OperationSecurityScopeProcessor("roles"));
settings.OperationProcessors.Add(new OperationSecurityScopeProcessor(Constants.SecurityDefinition));
return settings;
}

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

@ -145,7 +145,7 @@ namespace Squidex.Controllers.ContentApi.Generator
{
new SwaggerSecurityRequirement
{
{ "roles", new List<string> { SquidexRoles.AppOwner, SquidexRoles.AppDeveloper, SquidexRoles.AppEditor } }
{ Constants.SecurityDefinition, new List<string> { SquidexRoles.AppOwner, SquidexRoles.AppDeveloper, SquidexRoles.AppEditor } }
}
};

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

@ -13,6 +13,7 @@ using NJsonSchema;
using NSwag;
using Squidex.Config;
using System.Reflection;
using Squidex.Core.Identity;
namespace Squidex.Pipeline.Swagger
{
@ -46,11 +47,15 @@ namespace Squidex.Pipeline.Swagger
new SwaggerSecurityScheme
{
TokenUrl = tokenUrl,
Name = Constants.SecurityDefinition,
Type = SwaggerSecuritySchemeType.OAuth2,
Flow = SwaggerOAuth2Flow.Application,
Scopes = new Dictionary<string, string>
{
{ Constants.ApiScope, "Read and write access to the API" }
{ Constants.ApiScope, "Read and write access to the API" },
{ SquidexRoles.AppOwner, "You get this scope / role when you are owner of the app you are accessing." },
{ SquidexRoles.AppEditor, "You get this scope / role when you are owner of the app you are accessing or when the subject is a client." },
{ SquidexRoles.AppDeveloper, "You get this scope / role when you are owner of the app you are accessing." }
},
Description = securityDescription
};

Loading…
Cancel
Save