# Modelbuilder used to access sources.
var modelbuilder: ModelBuilder
+
+ # The JSON API does not filter anything by default.
+ #
+ # So we can cache the model view.
+ var view: ModelView is lazy do
+ var view = new ModelView(model)
+ view.min_visibility = private_visibility
+ view.include_fictive = true
+ view.include_empty_doc = true
+ view.include_attribute = true
+ view.include_test_suite = true
+ return view
+ end
end
# Specific handler for the nitweb API.
return model.mentity_by_full_name(full_name.from_percent_encoding)
end
- # The JSON API does not filter anything by default.
- #
- # So we can cache the model view.
- var view: ModelView is lazy do
- var view = new ModelView(config.model)
- view.min_visibility = private_visibility
- view.include_fictive = true
- view.include_empty_doc = true
- view.include_attribute = true
- view.include_test_suite = true
- return view
- end
-
# Try to load the mentity from uri with `/:id`.
#
# Send 400 if `:id` is null.
res.api_error(400, "Expected mentity full name")
return null
end
- var mentity = find_mentity(view, id)
+ var mentity = find_mentity(config.view, id)
if mentity == null then
res.api_error(404, "MEntity `{id}` not found")
end
return obj
end
- redef fun to_json do return json.to_json
+ redef fun serialize_to(v) do json.serialize_to(v)
end
# Fullname representation that can be used to build decorated links
class Namespace
super Array[nullable NSEntity]
super NSEntity
+ serialize
redef fun to_s do return self.join("")
- redef fun to_json do return (new JsonArray.from(self)).to_json
+ redef fun serialize_to(v) do to_a.serialize_to(v)
end
# Something that goes in a Namespace
# an infinite loop.
class NSRef
super NSEntity
+ serialize
# The mentity to link to/
var mentity: MEntity
- redef fun to_json do
+ redef fun serialize_to(v) do
var obj = new JsonObject
obj["web_url"] = mentity.web_url
obj["api_url"] = mentity.api_url
obj["name"] = mentity.name
- return obj.to_json
+ obj.serialize_to(v)
end
end
return obj
end
- redef fun to_json do return json.to_json
+ redef fun serialize_to(v) do json.serialize_to(v)
end