Skip to content

Commit a5cbca1

Browse files
authored
Defer to JSON provided titles for REST param attributes. (#12)
There may be scenarios where the simple "Minimum"/"Maximum" titles are not descriptive enough for a particular parameter attribute, and the JSON already provides more descriptive names like "Minimum Length" or "Maximum Value", etc.
1 parent a7d04d4 commit a5cbca1

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/components/DocumentationTopic/PrimaryContent/ParameterAttributes.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
v-if="shouldRender(AttributeKind.default)"
1515
v-bind="{ kind: AttributeKind.default, attributes: attributesObject, changes }">
1616
<template slot-scope="{ attribute }">
17-
Default: <code>{{ attribute.value }}</code>
17+
{{ attribute.title || 'Default' }}: <code>{{ attribute.value }}</code>
1818
</template>
1919
</ParameterMetaAttribute>
2020
<ParameterMetaAttribute
2121
v-if="shouldRender(AttributeKind.minimum)"
2222
v-bind="{ kind: AttributeKind.minimum, attributes: attributesObject, changes }">
2323
<template slot-scope="{ attribute }">
24-
Minimum: <code>{{ attribute.value }}</code>
24+
{{ attribute.title || 'Minimum' }}: <code>{{ attribute.value }}</code>
2525
</template>
2626
</ParameterMetaAttribute>
2727
<ParameterMetaAttribute
2828
v-if="shouldRender(AttributeKind.minimumExclusive)"
2929
v-bind="{ kind: AttributeKind.minimumExclusive, attributes: attributesObject, changes }">
3030
<template slot-scope="{ attribute }">
31-
Minimum: <code>&gt; {{ attribute.value }}</code>
31+
{{ attribute.title || 'Minimum' }}: <code>&gt; {{ attribute.value }}</code>
3232
</template>
3333
</ParameterMetaAttribute>
3434
<ParameterMetaAttribute
3535
v-if="shouldRender(AttributeKind.maximum)"
3636
v-bind="{ kind: AttributeKind.maximum, attributes: attributesObject, changes }">
3737
<template slot-scope="{ attribute }">
38-
Maximum: <code>{{ attribute.value }}</code>
38+
{{ attribute.title || 'Maximum' }}: <code>{{ attribute.value }}</code>
3939
</template>
4040
</ParameterMetaAttribute>
4141
<ParameterMetaAttribute
4242
v-if="shouldRender(AttributeKind.maximumExclusive)"
4343
v-bind="{ kind: AttributeKind.maximumExclusive, attributes: attributesObject, changes }">
4444
<template slot-scope="{ attribute }">
45-
Maximum: <code>&lt; {{ attribute.value }}</code>
45+
{{ attribute.title || 'Maximum' }}: <code>&lt; {{ attribute.value }}</code>
4646
</template>
4747
</ParameterMetaAttribute>
4848
<ParameterMetaAttribute

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ const { AttributeKind } = ParameterAttributes.constants;
1616

1717
const { ParameterMetaAttribute } = ParameterAttributes.components;
1818

19-
const defaultMetadata = { kind: AttributeKind.default, value: 3 };
20-
const minimumMetadata = { kind: AttributeKind.minimum, value: 20 };
21-
const maximumMetadata = { kind: AttributeKind.maximum, value: 50 };
22-
const minimumExclusiveMetadata = { kind: AttributeKind.minimumExclusive, value: 2 };
23-
const maximumExclusiveMetadata = { kind: AttributeKind.maximumExclusive, value: 5 };
19+
const defaultMetadata = { kind: AttributeKind.default, value: 3, title: 'Default' };
20+
const minimumMetadata = { kind: AttributeKind.minimum, value: 20, title: 'Minimum Value' };
21+
const maximumMetadata = { kind: AttributeKind.maximum, value: 50, title: 'Maximum Length' };
22+
const minimumExclusiveMetadata = { kind: AttributeKind.minimumExclusive, value: 2, title: 'Minimum' };
23+
const maximumExclusiveMetadata = { kind: AttributeKind.maximumExclusive, value: 5, title: 'Maximum' };
2424
const allowedValuesMetadata = {
2525
kind: AttributeKind.allowedValues,
2626
values: ["'one'", "'two'"],
27+
title: 'Allowed Values',
2728
};
2829
const allowedTypesMetadata = {
2930
kind: AttributeKind.allowedTypes,
3031
values: [
3132
[{ kind: 'text', text: 'string' }],
3233
[{ kind: 'text', text: 'number' }],
3334
],
35+
title: 'Allowed Types',
3436
};
3537

3638
const mountComponent = propsData => mount(ParameterAttributes, {
@@ -60,12 +62,12 @@ describe('ParameterAttributes', () => {
6062
metadata
6163
.at(0)
6264
.text(),
63-
).toBe('Minimum: 20');
65+
).toBe('Minimum Value: 20');
6466
expect(
6567
metadata
6668
.at(1)
6769
.text(),
68-
).toBe('Maximum: 50');
70+
).toBe('Maximum Length: 50');
6971
});
7072

7173
it('displays exclusive min/max metadata', () => {
@@ -150,8 +152,8 @@ describe('ParameterAttributes', () => {
150152
it('passes changes to default metadata', () => {
151153
const changes = {
152154
[AttributeKind.default]: {
153-
new: { value: 4 },
154-
previous: { value: 2 },
155+
new: { value: 4, title: 'Default' },
156+
previous: { value: 2, title: 'Default' },
155157
},
156158
};
157159
const wrapper = mountComponent({
@@ -170,12 +172,12 @@ describe('ParameterAttributes', () => {
170172
it('passes changes to minimum/maximum metadata', () => {
171173
const changes = {
172174
[AttributeKind.minimum]: {
173-
new: { value: 4 },
174-
previous: { value: 2 },
175+
new: { value: 4, title: 'Minimum' },
176+
previous: { value: 2, title: 'Minimum' },
175177
},
176178
[AttributeKind.maximum]: {
177-
new: { value: 10 },
178-
previous: { value: 7 },
179+
new: { value: 10, title: 'Maximum' },
180+
previous: { value: 7, title: 'Maximum' },
179181
},
180182
};
181183

@@ -208,12 +210,12 @@ describe('ParameterAttributes', () => {
208210
it('passes changes to exclusive minimum/maximum metadata', () => {
209211
const changes = {
210212
[AttributeKind.minimumExclusive]: {
211-
new: { value: 4 },
212-
previous: { value: 2 },
213+
new: { value: 4, title: 'Minimum' },
214+
previous: { value: 2, title: 'Minimum' },
213215
},
214216
[AttributeKind.maximumExclusive]: {
215-
new: { value: 10 },
216-
previous: { value: 7 },
217+
new: { value: 10, title: 'Maximum' },
218+
previous: { value: 7, title: 'Maximum' },
217219
},
218220
};
219221

0 commit comments

Comments
 (0)