mirror of https://github.com/coder/coder.git
135 lines
3.3 KiB
Modula-2
135 lines
3.3 KiB
Modula-2
{{
|
|
function renderSingleResponseType(r) {
|
|
var content;
|
|
for (var ct in r.content) {
|
|
content = r.content[ct];
|
|
break;
|
|
}
|
|
if (!content) {
|
|
return "";
|
|
}
|
|
|
|
var ref = content.schema["x-widdershins-oldRef"];
|
|
if (!ref) {
|
|
ref = content.schema.items["x-widdershins-oldRef"];
|
|
}
|
|
const aType = ref.replace("#/components/schemas/","");
|
|
const href = aType.replace(".","").toLowerCase();
|
|
return "[" + aType + "](schemas.md#" + href + ")";
|
|
}
|
|
|
|
function renderResponseType(r) {
|
|
if (r.type == "array") {
|
|
return "array of " + renderSingleResponseType(r);
|
|
}
|
|
return renderSingleResponseType(r);
|
|
}
|
|
|
|
function renderDisplayName(p) {
|
|
if (p.displayName == "*anonymous*") {
|
|
return "[array item]";
|
|
}
|
|
let displayName = p.displayName.replace("**additionalProperties**", "[any property]");
|
|
return displayName;
|
|
}
|
|
|
|
function renderResponsePropertyType(p) {
|
|
if (p.$ref) {
|
|
const href = p.$ref.replace(".","").toLowerCase();
|
|
return "[" + p.$ref + "](schemas.md#" + href + ")";
|
|
}
|
|
|
|
if (p.type == 'array') {
|
|
return p.type;
|
|
}
|
|
|
|
return p.safeType;
|
|
}
|
|
}}
|
|
{{ data.responses = data.utils.getResponses(data); }}
|
|
{{ data.responseSchemas = false; }}
|
|
{{~ data.responses :response }}
|
|
{{ if (response.content) data.responseSchemas = true; }}
|
|
{{~}}
|
|
|
|
{{? data.responseSchemas }}
|
|
### Example responses
|
|
|
|
{{= data.utils.getResponseExamples(data) }}
|
|
{{?}}
|
|
|
|
{{= data.tags.section }}
|
|
### Responses
|
|
|
|
|Status|Meaning|Description|Schema|
|
|
|---|---|---|---|
|
|
{{~ data.responses :r}}|{{=r.status}}|{{=r.meaning}}|{{=r.description||''}}|{{= renderResponseType(r)}}|
|
|
{{~}}
|
|
|
|
{{ data.responseSchemas = false; }}
|
|
{{~ data.responses :response }}
|
|
{{ if (response.content && !response.$ref && !data.utils.isPrimitive(response.type)) data.responseSchemas = true; }}
|
|
{{~}}
|
|
{{? data.responseSchemas }}
|
|
<h3 id="{{=data.operationUniqueSlug}}-responseschema">Response Schema</h3>
|
|
{{~ data.responses :response}}
|
|
{{? response.content && !response.$ref && !data.utils.isPrimitive(response.type)}}
|
|
{{? Object.keys(response.content).length }}
|
|
{{ var responseKey = Object.keys(response.content)[0]; }}
|
|
{{ var responseSchema = response.content[responseKey].schema; }}
|
|
{{ var enums = []; }}
|
|
{{ var blocks = data.utils.schemaToArray(responseSchema,0,{trim:true,join:true},data); }}
|
|
{{ for (var block of blocks) {
|
|
for (var p of block.rows) {
|
|
if (p.schema && p.schema.enum) {
|
|
for (var e of p.schema.enum) {
|
|
enums.push({name:p.name,value:e});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}}
|
|
|
|
{{? blocks[0].rows.length || blocks[0].title }}
|
|
Status Code **{{=response.status}}**
|
|
|
|
{{~ blocks :block}}
|
|
{{? block.title }}*{{=block.title}}*
|
|
{{?}}
|
|
|Name|Type|Required|Restrictions|Description|
|
|
|---|---|---|---|---|
|
|
{{~block.rows :p}}|`{{=renderDisplayName(p)}}`|{{=renderResponsePropertyType(p)}}|{{=p.required}}|{{=p.restrictions||''}}|{{=p.description||''}}|
|
|
{{~}}
|
|
{{~}}
|
|
{{?}}
|
|
|
|
{{? enums.length > 0 }}
|
|
#### Enumerated Values
|
|
|
|
|Property|Value|
|
|
|---|---|
|
|
{{~ enums :e}}|`{{=e.name}}`|`{{=data.utils.toPrimitive(e.value)}}`|
|
|
{{~}}
|
|
|
|
{{?}}
|
|
{{?}}
|
|
|
|
{{ data.response = response; }}
|
|
|
|
{{?}}
|
|
{{~}}
|
|
{{?}}
|
|
|
|
{{ data.responseHeaders = data.utils.getResponseHeaders(data); }}
|
|
{{? data.responseHeaders.length }}
|
|
|
|
### Response Headers
|
|
|
|
|Status|Header|Type|Format|Description|
|
|
|---|---|---|---|---|
|
|
{{~ data.responseHeaders :h}}|{{=h.status}}|{{=h.header}}|{{=h.type}}|{{=h.format||''}}|{{=h.description||''}}|
|
|
{{~}}
|
|
|
|
{{?}}
|
|
{{= data.tags.endSection }}
|