feature: support for Parameter.content (#5571)

* add `getParameterSchema` OAS helper

* use `Parameter.content.[firstKey].schema` as schema value when present

* `newValue` -> `initialValue`

* make `paramWithMeta` a const

* add trailing comma to `swagger2SchemaKeys`

* refactor `helpers` to a folder

* deprecate `src/core/utils.js` in favor of `src/core/helpers/`

* support `Parameter.content.[mediaType].schema` in validateParam

* reject `null` as an OAS3 object value

* expose Fetch errors in the browser console

* generate ParameterRow default values based on `content` values

* add tests for `getParameterSchema`

* remove debugger statement

* remove debugger statement

* don't apply `generatedSampleValue`s to parameters with `examples`

* remove extra semi

* disable JSON check in parameter runtime validation

* stringify JsonSchema_object textarea values

* add Cypress tests

* swagger-client@3.9.4
This commit is contained in:
kyle
2019-08-31 16:37:43 -07:00
committed by GitHub
parent 24c6473990
commit c9c3b2338e
11 changed files with 400 additions and 52 deletions

View File

@@ -0,0 +1,67 @@
/**
* @prettier
*/
import Im from "immutable"
const swagger2SchemaKeys = Im.Set.of(
"type",
"format",
"items",
"default",
"maximum",
"exclusiveMaximum",
"minimum",
"exclusiveMinimum",
"maxLength",
"minLength",
"pattern",
"maxItems",
"minItems",
"uniqueItems",
"enum",
"multipleOf"
)
/**
* Get the effective schema value for a parameter, or an empty Immutable.Map if
* no suitable schema can be found.
*
* Supports OpenAPI 3.0 `Parameter.content` priority -- since a Parameter Object
* cannot have both `schema` and `content`, this function ignores `schema` when
* `content` is present.
*
* @param {Immutable.Map} parameter The parameter to identify a schema for
* @param {object} config
* @param {boolean} config.isOAS3 Whether the parameter is from an OpenAPI 2.0
* or OpenAPI 3.0 definition
* @return {Immutable.Map} The desired schema
*/
export default function getParameterSchema(parameter, { isOAS3 } = {}) {
// Return empty Map if `parameter` isn't a Map
if (!Im.Map.isMap(parameter)) return Im.Map()
if (!isOAS3) {
// Swagger 2.0
if (parameter.get("in") === "body") {
return parameter.get("schema", Im.Map())
} else {
return parameter.filter((v, k) => swagger2SchemaKeys.includes(k))
}
}
// If we've reached here, the parameter is OpenAPI 3.0
if (parameter.get("content")) {
const parameterContentMediaTypes = parameter
.get("content", Im.Map({}))
.keySeq()
return parameter.getIn(
["content", parameterContentMediaTypes.first(), "schema"],
Im.Map()
)
}
return parameter.get("schema", Im.Map())
}