Compare commits

...
22 Commits
Author SHA1 Message Date
kyle 1646b270f8 Merge pull request #4052 from shockey/v/3.8.0
v3.8.0
2017-12-23 02:03:30 -06:00
Kyle Shockey 03f80dcc70 v3.8.0 2017-12-23 01:58:57 -06:00
kyle f982eb4894 Merge pull request #4049 from shockey/support/editor-validation-refactor
Supporting changes for Swagger-Editor semantic validation changes
2017-12-23 00:25:30 -06:00
kyle 10b4f5d8a7 Merge branch 'master' into support/editor-validation-refactor 2017-12-23 00:18:26 -06:00
kyle 9c2f9d2059 Merge pull request #4051 from shockey/bug/4040-default-tag
Don't parse non-method path keys as operations
2017-12-22 23:39:38 -06:00
kyle 7469705bef Merge branch 'master' into bug/4040-default-tag 2017-12-22 23:35:54 -06:00
Kyle Shockey 57db23ed1f Don't parse non-method path keys as operations 2017-12-22 23:30:38 -06:00
kyle 135fc34077 Merge pull request #4050 from shockey/bug/editor-1596
Prevent non-object values from being dispatched as new JSON content
2017-12-22 23:25:26 -06:00
Kyle Shockey ca0b248df2 Prevent non-object values from being dispatched as new JSON content 2017-12-22 23:19:10 -06:00
Kyle Shockey 27156bb79d Linter fixes 2017-12-22 22:58:37 -06:00
Kyle Shockey b03bf90664 Allow initialState key deletion 2017-12-22 22:41:53 -06:00
Kyle Shockey a9ebdb8a7a Add layout back to initalState 2017-12-22 22:29:55 -06:00
Kyle Shockey 68c689e491 Type-check errors before iterating over them 2017-12-20 13:59:22 -06:00
Kyle Shockey 150ebf3bc0 Add ability to explicitly skip rendering 2017-12-19 23:46:09 -06:00
Kyle Shockey e07b105b29 Remove layout from default initial state 2017-12-19 23:45:35 -06:00
Kyle Shockey 022b660b8c Merge branch 'master' into support/editor-validation-refactor 2017-12-19 23:29:59 -06:00
Kyle Shockey a2f8d289a0 Fix error transformer imports 2017-12-15 14:17:12 -08:00
Kyle Shockey 2dd25abbdd Move initOAuth attacher out of core constructor 2017-12-15 14:16:44 -08:00
Kyle Shockey c1ae4c133d Add afterLoad plugin interface 2017-12-14 21:01:37 -08:00
Kyle Shockey 85c83931c4 Move configs plugin to core 2017-12-14 20:17:31 -08:00
Kyle Shockey b5c713a72b Eliminate require.context usage 2017-12-14 20:17:31 -08:00
Kyle Shockey ca7f7ea78b Stop using require.context in error transformers 2017-12-14 20:17:31 -08:00
26 changed files with 147 additions and 97 deletions
+8
View File
@@ -9,6 +9,10 @@
[
"module-alias",
[
{
"expose": "root",
"src": "."
},
{
"expose": "components",
"src": "src/core/components"
@@ -17,6 +21,10 @@
"expose": "core",
"src": "src/core"
},
{
"expose": "plugins",
"src": "src/plugins"
},
{
"expose": "img",
"src": "src/img"
+1 -1
View File
@@ -22,7 +22,7 @@ The OpenAPI Specification has undergone 5 revisions since initial creation in 20
Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes
------------------ | ------------ | -------------------------- | -----
3.7.0 | 2017-12-15 | 2.0, 3.0 | [tag v3.7.0](https://github.com/swagger-api/swagger-ui/tree/v3.7.0)
3.8.0 | 2017-12-15 | 2.0, 3.0 | [tag v3.8.0](https://github.com/swagger-api/swagger-ui/tree/v3.8.0)
3.0.21 | 2017-07-26 | 2.0 | [tag v3.0.21](https://github.com/swagger-api/swagger-ui/tree/v3.0.21)
2.2.10 | 2017-01-04 | 1.1, 1.2, 2.0 | [tag v2.2.10](https://github.com/swagger-api/swagger-ui/tree/v2.2.10)
2.1.5 | 2016-07-20 | 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-ui/tree/v2.1.5)
+15 -15
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+30 -1
View File
@@ -19,7 +19,8 @@ A plugin return value may contain any of these keys, where `myStateKey` is a nam
},
components: {},
wrapComponents: {},
fn: {}
afterLoad: (system) => {}
fn: {},
}
```
@@ -363,7 +364,35 @@ const MyWrapComponentPlugin = function(system) {
}
```
##### `afterLoad`
The `afterLoad` plugin method allows you to get a reference to the system after your plugin has been registered with the system.
This interface is used in the core code to attach methods that are driven by bound selectors or actions directly to the system.
```javascript
const MyMethodProvidingPlugin = function() {
return {
afterLoad(system) {
// at this point in time, your actions have been bound into the system
// so you can do things with them
system.myMethod = system.exampleActions.updateFavoriteColor
},
statePlugins: {
example: {
actions: {
updateFavoriteColor: (str) => {
return {
type: "EXAMPLE_SET_FAV_COLOR",
payload: str
}
}
}
}
}
}
}
```
##### fn
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "swagger-ui",
"version": "3.7.0",
"version": "3.8.0",
"main": "dist/swagger-ui.js",
"repository": "git@github.com:swagger-api/swagger-ui.git",
"contributors": [
+17 -2
View File
@@ -92,6 +92,20 @@ module.exports = function SwaggerUI(opts) {
}, constructorConfig.initialState)
}
if(constructorConfig.initialState) {
// if the user sets a key as `undefined`, that signals to us that we
// should delete the key entirely.
// known usage: Swagger-Editor validate plugin tests
for (var key in constructorConfig.initialState) {
if(
constructorConfig.initialState.hasOwnProperty(key)
&& constructorConfig.initialState[key] === undefined
) {
delete storeConfigs.state[key]
}
}
}
let inlinePlugin = ()=> {
return {
fn: constructorConfig.fn,
@@ -105,8 +119,6 @@ module.exports = function SwaggerUI(opts) {
var system = store.getSystem()
system.initOAuth = system.authActions.configureAuth
const downloadSpec = (fetchedConfig) => {
if(typeof constructorConfig !== "object") {
return system
@@ -138,6 +150,9 @@ module.exports = function SwaggerUI(opts) {
} else if(mergedConfig.dom_id) {
let domNode = document.querySelector(mergedConfig.dom_id)
system.render(domNode, "App")
} else if(mergedConfig.dom_id === null || mergedConfig.domNode === null) {
// do nothing
// this is useful for testing that does not need to do any rendering
} else {
console.error("Skipped rendering: no `dom_id` or `domNode` was specified")
}
+3
View File
@@ -5,6 +5,9 @@ import * as specWrapActionReplacements from "./spec-wrap-actions"
export default function() {
return {
afterLoad(system) {
system.initOAuth = system.authActions.configureAuth
},
statePlugins: {
auth: {
reducers,
@@ -1,5 +1,5 @@
import YAML from "js-yaml"
import yamlConfig from "../../../swagger-config.yaml"
import yamlConfig from "root/swagger-config.yaml"
import * as actions from "./actions"
import * as selectors from "./selectors"
import reducers from "./reducers"
@@ -1,26 +1,13 @@
import reduce from "lodash/reduce"
let request = require.context("./transformers/", true, /\.js$/)
let errorTransformers = []
import * as NotOfType from "./transformers/not-of-type"
import * as ParameterOneOf from "./transformers/parameter-oneof"
import * as StripInstance from "./transformers/strip-instance"
request.keys().forEach( function( key ){
if( key === "./hook.js" ) {
return
}
if( !key.match(/js$/) ) {
return
}
if( key.slice(2).indexOf("/") > -1) {
// skip files in subdirs
return
}
errorTransformers.push({
name: toTitleCase(key).replace(".js", "").replace("./", ""),
transform: request(key).transform
})
})
const errorTransformers = [
NotOfType,
ParameterOneOf,
StripInstance
]
export default function transformErrors (errors, system) {
let inputs = {
@@ -47,10 +34,3 @@ export default function transformErrors (errors, system) {
})
}
function toTitleCase(str) {
return str
.split("-")
.map(substr => substr[0].toUpperCase() + substr.slice(1))
.join("")
}
@@ -72,10 +72,10 @@ export const servers = onlyOAS3(createSelector(
export const isOAS3 = (ori, system) => () => {
const spec = system.getSystem().specSelectors.specJson()
return isOAS3Helper(spec)
return isOAS3Helper(Map.isMap(spec) ? spec : Map())
}
export const isSwagger2 = (ori, system) => () => {
const spec = system.getSystem().specSelectors.specJson()
return isSwagger2Helper(spec)
return isSwagger2Helper(Map.isMap(spec) ? spec : Map())
}
+2 -3
View File
@@ -68,7 +68,7 @@ export const parseToJson = (str) => ({specActions, specSelectors, errActions}) =
line: e.mark && e.mark.line ? e.mark.line + 1 : undefined
})
}
if(json) {
if(json && typeof json === "object") {
return specActions.updateJsonSpec(json)
}
return {}
@@ -105,8 +105,7 @@ export const resolveSpec = (json, url) => ({specActions, specSelectors, errActio
errActions.clear({
type: "thrown"
})
if(errors.length > 0) {
if(Array.isArray(errors) && errors.length > 0) {
let preparedErrors = errors
.map(err => {
console.error(err)
+7
View File
@@ -4,6 +4,10 @@ import { fromJS, Set, Map, OrderedMap, List } from "immutable"
const DEFAULT_TAG = "default"
const OPERATION_METHODS = [
"get", "put", "post", "delete", "options", "head", "patch", "trace"
]
const state = state => {
return state || Map()
}
@@ -95,6 +99,9 @@ export const operations = createSelector(
return {}
}
path.forEach((operation, method) => {
if(OPERATION_METHODS.indexOf(method) < 0) {
return
}
list = list.push(fromJS({
path: pathName,
method,
@@ -1,17 +0,0 @@
import { pascalCaseFilename } from "core/utils"
const request = require.context(".", true, /\.jsx?$/)
request.keys().forEach( function( key ){
if( key === "./index.js" ) {
return
}
// if( key.slice(2).indexOf("/") > -1) {
// // skip files in subdirs
// return
// }
let mod = request(key)
module.exports[pascalCaseFilename(key)] = mod.default ? mod.default : mod
})
+4 -3
View File
@@ -1,5 +1,4 @@
import * as components from "./components"
import SplitPaneMode from "./components/split-pane-mode"
export default function SplitPaneModePlugin() {
return {
// statePlugins: {
@@ -9,6 +8,8 @@ export default function SplitPaneModePlugin() {
// }
// },
components,
components: {
SplitPaneMode
}
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ import auth from "core/plugins/auth"
import util from "core/plugins/util"
import SplitPaneModePlugin from "core/plugins/split-pane-mode"
import downloadUrlPlugin from "core/plugins/download-url"
import configsPlugin from "plugins/configs"
import configsPlugin from "core/plugins/configs"
import deepLinkingPlugin from "core/plugins/deep-linking"
import OperationContainer from "core/containers/OperationContainer"
+8
View File
@@ -68,6 +68,14 @@ export default class Store {
if(rebuild) {
this.buildSystem()
}
if(Array.isArray(plugins)) {
plugins.forEach(plugin => {
if(plugin.afterLoad) {
plugin.afterLoad(this.getSystem())
}
})
}
}
buildSystem(buildReducer=true) {
+6 -16
View File
@@ -1,17 +1,7 @@
import { pascalCaseFilename } from "js/utils"
import Configs from "./configs"
import Topbar from "./topbar"
const request = require.context(".", true, /\.jsx?$/)
request.keys().forEach( function( key ){
if( key === "./index.js" ) {
return
}
// if( key.slice(2).indexOf("/") > -1) {
// // skip files in subdirs
// return
// }
let mod = request(key)
module.exports[pascalCaseFilename(key)] = mod.default ? mod.default : mod
})
export default {
Configs,
Topbar
}
+1 -1
View File
@@ -1,6 +1,6 @@
import StandaloneLayout from "./layout"
import TopbarPlugin from "plugins/topbar"
import ConfigsPlugin from "plugins/configs"
import ConfigsPlugin from "corePlugins/configs"
// the Standalone preset
+27
View File
@@ -683,4 +683,31 @@ describe("bound system", function(){
})
})
describe("afterLoad", function() {
it("should call an plugin's `afterLoad` method after the plugin is loaded", function() {
// Given
const system = new System({
plugins: [
{
afterLoad(system) {
system.wow = system.dogeSelectors.wow
},
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
return "so selective"
}
}
}
}
}
]
})
// When
var res = system.getSystem().wow()
expect(res).toEqual("so selective")
})
})
})