mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-23 00:56:33 +03:00
feat: Color of "default" Response depends on other successful responses are specified
closes #197
This commit is contained in:
parent
d175a4d6ae
commit
9d0dd25f30
|
@ -53,5 +53,12 @@ describe('Redoc components', () => {
|
||||||
let resp2 = component.responses[1];
|
let resp2 = component.responses[1];
|
||||||
resp1.code.should.not.be.equal(resp2.code);
|
resp1.code.should.not.be.equal(resp2.code);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set type of default as error if other 200-399 response is defined', () => {
|
||||||
|
component.pointer = '#/paths/~1test2/get/responses';
|
||||||
|
fixture.detectChanges();
|
||||||
|
let resp1 = component.responses[1];
|
||||||
|
resp1.type.should.be.equal('error');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,10 +44,16 @@ export class ResponsesList extends BaseSearchableComponent implements OnInit {
|
||||||
let responses = this.componentSchema;
|
let responses = this.componentSchema;
|
||||||
if (!responses) return;
|
if (!responses) return;
|
||||||
|
|
||||||
responses = Object.keys(responses).filter(respCode => {
|
let hasSuccessResponses = false;
|
||||||
|
let respCodes = Object.keys(responses).filter(respCode => {
|
||||||
|
if ((parseInt(respCode) >= 100) && (parseInt(respCode) <=399)) {
|
||||||
|
hasSuccessResponses = true;
|
||||||
|
}
|
||||||
// only response-codes and "default"
|
// only response-codes and "default"
|
||||||
return ( isNumeric(respCode) || (respCode === 'default'));
|
return ( isNumeric(respCode) || (respCode === 'default'));
|
||||||
}).map(respCode => {
|
});
|
||||||
|
|
||||||
|
responses = respCodes.map(respCode => {
|
||||||
let resp = responses[respCode];
|
let resp = responses[respCode];
|
||||||
resp.pointer = JsonPointer.join(this.pointer, respCode);
|
resp.pointer = JsonPointer.join(this.pointer, respCode);
|
||||||
if (resp.$ref) {
|
if (resp.$ref) {
|
||||||
|
@ -58,7 +64,7 @@ export class ResponsesList extends BaseSearchableComponent implements OnInit {
|
||||||
|
|
||||||
resp.empty = !resp.schema;
|
resp.empty = !resp.schema;
|
||||||
resp.code = respCode;
|
resp.code = respCode;
|
||||||
resp.type = statusCodeType(resp.code);
|
resp.type = statusCodeType(resp.code, hasSuccessResponses);
|
||||||
|
|
||||||
resp.expanded = false;
|
resp.expanded = false;
|
||||||
if (this.options.expandResponses) {
|
if (this.options.expandResponses) {
|
||||||
|
|
|
@ -37,7 +37,11 @@ export class ResponsesSamples extends BaseComponent implements OnInit {
|
||||||
let responses = this.componentSchema;
|
let responses = this.componentSchema;
|
||||||
if (!responses) return;
|
if (!responses) return;
|
||||||
|
|
||||||
|
let hasSuccessResponses = false;
|
||||||
responses = Object.keys(responses).filter(respCode => {
|
responses = Object.keys(responses).filter(respCode => {
|
||||||
|
if ((parseInt(respCode) >= 100) && (parseInt(respCode) <=399)) {
|
||||||
|
hasSuccessResponses = true;
|
||||||
|
}
|
||||||
// only response-codes and "default"
|
// only response-codes and "default"
|
||||||
return ( isNumeric(respCode) || (respCode === 'default'));
|
return ( isNumeric(respCode) || (respCode === 'default'));
|
||||||
}).map(respCode => {
|
}).map(respCode => {
|
||||||
|
@ -50,7 +54,7 @@ export class ResponsesSamples extends BaseComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.code = respCode;
|
resp.code = respCode;
|
||||||
resp.type = statusCodeType(resp.code);
|
resp.type = statusCodeType(resp.code, hasSuccessResponses);
|
||||||
return resp;
|
return resp;
|
||||||
})
|
})
|
||||||
.filter(response => hasExample(response));
|
.filter(response => hasExample(response));
|
||||||
|
|
|
@ -32,7 +32,11 @@ export function groupBy<T>(array: T[], key:string):StringMap<T[]> {
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function statusCodeType(statusCode) {
|
export function statusCodeType(statusCode, defaultAsError = false) {
|
||||||
|
if (statusCode === 'default') {
|
||||||
|
return defaultAsError ? 'error' : 'success';
|
||||||
|
}
|
||||||
|
|
||||||
if (statusCode < 100 || statusCode > 599) {
|
if (statusCode < 100 || statusCode > 599) {
|
||||||
throw new Error('invalid HTTP code');
|
throw new Error('invalid HTTP code');
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/test2": {
|
||||||
|
"get": {
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "successful operation",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/def1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"default": {
|
||||||
|
"description": "successful operation",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/def1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
"definitions": {
|
"definitions": {
|
||||||
"def1": {
|
"def1": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user