Skip to content

Commit

Permalink
Merge pull request #237 from Authress-Engineering/remove-duplicate-ac…
Browse files Browse the repository at this point in the history
…cept-headers

Remove duplicate accept header response types. fix #236
  • Loading branch information
wparad authored Feb 17, 2024
2 parents 28e8b85 + 233d016 commit d51be81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/api-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class ApiResponse extends LitElement {
}}"
class='m-btn small ${this.selectedStatus === respStatus ? 'primary' : ''}'
part="btn--resp ${this.selectedStatus === respStatus ? 'btn-fill--resp' : 'btn-outline--resp'} btn-response-status"
style='margin: 8px 4px 0 0'>
style='margin: 8px 4px 0 0; text-transform: capitalize'>
${respStatus}
</button>`
}`)
Expand Down
6 changes: 4 additions & 2 deletions src/utils/spec-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ function groupByTags(openApiSpec) {
const finalParameters = pathOrHookObj.parameters?.slice(0) || [];
finalParameters.push(...commonParams.filter((commonParam) => !finalParameters.some((param) => (commonParam.name === param.name && commonParam.in === param.in))));

const responseContentTypes = Object.values(pathOrHookObj.responses || {}).map(response => Object.keys(response.content || {})).flat(1);
if (!finalParameters.some(p => p.in === 'header' && p.name.match(/^accept$/i)) && responseContentTypes.length > 1) {
const successResponseKeys = Object.keys(pathOrHookObj.responses || {}).filter(r => !r.match(/^\d{3}$/i) || r.match(/^[23]\d{2}$/i));
const responseContentTypesMap = successResponseKeys.map(key => pathOrHookObj.responses[key]).reduce((acc, response) => Object.assign({}, acc, response.content || {}), {});
const responseContentTypes = Object.keys(responseContentTypesMap).sort((a, b) => a.localeCompare(b));
if (!finalParameters.some(p => p.in === 'header' && p.name.match(/^accept$/i)) && Object.keys(responseContentTypesMap).length > 1) {
finalParameters.push({
in: 'header',
name: 'Accept',
Expand Down

0 comments on commit d51be81

Please sign in to comment.