Improve enum values for Enum Type in Swagger ReadOnly documentation (#4191)

* Adding enum values for Enum Type in Swagger ReadOnly documentation

* Adding enum values for Enum Type in Swagger ReadOnly documentation (optimisation) and also adding default/example value

* Add new display enums, defaults, and examples when not in TIO mode (another way to have enums values in swagger.json)

* Fix npm test result

* review corrections

* fix: don't render parameter description if field is empty

* use cross-version schema variable to access properties

* pass className through Markdown component usage

* add per-field classNames to Markdown for easier styling + testing

* remove parameter Example field (out-of-scope for this PR)

* get default value from schema instead of top-level parameter

* tests: add e2e cases for swagger2 and oas3

* remove `swagger-petstore-enum.json`

the purpose of this file lives on in the e2e test specs folder

* add missing proptypes validation

* use `classnames` to more effectively union class names
This commit is contained in:
David DE CARVALHO
2018-04-06 03:48:19 +02:00
committed by kyle
parent d90353228a
commit 39d34523b9
6 changed files with 138 additions and 37 deletions

View File

@@ -107,40 +107,43 @@ export default class ParameterRow extends Component {
let paramWithMeta = specSelectors.parameterWithMeta(pathMethod, param.get("name"), param.get("in"))
let schema = param.get("schema")
let type = isOAS3 && isOAS3() ? param.getIn(["schema", "type"]) : param.get("type")
let schema = isOAS3 && isOAS3() ? param.get("schema") : param
let type = schema.get("type")
let isFormData = inType === "formData"
let isFormDataSupported = "FormData" in win
let required = param.get("required")
let itemType = param.getIn(isOAS3 && isOAS3() ? ["schema", "items", "type"] : ["items", "type"])
let itemType = schema.getIn(["items", "type"])
let value = paramWithMeta ? paramWithMeta.get("value") : ""
let extensions = getExtensions(param)
let paramItems // undefined
let paramItemsEnum // undefined
let isDisplayParamItemsEnum = false
let paramEnum // undefined
let paramDefaultValue // undefined
let paramExample // undefined
let isDisplayParamEnum = false
if ( param !== undefined ) {
paramItems = param.get("items")
paramItems = schema.get("items")
}
if ( paramItems !== undefined ) {
paramItemsEnum = param.get("items").get("enum")
if (paramItems !== undefined) {
paramEnum = paramItems.get("enum")
paramDefaultValue = paramItems.get("default")
} else {
paramEnum = schema.get("enum")
}
if ( paramItemsEnum !== undefined ) {
if (paramItemsEnum.size > 0) {
isDisplayParamItemsEnum = true
}
if ( paramEnum !== undefined && paramEnum.size > 0) {
isDisplayParamEnum = true
}
// Default and Example Value for readonly doc
let paramDefaultValue // undefined
let paramExample // undefined
if ( param !== undefined ) {
paramDefaultValue = param.get("default")
paramDefaultValue = schema.get("default")
paramExample = param.get("example")
}
if (isDisplayParamItemsEnum) { // if we have an array, default value is in "items"
paramDefaultValue = paramItems.get("default")
if (paramExample === undefined) {
paramExample = param.get("x-example")
}
}
return (
@@ -159,23 +162,18 @@ export default class ParameterRow extends Component {
</td>
<td className="col parameters-col_description">
<Markdown source={ param.get("description") }/>
{ param.get("description") ? <Markdown source={ param.get("description") }/> : null }
{ (bodyParam || !isExecute) && isDisplayParamItemsEnum ?
<Markdown source={
"<i>Available values</i>: " + paramItemsEnum.map(function(item) {
{ (bodyParam || !isExecute) && isDisplayParamEnum ?
<Markdown className="parameter__enum" source={
"<i>Available values</i> : " + paramEnum.map(function(item) {
return item
}).toArray().join(", ")}/>
: null
}
{ (bodyParam || !isExecute) && paramDefaultValue !== undefined ?
<Markdown source={"<i>Default value</i>: " + paramDefaultValue}/>
: null
}
{ (bodyParam || !isExecute) && paramExample !== undefined ?
<Markdown source={"<i>Example</i>: " + paramExample}/>
<Markdown className="parameter__default" source={"<i>Default value</i> : " + paramDefaultValue}/>
: null
}
@@ -189,7 +187,7 @@ export default class ParameterRow extends Component {
description={param.get("description") ? `${param.get("name")} - ${param.get("description")}` : `${param.get("name")}`}
onChange={ this.onChangeWrapper }
errors={ paramWithMeta.get("errors") }
schema={ isOAS3 && isOAS3() ? param.get("schema") : param }/>
schema={ schema }/>
}