|
|
|
@ -173,26 +173,27 @@ namespace Squidex.Controllers.ContentApi.Generator |
|
|
|
|
|
|
|
private void GenerateSchemaOperations(Schema schema) |
|
|
|
{ |
|
|
|
var schemaName = schema.Properties.Label ?? schema.Name; |
|
|
|
var schemaIdentifier = schema.Name.ToPascalCase(); |
|
|
|
var schemaName = !string.IsNullOrWhiteSpace(schema.Properties.Label) ? schema.Properties.Label.Trim() : schema.Name; |
|
|
|
|
|
|
|
document.Tags.Add( |
|
|
|
new SwaggerTag |
|
|
|
{ |
|
|
|
Name = schemaName, Description = $"API to managed {schemaName} content." |
|
|
|
Name = schemaName, Description = $"API to managed {schemaName} contents." |
|
|
|
}); |
|
|
|
|
|
|
|
var dataSchem = AppendSchema($"{schema.Name}Dto", schema.BuildSchema(languages, AppendSchema)); |
|
|
|
var dataSchema = AppendSchema($"{schemaIdentifier}Dto", schema.BuildSchema(languages, AppendSchema)); |
|
|
|
|
|
|
|
var schemaOperations = new List<SwaggerOperations> |
|
|
|
{ |
|
|
|
GenerateSchemaQueryOperation(schema, schemaName, dataSchem), |
|
|
|
GenerateSchemaCreateOperation(schema, schemaName, dataSchem), |
|
|
|
GenerateSchemaGetOperation(schema, schemaName, dataSchem), |
|
|
|
GenerateSchemaUpdateOperation(schema, schemaName, dataSchem), |
|
|
|
GenerateSchemaPatchOperation(schema, schemaName, dataSchem), |
|
|
|
GenerateSchemaPublishOperation(schema, schemaName), |
|
|
|
GenerateSchemaUnpublishOperation(schema, schemaName), |
|
|
|
GenerateSchemaDeleteOperation(schema, schemaName) |
|
|
|
GenerateSchemaQueryOperation(schema, schemaName, schemaIdentifier, dataSchema), |
|
|
|
GenerateSchemaCreateOperation(schema, schemaName, schemaIdentifier, dataSchema), |
|
|
|
GenerateSchemaGetOperation(schema, schemaName, schemaIdentifier, dataSchema), |
|
|
|
GenerateSchemaUpdateOperation(schema, schemaName, schemaIdentifier, dataSchema), |
|
|
|
GenerateSchemaPatchOperation(schema, schemaName, schemaIdentifier, dataSchema), |
|
|
|
GenerateSchemaPublishOperation(schema, schemaName, schemaIdentifier), |
|
|
|
GenerateSchemaUnpublishOperation(schema, schemaName, schemaIdentifier), |
|
|
|
GenerateSchemaDeleteOperation(schema, schemaName, schemaIdentifier) |
|
|
|
}; |
|
|
|
|
|
|
|
foreach (var operation in schemaOperations.SelectMany(x => x.Values).Distinct()) |
|
|
|
@ -201,11 +202,13 @@ namespace Squidex.Controllers.ContentApi.Generator |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaQueryOperation(Schema schema, string schemaName, JsonSchema4 dataSchema) |
|
|
|
private SwaggerOperations GenerateSchemaQueryOperation(Schema schema, string schemaName, string schemaIdentifier, JsonSchema4 dataSchema) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Get, null, $"{appBasePath}/{schema.Name}", operation => |
|
|
|
{ |
|
|
|
operation.Summary = $"Queries {schemaName} content."; |
|
|
|
operation.OperationId = $"Query{schemaIdentifier}Contents"; |
|
|
|
|
|
|
|
operation.Summary = $"Queries {schemaName} contents."; |
|
|
|
|
|
|
|
operation.Description = schemaQueryDescription; |
|
|
|
|
|
|
|
@ -221,78 +224,89 @@ namespace Squidex.Controllers.ContentApi.Generator |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaGetOperation(Schema schema, string schemaName, JsonSchema4 dataSchema) |
|
|
|
private SwaggerOperations GenerateSchemaGetOperation(Schema schema, string schemaName, string schemaIdentifier, JsonSchema4 dataSchema) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Get, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Get{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Get a {schemaName} content."; |
|
|
|
|
|
|
|
var responseSchema = CreateContentSchema(schemaName, schema.Name, dataSchema); |
|
|
|
var responseSchema = CreateContentSchema(schemaName, schemaIdentifier, dataSchema); |
|
|
|
|
|
|
|
operation.AddResponse("200", $"{schemaName} content found.", responseSchema); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaCreateOperation(Schema schema, string schemaName, JsonSchema4 dataSchema) |
|
|
|
private SwaggerOperations GenerateSchemaCreateOperation(Schema schema, string schemaName, string schemaIdentifier, JsonSchema4 dataSchema) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Post, null, $"{appBasePath}/{schema.Name}", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Create{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Create a {schemaName} content."; |
|
|
|
|
|
|
|
operation.AddBodyParameter(dataSchema, "data", schemaBodyDescription); |
|
|
|
|
|
|
|
operation.AddResponse("201", $"{schemaName} created.", entityCreatedDtoSchema); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaUpdateOperation(Schema schema, string schemaName, JsonSchema4 dataSchema) |
|
|
|
private SwaggerOperations GenerateSchemaUpdateOperation(Schema schema, string schemaName, string schemaIdentifier, JsonSchema4 dataSchema) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Update{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Update a {schemaName} content."; |
|
|
|
|
|
|
|
operation.AddBodyParameter(dataSchema, "data", schemaBodyDescription); |
|
|
|
|
|
|
|
operation.AddResponse("204", $"{schemaName} element updated."); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaPatchOperation(Schema schema, string schemaName, JsonSchema4 dataSchema) |
|
|
|
private SwaggerOperations GenerateSchemaPatchOperation(Schema schema, string schemaName, string schemaIdentifier, JsonSchema4 dataSchema) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Patch, schemaName, $"{appBasePath}/{schema.Name}/{{id}}", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Path{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Patchs a {schemaName} content."; |
|
|
|
|
|
|
|
operation.AddBodyParameter(dataSchema, "data", schemaBodyDescription); |
|
|
|
|
|
|
|
operation.AddResponse("204", $"{schemaName} element updated."); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaPublishOperation(Schema schema, string schemaName) |
|
|
|
private SwaggerOperations GenerateSchemaPublishOperation(Schema schema, string schemaName, string schemaIdentifier) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appBasePath}/{schema.Name}/{{id}}/publish", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Publish{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Publish a {schemaName} content."; |
|
|
|
|
|
|
|
operation.AddResponse("204", $"{schemaName} element published."); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaUnpublishOperation(Schema schema, string schemaName) |
|
|
|
private SwaggerOperations GenerateSchemaUnpublishOperation(Schema schema, string schemaName, string schemaIdentifier) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Put, schemaName, $"{appBasePath}/{schema.Name}/{{id}}/unpublish", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Unpublish{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Unpublish a {schemaName} content."; |
|
|
|
|
|
|
|
operation.AddResponse("204", $"{schemaName} element unpublished."); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private SwaggerOperations GenerateSchemaDeleteOperation(Schema schema, string schemaName) |
|
|
|
private SwaggerOperations GenerateSchemaDeleteOperation(Schema schema, string schemaName, string schemaIdentifier) |
|
|
|
{ |
|
|
|
return AddOperation(SwaggerOperationMethod.Delete, schemaName, $"{appBasePath}/{schema.Name}/{{id}}/", operation => |
|
|
|
{ |
|
|
|
operation.OperationId = $"Delete{schemaIdentifier}Content"; |
|
|
|
|
|
|
|
operation.Summary = $"Delete a {schemaName} content."; |
|
|
|
|
|
|
|
operation.AddResponse("204", $"{schemaName} content deleted."); |
|
|
|
@ -341,7 +355,7 @@ namespace Squidex.Controllers.ContentApi.Generator |
|
|
|
return schema; |
|
|
|
} |
|
|
|
|
|
|
|
private JsonSchema4 CreateContentSchema(string schemaName, string id, JsonSchema4 dataSchema) |
|
|
|
private JsonSchema4 CreateContentSchema(string schemaName, string schemaIdentifier, JsonSchema4 dataSchema) |
|
|
|
{ |
|
|
|
var CreateProperty = |
|
|
|
new Func<string, string, JsonProperty>((d, f) => |
|
|
|
@ -363,7 +377,7 @@ namespace Squidex.Controllers.ContentApi.Generator |
|
|
|
Type = JsonObjectType.Object |
|
|
|
}; |
|
|
|
|
|
|
|
return AppendSchema($"{id}ContentDto", schema); |
|
|
|
return AppendSchema($"{schemaIdentifier}ContentDto", schema); |
|
|
|
} |
|
|
|
|
|
|
|
private JsonSchema4 AppendSchema(string name, JsonSchema4 schema) |
|
|
|
|