Spaces:
Running
Running
File size: 26,481 Bytes
2510c5e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
openapi: 3.1.0
info:
title: Obsidian-Like Docs Viewer API
version: 1.0.0
description: |
Multi-tenant Obsidian-like documentation viewer with full-text search, wikilinks, and tags.
## Authentication
All endpoints require Bearer JWT authentication via the `Authorization` header (except in local mode).
## Multi-tenancy
All operations are scoped to the authenticated user's vault. Users cannot access other users' notes.
## Path Encoding
Note paths in URLs must be URL-encoded (e.g., `api/design.md` becomes `api%2Fdesign.md`).
contact:
name: API Support
license:
name: MIT
servers:
- url: http://localhost:8000
description: Local development server
- url: https://your-space.hf.space
description: Hugging Face Space deployment
security:
- BearerAuth: []
tags:
- name: Authentication
description: User authentication and token management
- name: Notes
description: CRUD operations for notes
- name: Search
description: Full-text search and navigation
- name: Index
description: Index health and rebuild operations
paths:
/api/tokens:
post:
summary: Issue JWT token
description: Issue a new JWT access token for the authenticated user (90-day expiration)
operationId: issueToken
tags:
- Authentication
security:
- BearerAuth: []
responses:
'200':
description: Token issued successfully
content:
application/json:
schema:
$ref: '#/components/schemas/TokenResponse'
example:
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhbGljZSIsImlhdCI6MTczNjk1NjgwMCwiZXhwIjoxNzQ0NzMyODAwfQ.signature
token_type: bearer
expires_at: "2025-04-15T10:30:00Z"
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/api/me:
get:
summary: Get current user info
description: Retrieve authenticated user information including HF profile
operationId: getCurrentUser
tags:
- Authentication
responses:
'200':
description: User information retrieved
content:
application/json:
schema:
$ref: '#/components/schemas/User'
example:
user_id: alice
hf_profile:
username: alice
name: Alice Smith
avatar_url: https://cdn-avatars.huggingface.co/v1/alice
vault_path: /data/vaults/alice
created: "2025-01-15T10:30:00Z"
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/api/notes:
get:
summary: List notes
description: List all notes in the user's vault with optional folder filtering
operationId: listNotes
tags:
- Notes
parameters:
- name: folder
in: query
description: Filter notes by folder path (e.g., "api" or "guides/tutorials")
required: false
schema:
type: string
maxLength: 256
example: api
responses:
'200':
description: List of notes
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/NoteSummary'
example:
- note_path: api/design.md
title: API Design
updated: "2025-01-15T14:30:00Z"
- note_path: api/endpoints.md
title: API Endpoints
updated: "2025-01-14T09:15:00Z"
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/api/notes/{path}:
get:
summary: Get note
description: Retrieve full note content including metadata, body, and version
operationId: getNote
tags:
- Notes
parameters:
- $ref: '#/components/parameters/NotePath'
responses:
'200':
description: Note retrieved successfully
content:
application/json:
schema:
$ref: '#/components/schemas/Note'
example:
user_id: alice
note_path: api/design.md
version: 5
title: API Design
metadata:
tags:
- backend
- api
project: auth-service
body: "# API Design\n\nThis document describes the API architecture...\n\n## Endpoints\n\nSee [[Endpoints]] for details."
created: "2025-01-10T09:00:00Z"
updated: "2025-01-15T14:30:00Z"
size_bytes: 4096
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'404':
description: Note not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: not_found
message: Note not found
detail:
note_path: api/design.md
'500':
$ref: '#/components/responses/InternalServerError'
put:
summary: Create or update note
description: Create a new note or update an existing note with optional optimistic concurrency control
operationId: createOrUpdateNote
tags:
- Notes
parameters:
- $ref: '#/components/parameters/NotePath'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NoteUpdate'
example:
title: API Design
metadata:
tags:
- backend
- api
project: auth-service
body: "# API Design\n\nThis document describes the API architecture..."
if_version: 4
responses:
'200':
description: Note updated successfully
content:
application/json:
schema:
$ref: '#/components/schemas/NoteResponse'
example:
status: ok
path: api/design.md
version: 5
'201':
description: Note created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/NoteResponse'
example:
status: ok
path: api/design.md
version: 1
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'409':
$ref: '#/components/responses/Conflict'
'413':
$ref: '#/components/responses/PayloadTooLarge'
'500':
$ref: '#/components/responses/InternalServerError'
delete:
summary: Delete note
description: Delete a note and remove it from all indices
operationId: deleteNote
tags:
- Notes
parameters:
- $ref: '#/components/parameters/NotePath'
responses:
'200':
description: Note deleted successfully
content:
application/json:
schema:
$ref: '#/components/schemas/DeleteResponse'
example:
status: ok
path: api/design.md
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'404':
description: Note not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: not_found
message: Note not found
detail:
note_path: api/design.md
'500':
$ref: '#/components/responses/InternalServerError'
/api/search:
get:
summary: Search notes
description: Full-text search across all notes with ranking (title 3x weight, body 1x, recency bonus)
operationId: searchNotes
tags:
- Search
parameters:
- name: q
in: query
description: Search query (tokenized, case-insensitive)
required: true
schema:
type: string
minLength: 1
maxLength: 256
example: authentication
- name: limit
in: query
description: Maximum number of results to return
required: false
schema:
type: integer
minimum: 1
maximum: 100
default: 50
responses:
'200':
description: Search results
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/SearchResult'
example:
- note_path: api/auth.md
title: Authentication Flow
snippet: "...describes the <mark>authentication</mark> process using JWT tokens..."
score: 8.5
updated: "2025-01-15T14:30:00Z"
- note_path: guides/setup.md
title: Setup Guide
snippet: "...configure <mark>authentication</mark> settings in the config file..."
score: 3.2
updated: "2025-01-10T09:00:00Z"
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/api/backlinks/{path}:
get:
summary: Get backlinks
description: Get all notes that reference the specified note via wikilinks
operationId: getBacklinks
tags:
- Search
parameters:
- name: path
in: path
description: URL-encoded note path (includes .md extension)
required: true
schema:
type: string
maxLength: 256
example: api%2Fdesign.md
responses:
'200':
description: Backlinks retrieved
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/BacklinkResult'
example:
- note_path: guides/architecture.md
title: Architecture Overview
- note_path: api/endpoints.md
title: API Endpoints
'401':
$ref: '#/components/responses/Unauthorized'
'404':
description: Note not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: not_found
message: Note not found
detail:
note_path: api/design.md
'500':
$ref: '#/components/responses/InternalServerError'
/api/tags:
get:
summary: List all tags
description: Get all tags used in the user's vault with note counts
operationId: listTags
tags:
- Search
responses:
'200':
description: List of tags
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Tag'
example:
- tag: backend
count: 15
- tag: api
count: 12
- tag: frontend
count: 8
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/api/index/health:
get:
summary: Get index health status
description: Retrieve index health metrics including note count and last update timestamps
operationId: getIndexHealth
tags:
- Index
responses:
'200':
description: Index health metrics
content:
application/json:
schema:
$ref: '#/components/schemas/IndexHealth'
example:
user_id: alice
note_count: 142
last_full_rebuild: "2025-01-01T00:00:00Z"
last_incremental_update: "2025-01-15T14:30:00Z"
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/api/index/rebuild:
post:
summary: Trigger full index rebuild
description: Manually rebuild all indices from scratch by re-scanning vault files
operationId: rebuildIndex
tags:
- Index
responses:
'200':
description: Index rebuild completed
content:
application/json:
schema:
$ref: '#/components/schemas/RebuildResponse'
example:
status: ok
notes_indexed: 142
duration_ms: 1250
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
description: JWT token obtained from POST /api/tokens
parameters:
NotePath:
name: path
in: path
description: URL-encoded note path (includes .md extension, e.g., "api%2Fdesign.md")
required: true
schema:
type: string
maxLength: 256
example: api%2Fdesign.md
schemas:
User:
type: object
required:
- user_id
- vault_path
- created
properties:
user_id:
type: string
minLength: 1
maxLength: 64
description: Internal user identifier
example: alice
hf_profile:
$ref: '#/components/schemas/HFProfile'
vault_path:
type: string
description: Absolute path to user's vault directory
example: /data/vaults/alice
created:
type: string
format: date-time
description: Account creation timestamp (ISO 8601)
example: "2025-01-15T10:30:00Z"
HFProfile:
type: object
properties:
username:
type: string
description: Hugging Face username
example: alice
name:
type: string
nullable: true
description: Display name from HF profile
example: Alice Smith
avatar_url:
type: string
format: uri
nullable: true
description: Profile picture URL
example: https://cdn-avatars.huggingface.co/v1/alice
NoteMetadata:
type: object
description: Arbitrary frontmatter key-value pairs (YAML)
properties:
title:
type: string
nullable: true
tags:
type: array
items:
type: string
nullable: true
project:
type: string
nullable: true
created:
type: string
format: date-time
nullable: true
updated:
type: string
format: date-time
nullable: true
additionalProperties: true
example:
tags:
- backend
- api
project: auth-service
Note:
type: object
required:
- user_id
- note_path
- version
- title
- body
- created
- updated
- size_bytes
properties:
user_id:
type: string
description: Owner user ID
example: alice
note_path:
type: string
minLength: 1
maxLength: 256
description: Relative path to vault root (includes .md)
example: api/design.md
version:
type: integer
minimum: 1
description: Optimistic concurrency version counter
example: 5
title:
type: string
minLength: 1
description: Display title (from frontmatter, H1, or filename)
example: API Design
metadata:
$ref: '#/components/schemas/NoteMetadata'
body:
type: string
description: Markdown content (excluding frontmatter)
example: "# API Design\n\nThis document describes..."
created:
type: string
format: date-time
description: Creation timestamp (ISO 8601)
example: "2025-01-10T09:00:00Z"
updated:
type: string
format: date-time
description: Last modification timestamp (ISO 8601)
example: "2025-01-15T14:30:00Z"
size_bytes:
type: integer
minimum: 0
maximum: 1048576
description: File size in bytes (max 1 MiB)
example: 4096
NoteSummary:
type: object
required:
- note_path
- title
- updated
properties:
note_path:
type: string
example: api/design.md
title:
type: string
example: API Design
updated:
type: string
format: date-time
example: "2025-01-15T14:30:00Z"
NoteUpdate:
type: object
required:
- body
properties:
title:
type: string
nullable: true
description: Override title (if not set, will be extracted from frontmatter or body)
metadata:
$ref: '#/components/schemas/NoteMetadata'
body:
type: string
maxLength: 1048576
description: Markdown content (max 1 MiB UTF-8)
if_version:
type: integer
minimum: 1
nullable: true
description: Expected version for optimistic concurrency (409 if mismatch)
example: 4
NoteResponse:
type: object
required:
- status
- path
- version
properties:
status:
type: string
enum:
- ok
path:
type: string
example: api/design.md
version:
type: integer
example: 5
DeleteResponse:
type: object
required:
- status
- path
properties:
status:
type: string
enum:
- ok
path:
type: string
example: api/design.md
SearchResult:
type: object
required:
- note_path
- title
- snippet
- score
- updated
properties:
note_path:
type: string
example: api/auth.md
title:
type: string
example: Authentication Flow
snippet:
type: string
description: Highlighted excerpt with <mark> tags
example: "...describes the <mark>authentication</mark> process using JWT..."
score:
type: number
format: float
description: Relevance score (title 3x, body 1x, recency bonus)
example: 8.5
updated:
type: string
format: date-time
example: "2025-01-15T14:30:00Z"
BacklinkResult:
type: object
required:
- note_path
- title
properties:
note_path:
type: string
example: guides/architecture.md
title:
type: string
example: Architecture Overview
Tag:
type: object
required:
- tag
- count
properties:
tag:
type: string
description: Tag name (lowercase, normalized)
example: backend
count:
type: integer
minimum: 0
description: Number of notes with this tag
example: 15
IndexHealth:
type: object
required:
- user_id
- note_count
properties:
user_id:
type: string
example: alice
note_count:
type: integer
minimum: 0
description: Total notes indexed
example: 142
last_full_rebuild:
type: string
format: date-time
nullable: true
description: Timestamp of last manual rebuild
example: "2025-01-01T00:00:00Z"
last_incremental_update:
type: string
format: date-time
nullable: true
description: Timestamp of last write/delete operation
example: "2025-01-15T14:30:00Z"
RebuildResponse:
type: object
required:
- status
- notes_indexed
- duration_ms
properties:
status:
type: string
enum:
- ok
notes_indexed:
type: integer
minimum: 0
example: 142
duration_ms:
type: integer
minimum: 0
description: Rebuild duration in milliseconds
example: 1250
TokenResponse:
type: object
required:
- token
- token_type
- expires_at
properties:
token:
type: string
description: JWT access token
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
token_type:
type: string
enum:
- bearer
example: bearer
expires_at:
type: string
format: date-time
description: Token expiration timestamp (90 days from issuance)
example: "2025-04-15T10:30:00Z"
Error:
type: object
required:
- error
- message
properties:
error:
type: string
description: Error code (machine-readable)
example: validation_error
message:
type: string
description: Human-readable error message
example: Invalid note path format
detail:
type: object
nullable: true
description: Additional error context
additionalProperties: true
example:
field: note_path
reason: Path must end with .md
responses:
BadRequest:
description: Bad request (invalid input)
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
examples:
invalidPath:
summary: Invalid note path
value:
error: validation_error
message: Invalid note path format
detail:
field: note_path
reason: Path must end with .md
emptyQuery:
summary: Empty search query
value:
error: validation_error
message: Search query cannot be empty
detail:
field: query
reason: Query must be at least 1 character
Unauthorized:
description: Authentication required or token invalid/expired
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
examples:
missingToken:
summary: Missing authorization header
value:
error: unauthorized
message: Authorization header required
expiredToken:
summary: Expired JWT token
value:
error: token_expired
message: Token expired, please re-authenticate
invalidToken:
summary: Invalid JWT token
value:
error: invalid_token
message: Invalid token signature
Forbidden:
description: Forbidden (vault limit exceeded or permission denied)
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
examples:
vaultLimitExceeded:
summary: Vault note limit exceeded
value:
error: vault_note_limit_exceeded
message: Vault has reached maximum of 5,000 notes
detail:
current_count: 5000
max_limit: 5000
pathTraversal:
summary: Path traversal attempt
value:
error: forbidden
message: Path escapes vault root
detail:
note_path: ../../../etc/passwd
Conflict:
description: Version conflict (optimistic concurrency failure)
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: version_conflict
message: Note was modified since you opened it
detail:
expected_version: 4
current_version: 6
note_path: api/design.md
PayloadTooLarge:
description: Note content exceeds 1 MiB limit
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: payload_too_large
message: Note content exceeds maximum size of 1 MiB
detail:
size_bytes: 1572864
max_size_bytes: 1048576
InternalServerError:
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
error: internal_error
message: An unexpected error occurred
detail:
request_id: req_abc123
|