SchemaViewer
Domain · API DocJSON Schema nesnesini hiyerarşik olarak görselleştirir. İç içe nesneler details/summary ile genişletilebilir.
id*
string
UUID identifier
name*
string
Display name
price*
number
<%- include('modules/domain/api-doc/SchemaViewer', {
schema: {
type: 'object',
required: ['id', 'name', 'price'],
properties: {
id: { type: 'string', description: 'UUID identifier', readOnly: true },
name: { type: 'string', description: 'Display name' },
price: { type: 'number' },
}
}
}) %>
<%
var _schema = locals.schema || {};
var _title = locals.title || null;
var _depth = locals.depth || 0;
var typeColors = {
string: 'text-success-fg',
number: 'text-primary',
integer: 'text-primary',
boolean: 'text-secondary',
array: 'text-warning-fg',
object: 'text-text-secondary',
'null': 'text-text-disabled',
};
function getTypeLabel(s) {
if (!s) return '?';
if (s.enum) return 'enum';
if (s.$ref) return s.$ref.split('/').pop() || '?';
var t = s.type || (s.properties ? 'object' : s.items ? 'array' : '?');
if (t === 'array' && s.items) return 'array[' + (s.items.type || '?') + ']';
return t;
}
function getTypeColor(s) {
if (!s) return 'text-text-secondary';
var t = s.type || (s.properties ? 'object' : s.items ? 'array' : null);
return typeColors[t] || 'text-text-secondary';
}
var properties = (_schema.type === 'object' || _schema.properties) ? (_schema.properties || {}) : null;
var required = _schema.required || [];
var isArray = _schema.type === 'array';
var enumVals = _schema.enum || null;
var pills = [];
if (_schema.nullable) pills.push('nullable');
if (_schema.readOnly) pills.push('read-only');
if (_schema.writeOnly) pills.push('write-only');
if (_schema.deprecated)pills.push('deprecated');
var constraints = [];
if (_schema.minLength != null) constraints.push('min: ' + _schema.minLength);
if (_schema.maxLength != null) constraints.push('max: ' + _schema.maxLength);
if (_schema.minimum != null) constraints.push('≥ ' + _schema.minimum);
if (_schema.maximum != null) constraints.push('≤ ' + _schema.maximum);
if (_schema.pattern) constraints.push('pattern: ' + _schema.pattern);
%>
<% if (_title) { %>
<%= _title %>
<% } %>
<% if (enumVals && enumVals.length) { %>
<% enumVals.forEach(function(v) { %>
<%= JSON.stringify(v) %>
<% }); %>
<% } %>
<% if (isArray && _schema.items) { %>
array
→ items:
<%= getTypeLabel(_schema.items) %>
<% if (_schema.items.description) { %><%= _schema.items.description %><% } %>
<% } %>
<% if (properties) { %>
<% Object.keys(properties).forEach(function(key) {
var prop = properties[key];
var isReq = required.indexOf(key) !== -1;
var hasChildren = (prop.type === 'object' && prop.properties) || (prop.type === 'array' && prop.items && prop.items.properties);
var typeLabel = getTypeLabel(prop);
var typeColor = getTypeColor(prop);
var propPills = [];
if (prop.nullable) propPills.push('nullable');
if (prop.readOnly) propPills.push('read-only');
if (prop.writeOnly) propPills.push('write-only');
if (prop.deprecated) propPills.push('deprecated');
%>
<% if (hasChildren) { %>
<%= key %><% if (isReq) { %>*<% } %>
<%= typeLabel %>
<% propPills.forEach(function(p) { %><% }); %>
<% if (prop.description) { %><%= prop.description %><% } %>
<%- include('./SchemaViewer', { schema: prop.type === 'array' ? prop.items : prop, depth: _depth + 1 }) %>
<% } else { %>
<%= key %><% if (isReq) { %>*<% } %>
<%= typeLabel %><% if (prop.format) { %>(<%= prop.format %>)<% } %>
<% propPills.forEach(function(p) { %><% }); %>
<% if (prop.description) { %><%= prop.description %><% } %>
<% if (prop.default !== undefined) { %>default: <%= JSON.stringify(prop.default) %><% } %>
<% if (prop.enum && prop.enum.length) { %>
<% prop.enum.forEach(function(v) { %>
<%= JSON.stringify(v) %>
<% }); %>
<% } %>
<% } %>
<% }); %>
<% } %>
<% if (!properties && !isArray && !enumVals) { %>
<%= getTypeLabel(_schema) %>
<% if (_schema.description) { %> — <%= _schema.description %><% } %>
<% } %>
<% if (constraints.length) { %>
<% constraints.forEach(function(c) { %><%= c %><% }); %>
<% } %>