feat: new api endpoints#5
Open
caviri wants to merge 2 commits into
Open
Conversation
rmfranken
approved these changes
Sep 25, 2025
Member
rmfranken
left a comment
There was a problem hiding this comment.
Looks good! The only thing I'm doubting is whether it makes sense to have fuzzy be false by default - I would expect the opposite.
I also tested quickly locally your code with a turtle document and it seems to work 👍 as expected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This PR refactors and enhances the RDF transformation API by splitting input modalities into two explicit endpoints, adding native raw Turtle support (without JSON wrapping), enforcing an explicit output serialization parameter, and improving OpenAPI clarity.
Summary of Key Improvements
POST /v1/things— Raw body (JSON-LD object/array or Turtle string).POST /v1/things/upload— Multipart file upload.Content-Type: text/turtleortext/plain) without wrapping it in JSON.serializationa mandatory parameter (jsonld|turtle) across both endpoints.fuzzy(bool, defaultfalse)fuzzy_threshold(int, 0–100, default90)multipart/form-datarepresentation.400for empty bodies or malformed content).Rationale
Previously a single endpoint attempted to multiplex raw JSON, Turtle, and file uploads. Because FastAPI/OpenAPI only allows one requestBody schema per operation, the presence of a
Fileparameter degraded the generated docs—Swagger showed onlymultipart/form-data, obscuring JSON-LD/Turtle raw usage. Splitting the endpoints yields explicit, self-documenting API surfaces and reduces client ambiguity.Backward Compatibility
POST /v1/things/upload.Types of Changes
feature.(Arguably a minor breaking path change for file uploads if they previously used
/v1/things; if your release policy treats endpoint path changes as breaking, tick breaking instead.)Checklist
API Specification (Delta)
1. Raw Transformation Endpoint
POST /v1/thingsAccepts one of:
application/ld+json— JSON-LD object/arrayapplication/json— Interpreted as JSON-LDtext/turtle— Turtle stringtext/plain— Treated as Turtle if parsableQuery Parameters:
serializationjsonld|turtlefuzzyfuzzy_thresholdSuccessful Responses:
200 OK— RDF graph serialized as:application/ld+jsonifserialization=jsonldtext/turtleifserialization=turtleError Responses:
400 Bad Request— Empty body, parse failure, or transformation error.2. Multipart Upload Endpoint
POST /v1/things/uploadConsumes:
multipart/form-dataForm Fields:
fileserializationjsonld|turtlefuzzyfuzzy_thresholdResponses: Same as raw endpoint.
OpenAPI Snippet (Representative)
Internal Implementation Notes
Refactored raw handler to read request.body() (byte-level) allowing flexible media types.
Heuristic fallback for format detection: leading { or [ => JSON-LD else Turtle.
serialization drives only output format; input autodetected.
Centralized _transform_bytes() pipeline ensures consistent logic across endpoints.
Logging captures ontology load failures without aborting transformation.
Testing Recommendations (Follow-Up PR)
Add tests for:
Raw JSON-LD → Turtle output
Raw Turtle → JSON-LD output
Multipart JSON-LD & Turtle flows
Fuzzy match ON vs OFF (with mock label map)
Mock OntologyManager in unit tests to avoid external SPARQL dependencies.