public void Process(DocumentProcessorContext context) { if (!_openApiOptions.QueriesApi.AlterPathSchema) { return; } if (context.Document.Definitions.TryGetValue("ContentItemDto", out var contentItemDtoSchema)) { var itemSchema = new JsonSchema { Type = JsonObjectType.Array, IsNullableRaw = true, Item = new JsonSchema { Type = JsonObjectType.Object, Reference = contentItemDtoSchema } }; // TODO This only works when returning content items. // Consider a different path for documents? context.Document.Definitions["QueriesItemsDto"] = itemSchema; context.AlterPathSchema("/api/queries/{name}", "post", "200", itemSchema, (operation) => { operation.OperationId = _openApiOptions.QueriesApi.PostOperationId; }); context.AlterPathSchema("/api/queries/{name}", "get", "200", itemSchema, (operation) => { operation.OperationId = _openApiOptions.QueriesApi.GetOperationId; }); } }
public void Process(DocumentProcessorContext context) { if (!_openApiOptions.ContentsApi.AlterPathSchema) { return; } if (context.Document.Definitions.TryGetValue("ContentItemDto", out var contentItemDtoSchema)) { context.AlterPathSchema("/api/content/{contentItemId}", "get", "200", contentItemDtoSchema); context.AlterPathSchema("/api/content/{contentItemId}", "delete", "200", contentItemDtoSchema); context.AlterPathSchema("/api/content", "post", "200", contentItemDtoSchema, (operation) => operation.RequestBody.Content.ApplySchemaToContent(contentItemDtoSchema)); } }
public void Process(DocumentProcessorContext context) { if (!_openApiOptions.LuceneApi.AlterPathSchema) { return; } if (context.Document.Definitions.TryGetValue("ContentItemDto", out var contentItemDtoSchema)) { var propertySchema = new JsonSchemaProperty { Type = JsonObjectType.Array, IsNullableRaw = true, Item = new JsonSchemaProperty { Type = JsonObjectType.Object, IsNullableRaw = true, Reference = contentItemDtoSchema } }; var itemSchema = new JsonSchema { Type = JsonObjectType.Object, IsNullableRaw = true }; itemSchema.Properties["Items"] = propertySchema; // Would be nice if this didn't have to be a dto. Or we could just ignore it? // Just ignoring it for now. context.Document.Definitions["LuceneItemsDto"] = itemSchema; context.AlterPathSchema("/api/lucene/content", "post", "200", itemSchema, (operation) => { operation.OperationId = _openApiOptions.LuceneApi.ContentPostOperationId; }); context.AlterPathSchema("/api/lucene/content", "get", "200", itemSchema, (operation) => { operation.OperationId = _openApiOptions.LuceneApi.ContentGetOperationId; }); // The document schema can be anything, so everything is stored in additional properties as kvps. var referenceSchema = new JsonSchema { Type = JsonObjectType.Object, AllowAdditionalProperties = true }; var documentsSchema = new JsonSchema { Type = JsonObjectType.Array, IsNullableRaw = true, Item = new JsonSchema { Type = JsonObjectType.Object, Reference = referenceSchema } }; context.Document.Definitions["LuceneDocumentDto"] = referenceSchema; context.Document.Definitions["LuceneDocumentsDto"] = documentsSchema; context.AlterPathSchema("/api/lucene/documents", "post", "200", documentsSchema, (operation) => { operation.OperationId = _openApiOptions.LuceneApi.DocumentsPostOperationId; }); context.AlterPathSchema("/api/lucene/documents", "get", "200", documentsSchema, (operation) => { operation.OperationId = _openApiOptions.LuceneApi.DocumentsGetOperationId; }); } }