Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* supporting changes for swagger-api/swagger-ui#4614

* add version pragmas to all validation tests
  • Loading branch information
shockey authored Jun 12, 2018
1 parent d517a82 commit 89810dc
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/plugins/editor/components/editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
}
}

.swagger-ui {
// ensure Swagger-UI uses its entire container
height: 100%;

.version-pragma {
// make the version pragma message look nicer in the context
// of the Editor
font-size: 1.2em;
}
}


@import './read-only-watermark.less';

@import './print.less';
17 changes: 16 additions & 1 deletion src/plugins/validate-json-schema/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@ let debouncedValidation = makeValidationWorker()

export const validateSpec = (jsSpec) => ({ specSelectors, errActions }) => {
const isOAS3 = specSelectors.isOAS3 ? specSelectors.isOAS3() : false
const isSwagger2 = specSelectors.isSwagger2 ? specSelectors.isSwagger2() : false
const isAmbiguousVersion = isOAS3 && isSwagger2
const ourMode = isOAS3 ? "oas3" : "swagger2"
debouncedValidation({ mode: ourMode, specSelectors, errActions, jsSpec })
if(!isAmbiguousVersion && (isOAS3 || isSwagger2)) {
debouncedValidation({ mode: ourMode, specSelectors, errActions, jsSpec })
} else {
// stagger clearing errors, in case there is another debounced validation
// run happening, which can occur when the user's typing cadence matches
// the latency of validation
// TODO: instead of using a timeout, be aware of any pending validation
// promises, and use them to schedule error clearing.
setTimeout(() => {
errActions.clear({
source: "schema"
})
}, 50)
}
}

export default function() {
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/validate-semantic/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export const all = () => (system) => {
source: SOURCE
})

// these will be functions or undefined
const { specSelectors: { isSwagger2, isOAS3 } } = system

// don't run validation if we don't recognize this content
if(isSwagger2 && isOAS3 && !isSwagger2() && !isOAS3()) {
return
}

// don't run validation if valid swagger and openapi is used together
if(isSwagger2 && isOAS3 && isSwagger2() && isOAS3()) {
return
}

const errCb = (obj) => bufferedNewSpecErrBatch(system, obj)

forEach(system.validateActions, (fn, name) => {
Expand Down
7 changes: 7 additions & 0 deletions test/plugins/validate-semantic/2and3/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {
describe("Swagger 2", () => {
it("should not return problems for a valid path-level definiton/declaration pair", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [{
Expand All @@ -257,6 +258,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {

it("should not return problems for a valid path-level definiton/declaration pair using a $ref", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [
Expand All @@ -279,6 +281,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {

it("should not return problems for a valid operation-level definiton/declaration pair", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
get: {
Expand All @@ -298,6 +301,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {

it("should return one problem for a path parameter defined at the operation level that is not present within every operation on the path", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
get: {
Expand Down Expand Up @@ -330,6 +334,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {

it("should return one problem when the definition is completely absent", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: []
Expand All @@ -350,6 +355,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {

it("should return one error when no parameters are defined", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {}
}
Expand All @@ -368,6 +374,7 @@ describe("validation plugin - semantic - 2and3 paths", () => {

it("should return one problem for a missed 'in' value", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [{
Expand Down
2 changes: 2 additions & 0 deletions test/plugins/validate-semantic/2and3/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ describe("validation plugin - semantic - 2and3 refs", function() {

it("should return a warning when a definition is declared but not used in Swagger 2", () => {
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {}
},
Expand All @@ -203,6 +204,7 @@ describe("validation plugin - semantic - 2and3 refs", function() {

it("should not return a warning when a definition with special character is declared and used in Swagger 2", () => {
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
get: {
Expand Down
7 changes: 7 additions & 0 deletions test/plugins/validate-semantic/form-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("validation plugin - semantic - form data", function(){
it("should warn about formdata ( typo )", function(){

const spec = {
swagger: "2.0",
parameters: {
CoolParam: [
{ in: "formdata" },
Expand Down Expand Up @@ -41,6 +42,7 @@ describe("validation plugin - semantic - form data", function(){
describe("missing consumes", function(){
it("should complain if 'type:file` and no 'in: formData", function(){
const spec = {
swagger: "2.0",
paths: {
"/some": {
post: {
Expand All @@ -65,6 +67,7 @@ describe("validation plugin - semantic - form data", function(){
})
it("should complain if 'type:file` and no consumes - 'multipart/form-data'", function(){
const spec = {
swagger: "2.0",
paths: {
"/some": {
post: {
Expand All @@ -90,6 +93,7 @@ describe("validation plugin - semantic - form data", function(){
})
it("should complain if 'in:formData` and no consumes - 'multipart/form-data' or 'application/x-www-form-urlencoded'", function(){
const spec = {
swagger: "2.0",
paths: {
"/some": {
post: {
Expand All @@ -115,6 +119,7 @@ describe("validation plugin - semantic - form data", function(){

it("should not complain if 'in:formData` and consumes is set globally", function(){
const spec = {
swagger: "2.0",
consumes: [
"multipart/form-data"
],
Expand All @@ -139,6 +144,7 @@ describe("validation plugin - semantic - form data", function(){
describe("/pathitems/...", function(){
it("should complain about having both in the same parameter", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
consumes: ["multipart/form-data"],
Expand All @@ -161,6 +167,7 @@ describe("validation plugin - semantic - form data", function(){
})
it("should complain if 'type:file` and no 'in: formData", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
consumes: ["multipart/form-data"],
Expand Down
2 changes: 2 additions & 0 deletions test/plugins/validate-semantic/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("validation plugin - semantic - operations", () => {
describe("Operations must have unique operationIds", () => {
it("should return an error when operationId collisions exist", () => {
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand All @@ -33,6 +34,7 @@ describe("validation plugin - semantic - operations", () => {
})
it("should not return an error when operationId collisions don't exist", () => {
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand Down
6 changes: 6 additions & 0 deletions test/plugins/validate-semantic/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe("validation plugin - semantic - parameters", function() {

it("should return an error when an array type parameter omits an `items` property", () => {
const spec = {
swagger: "2.0",
"paths": {
"/pets": {
"get": {
Expand Down Expand Up @@ -35,6 +36,7 @@ describe("validation plugin - semantic - parameters", function() {
describe("Operations cannot have both a 'body' parameter and a 'formData' parameter", () => {
it("should complain about having both in the same operation", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand All @@ -59,6 +61,7 @@ describe("validation plugin - semantic - parameters", function() {
})
it("should not complain about having only a body parameter in the same operation", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand All @@ -75,6 +78,7 @@ describe("validation plugin - semantic - parameters", function() {
})
it("should not complain about having only a formData parameter in the same operation", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand All @@ -94,6 +98,7 @@ describe("validation plugin - semantic - parameters", function() {
describe("Operations must have only one body parameter", () => {
it("should complain about having two body parameters in the same operation", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand All @@ -118,6 +123,7 @@ describe("validation plugin - semantic - parameters", function() {
})
it("should not complain about having one body parameter in the same operation", function(){
const spec = {
swagger: "2.0",
paths: {
"/": {
get: {
Expand Down
10 changes: 10 additions & 0 deletions test/plugins/validate-semantic/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return one problem for an empty path template", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{}": {}
}
Expand All @@ -30,6 +31,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return one problem for an undefined declared path parameter", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {}
}
Expand All @@ -47,6 +49,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return one problem for an path parameter defined in another path", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {},
"/UncoolPath/{id}": {
Expand All @@ -71,6 +74,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return no problems for a path parameter defined in the path", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [{
Expand All @@ -87,6 +91,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return no problems for a path parameter defined in an operation", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
get: {
Expand All @@ -109,6 +114,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return one problem for an equivalent templated path strings", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [{
Expand Down Expand Up @@ -139,6 +145,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return no problems for a templated and untemplated pair of path strings", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/": {},
"/CoolPath/{count}": {
Expand All @@ -156,6 +163,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return no problems for a templated and double-templated set of path strings", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{group_id1}/all": {
parameters: [{
Expand Down Expand Up @@ -189,6 +197,7 @@ describe("validation plugin - semantic - paths", function(){
describe("Paths must have unique name + in parameters", () => {
it("should return no problems for a name collision only", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [
Expand All @@ -211,6 +220,7 @@ describe("validation plugin - semantic - paths", function(){

it("should return no problems when 'in' is not defined", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath/{id}": {
parameters: [
Expand Down
8 changes: 8 additions & 0 deletions test/plugins/validate-semantic/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("validation plugin - semantic - refs", function() {
describe("Response $refs", () => {
it("should return a problem for a parameters $ref in a response position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
responses: {
Expand All @@ -34,6 +35,7 @@ describe("validation plugin - semantic - refs", function() {
// PS: We have a flag in mapSpec, that adds $$refs known as metaPatches
it("should return a problem for a definitions $ref in a response position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
schema: {
Expand All @@ -55,6 +57,7 @@ describe("validation plugin - semantic - refs", function() {

it("should not return a problem for a responses $ref in a response position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
responses: {
Expand Down Expand Up @@ -107,6 +110,7 @@ describe("validation plugin - semantic - refs", function() {

it("should not return a problem for a definition $ref in a schema position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
schema: {
Expand All @@ -126,6 +130,7 @@ describe("validation plugin - semantic - refs", function() {
it("should not return a problem for a schema property named 'properties'", function(){
// #492 regression
const spec = {
"swagger": "2.0",
"definitions": {
"ServicePlan": {
"description": "New Plan to be added to a service.",
Expand Down Expand Up @@ -157,6 +162,7 @@ describe("validation plugin - semantic - refs", function() {

it("should return a problem for a definition $ref in a parameter position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
parameters: [{
Expand All @@ -178,6 +184,7 @@ describe("validation plugin - semantic - refs", function() {

it("should return a problem for a responses $ref in a parameter position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
parameters: [{
Expand All @@ -199,6 +206,7 @@ describe("validation plugin - semantic - refs", function() {

it("should not return a problem for a parameter $ref in a parameter position", function(){
const spec = {
swagger: "2.0",
paths: {
"/CoolPath": {
parameters: [{
Expand Down
Loading

0 comments on commit 89810dc

Please sign in to comment.