Skip to content

Commit 69bf008

Browse files
cangoektasdanez
authored andcommitted
Allow descriptions for oneOfType values (#301)
1 parent d25d262 commit 69bf008

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

src/__tests__/__snapshots__/main-test.js.snap

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,3 +889,47 @@ Object {
889889
},
890890
}
891891
`;
892+
893+
exports[`main fixtures processes component "component_17.js" without errors 1`] = `
894+
Object {
895+
"description": "",
896+
"displayName": "Foo",
897+
"methods": Array [],
898+
"props": Object {
899+
"oneOfTypeProp": Object {
900+
"description": "",
901+
"required": false,
902+
"type": Object {
903+
"name": "union",
904+
"value": Array [
905+
Object {
906+
"description": "Comment for type string",
907+
"name": "string",
908+
},
909+
Object {
910+
"name": "number",
911+
},
912+
],
913+
},
914+
},
915+
"shapeProp": Object {
916+
"description": "",
917+
"required": false,
918+
"type": Object {
919+
"name": "shape",
920+
"value": Object {
921+
"a": Object {
922+
"description": "Comment for property a",
923+
"name": "string",
924+
"required": false,
925+
},
926+
"b": Object {
927+
"name": "number",
928+
"required": false,
929+
},
930+
},
931+
},
932+
},
933+
},
934+
}
935+
`;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
*/
10+
11+
/**
12+
* Testing descriptions of shape and oneOfType values
13+
*/
14+
15+
import React from 'react';
16+
import PropTypes from 'prop-types';
17+
18+
export default function Foo(props) {
19+
return <div />;
20+
}
21+
22+
Foo.propTypes = {
23+
shapeProp: PropTypes.shape({
24+
/** Comment for property a */
25+
a: PropTypes.string,
26+
b: PropTypes.number
27+
}),
28+
oneOfTypeProp: PropTypes.oneOfType([
29+
/** Comment for type string */
30+
PropTypes.string,
31+
PropTypes.number
32+
])
33+
};

src/utils/getPropType.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ function getPropTypeOneOfType(argumentPath) {
8080
type.computed = true;
8181
type.value = printValue(argumentPath);
8282
} else {
83-
type.value = argumentPath.get('elements').map(getPropType);
83+
type.value = argumentPath.get('elements').map(function(itemPath) {
84+
const descriptor: PropTypeDescriptor = getPropType(itemPath);
85+
const docs = getDocblock(itemPath);
86+
if (docs) {
87+
descriptor.description = docs;
88+
}
89+
return descriptor;
90+
});
8491
}
8592
return type;
8693
}

0 commit comments

Comments
 (0)