forked from swagger-api/swagger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to "examples" as per OpenAPI 3.0.0 spec
Merged from swagger-api#3616, then collected and re-applied the diff to have a nice git history
- Loading branch information
Showing
8 changed files
with
183 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react" | ||
import PropTypes from "prop-types" | ||
|
||
/** | ||
* ExternalValue is a <HighlightCode> with content set to an external location. | ||
* usage: <ExternalValue location="http://example.com/path/to/file" /> | ||
*/ | ||
export default class ExternalValue extends React.Component { | ||
static propTypes = { | ||
getComponent: PropTypes.func.isRequired, | ||
location: PropTypes.string.isRequired | ||
} | ||
|
||
constructor(props, context) { | ||
super(props, context) | ||
} | ||
|
||
render() { | ||
let { location } = this.props | ||
// const Markdown = getComponent("Markdown") | ||
|
||
// TODO should externalValue be fetched and displayed inline? | ||
|
||
return ( | ||
<div> | ||
<a href={location} target="_blank" title={location} >Open ExternalValue</a> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import memoizee from "memoizee" | ||
import { fromJS } from "immutable" | ||
|
||
/** | ||
* Convert OAS3 "Examples" (in requestBody) section and convert to Map | ||
* @param examplesInSpec {object} "examples" in OAS3 spec | ||
* @returns {Map} Map {name: {summary, description, value, externalValue}} | ||
*/ | ||
export const getExamples = (examplesInSpec) => { | ||
return fromJS(examplesInSpec) | ||
} | ||
|
||
export const memoizedGetExamples = memoizee(getExamples) | ||
|
||
/** | ||
* Convert 'value' to serialized format, so can be handled correctly in <input> | ||
* @param value value | ||
* @param parameter {OrderedMap} parameter in spec | ||
*/ | ||
export const formatParamValue = (value, parameter) => { | ||
if (typeof ( value ) === "string") { | ||
return value | ||
} else { | ||
// TODO apply 'style', 'explode', 'allowReserved' in OAS3 | ||
return JSON.stringify(value, null, 2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters