Skip to content

Commit 938093e

Browse files
authored
Handle both mimeType and mimetype in REST responses. (#801)
While `mimeType` is the correct spelling of this data in the Render Node JSON specification, there may be data providers mistakenly using the `mimetype` spelling, so this change allows the renderer to handle both spellings as a temporary workaround until all providers are using the correct spelling. Resolves: rdar://124300035
1 parent a4bc961 commit 938093e

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/components/DocumentationTopic/PrimaryContent/RestResponses.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<template>
1212
<section>
1313
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
14-
<ParametersTable :parameters="responses" :changes="propertyChanges" key-by="status">
14+
<ParametersTable :parameters="sanitizedResponses" :changes="propertyChanges" key-by="status">
1515
<template #symbol="{ status, type, reason, content, changes }">
1616
<div class="response-name">
1717
<code>
@@ -26,7 +26,7 @@
2626
/>
2727
</template>
2828
<template
29-
#description="{ content, mimetype, reason, type, status, changes }"
29+
#description="{ content, mimeType, reason, type, status, changes }"
3030
>
3131
<PossiblyChangedType
3232
v-if="shouldShiftType({content, reason, status})"
@@ -38,8 +38,8 @@
3838
</div>
3939
<ContentNode v-if="content" :content="content" />
4040
<PossiblyChangedMimetype
41-
v-if="mimetype"
42-
:mimetype="mimetype"
41+
v-if="mimeType"
42+
:mimetype="mimeType"
4343
:changes="changes.mimetype"
4444
:change="changes.change"
4545
/>
@@ -81,8 +81,15 @@ export default {
8181
computed: {
8282
anchor: ({ title }) => anchorize(title),
8383
propertyChanges: ({ apiChanges }) => ((apiChanges || {}).restResponses),
84+
sanitizedResponses: ({ responses, sanitizeResponse }) => responses.map(sanitizeResponse),
8485
},
8586
methods: {
87+
// ensure that mimetype data gets handled correctly, regardless of its
88+
// spelling in the JSON (`mimeType` is the expected spelling, but some
89+
// data sources may be encoded as `mimetype` at present)
90+
sanitizeResponse: ({ mimetype, ...response }) => (mimetype
91+
? ({ ...response, mimeType: mimetype })
92+
: response),
8693
shouldShiftType:
8794
({ content = [], reason, status }) => (!(content.length || reason) && status),
8895
},

tests/unit/components/DocumentationTopic/PrimaryContent/RestResponses.spec.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('RestResponses', () => {
2828
{
2929
status: '200',
3030
reason: 'OK',
31-
mimetype: 'application/json',
31+
mimeType: 'application/json',
3232
type: [
3333
{
3434
kind: 'identifier',
@@ -99,7 +99,7 @@ describe('RestResponses', () => {
9999
});
100100

101101
it('hides mime-type if absent', () => {
102-
const { mimetype, ...otherProps } = propsData.responses[0];
102+
const { mimeType, ...otherProps } = propsData.responses[0];
103103
const wrapper = mountComponent({
104104
propsData: {
105105
...propsData,
@@ -262,4 +262,23 @@ describe('RestResponses', () => {
262262
expect(wrapper.find(PossiblyChangedType).props()).toHaveProperty('changes', changes['200'].type);
263263
expect(wrapper.find(PossiblyChangedMimetype).props()).toMatchObject({ changes: changes['200'].mimetype, change: changes['200'].change });
264264
});
265+
266+
it('handles data where `mimetype` spelling is used instead of `mimeType`', () => {
267+
const { mimetype, mimeType, ...firstResponse } = propsData.responses[0];
268+
269+
expect(mimeType).not.toBeUndefined();
270+
expect(mimetype).toBeUndefined();
271+
const wrapper = mountComponent({
272+
propsData: {
273+
...propsData,
274+
responses: [
275+
{
276+
...firstResponse,
277+
mimetype: mimeType,
278+
},
279+
],
280+
},
281+
});
282+
expect(wrapper.find(PossiblyChangedMimetype).exists()).toBe(true);
283+
});
265284
});

0 commit comments

Comments
 (0)