refactor(oas31): concentrate OpenAPI 3.1.0 code to separate plugin (#8475)

Refs #8474
This commit is contained in:
Vladimír Gorej
2023-03-16 12:05:19 +01:00
committed by GitHub
parent ceccb218d3
commit 8b274414ab
35 changed files with 929 additions and 699 deletions

View File

@@ -1,4 +1,5 @@
swagger: 2.0.0
swagger: "2.0"
info:
title: OpenAPI 2.0 Info Object
version: 1.0.0

View File

@@ -1,4 +1,4 @@
swagger: 2.0.0
swagger: "2.0"
info:
title: OpenAPI 2.0 License with only url present
version: 1.0.0

View File

@@ -5,5 +5,4 @@ info:
description: This is a sample server for a pet store.
license:
name: Apache 2.0
# url: https://www.apache.org/licenses/LICENSE-2.0.html
identifier: Apache-2.0 # mutually exclusive of url; separately, for json_schema, consider const, prefix, array items can be of a different type (current assumption is all array items are the same)
identifier: Apache-2.0

View File

@@ -1,11 +1,13 @@
describe("Render Info Component", () => {
describe("OpenAPI 2.x", () => {
describe("OpenAPI 2.0", () => {
const baseUrl = "/?url=/documents/features/info-openAPI2.yaml"
it("should render Info Description", () => {
cy.visit(baseUrl)
.get(".info .description")
.should("contains.text", "This is a sample")
})
it("should render Info Main anchor target xss link with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info .main > a")
@@ -16,19 +18,23 @@ describe("Render Info Component", () => {
.should("have.attr", "target")
.and("equal", "_blank")
})
it("should not render Info Summary (an OpenAPI 3.1 field)", () => {
cy.visit(baseUrl)
.get(".info__summary")
.should("not.exist")
})
})
describe("OpenAPI 3.0.x", () => {
const baseUrl = "/?url=/documents/features/info-openAPI30.yaml"
it("should render Info Description", () => {
cy.visit(baseUrl)
.get(".info .description")
.should("contains.text", "This is a sample")
})
it("should render Info Main anchor target xss link with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info .main > a")
@@ -39,19 +45,23 @@ describe("Render Info Component", () => {
.should("have.attr", "target")
.and("equal", "_blank")
})
it("should not render Info Summary (an OpenAPI 3.1 field)", () => {
cy.visit(baseUrl)
.get(".info__summary")
.should("not.exist")
})
})
describe("OpenAPI 3.1.x", () => {
const baseUrl = "/?url=/documents/features/info-openAPI31.yaml"
it("should render Info Description", () => {
cy.visit(baseUrl)
.get(".info .description")
.should("contains.text", "This is a sample")
})
it("should render Info Main anchor target xss link with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info .main > a")

View File

@@ -1,18 +1,20 @@
/**
* @prettier
*/
describe("Render License Component", () => {
describe("OpenAPI 2", () =>{
describe("OpenAPI 2.0", () => {
const baseUrl = "/?url=/documents/features/license-openAPI2.yaml"
it("should render License URL", () => {
cy.visit(baseUrl)
.get(".info__license")
.should("exist")
.should("contains.text", "Apache 2.0")
.should("not.contains.text", "SPDX License")
.get(".info__license__identifier")
.should("not.exist")
})
it("should render License URL anchor target xss link with safe `rel` attributes ", () => {
it("should render License URL anchor target xss link with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info__license > .link")
.get(".info__license__url > .link")
.should("have.attr", "rel")
.and("include", "noopener")
.and("include", "noreferrer")
@@ -21,18 +23,18 @@ describe("Render License Component", () => {
.and("equal", "_blank")
})
})
describe("OpenAPI 3.0.x", () => {
const baseUrl = "/?url=/documents/features/license-openAPI30.yaml"
it("should render License URL", () => {
cy.visit(baseUrl)
.get(".info__license__url")
.should("exist")
.should("contains.text", "Apache 2.0")
.should("not.contains.text", "SPDX License")
.get(".info__license__identifier")
.should("not.exist")
})
it("should render URL anchor target xss link with safe `rel` attributes ", () => {
})
it("should render URL anchor target xss link with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info__license__url > a")
.should("have.attr", "rel")
@@ -43,19 +45,22 @@ describe("Render License Component", () => {
.and("equal", "_blank")
})
})
describe("OpenAPI 3.1.x", () => {
describe("only URL", () => {
describe("OpenAPI 3.1.x", () => {
describe("given URL field", () => {
const baseUrl = "/?url=/documents/features/license-openAPI31-url.yaml"
it("should render URL", () => {
cy.visit(baseUrl)
.get(".info__license__url")
.should("exist")
.should("contains.text", "Apache 2.0")
.should("not.contains.text", "SPDX License")
.get(".info__license__identifier")
.should("not.exist")
})
it("should render URL anchor target xss link with safe `rel` attributes ", () => {
.get(".info__license__url > a")
.should("have.attr", "href")
.and("equal", "https://www.apache.org/licenses/LICENSE-2.0.html")
})
it("should render URL anchor target xss link with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info__license__url > a")
.should("have.attr", "rel")
@@ -66,40 +71,43 @@ describe("Render License Component", () => {
.and("equal", "_blank")
})
})
describe("only SPDX Identifier", () => {
const baseUrl = "/?url=/documents/features/license-openAPI31-identifier.yaml"
it("should render SPDX Identifier", () => {
describe("given identifier field", () => {
const baseUrl =
"/?url=/documents/features/license-openAPI31-identifier.yaml"
it("should render URL using identifier", () => {
cy.visit(baseUrl)
.get(".info__license__identifier")
.should("exist")
.should("contains.text", "Apache-2.0")
.should("contains.text", "SPDX License")
.get(".info__license__url")
.should("not.exist")
})
it("should render SPDX and Identifier anchor target xss links with safe `rel` attributes ", () => {
.should("exist")
.should("contains.text", "Apache 2.0")
.get(".info__license__url > a")
.should("have.attr", "href")
.and("equal", "https://spdx.org/licenses/Apache-2.0.html")
})
it("should render URL anchor target xss links with safe `rel` attributes", () => {
cy.visit(baseUrl)
.get(".info__license__identifier > a")
.each(($el) => {
cy.get($el)
.should("have.attr", "rel")
.and("include", "noopener")
.and("include", "noreferrer")
cy.get($el)
.should("have.attr", "target")
.and("equal", "_blank")
})
.get(".info__license__url > a")
.should("have.attr", "rel")
.and("include", "noopener")
.and("include", "noreferrer")
.get(".info .main > a")
.should("have.attr", "target")
.and("equal", "_blank")
})
})
describe("URL and SPX are mutually exclusive", () => {
it("should render nothing if both URL & SPDX exists", () => {
const baseUrl = "/?url=/documents/features/license-openAPI31-error-both-identifier-and-url.yaml"
const baseUrl =
"/?url=/documents/features/license-openAPI31-error-both-identifier-and-url.yaml"
cy.visit(baseUrl)
.get(".info__license__identifier")
.should("not.exist")
.get(".info__license__url")
.should("not.exist")
})
})
})
})
})

View File

@@ -1,7 +1,7 @@
import { fromJS } from "immutable"
import { isOAS3, isSwagger2 } from "corePlugins/oas3/helpers"
import { isOAS30, isSwagger2 } from "corePlugins/oas3/helpers"
const isOAS3Shorthand = (version) => isOAS3(fromJS({
const isOAS3Shorthand = (version) => isOAS30(fromJS({
openapi: version
}))
@@ -13,7 +13,7 @@ describe("isOAS3", function () {
it("should recognize valid OAS3 version values", function () {
expect(isOAS3Shorthand("3.0.0")).toEqual(true)
expect(isOAS3Shorthand("3.0.1")).toEqual(true)
expect(isOAS3Shorthand("3.0.11111")).toEqual(true)
expect(isOAS3Shorthand("3.0.11111")).toEqual(false)
expect(isOAS3Shorthand("3.0.0-rc0")).toEqual(true)
})
@@ -31,7 +31,7 @@ describe("isOAS3", function () {
})
it("should gracefully fail when `openapi` field is missing", function () {
expect(isOAS3(fromJS({
expect(isOAS30(fromJS({
openApi: "3.0.0"
}))).toEqual(false)
expect(isOAS3Shorthand(null)).toEqual(false)
@@ -41,7 +41,7 @@ describe("isOAS3", function () {
describe("isSwagger2", function () {
it("should recognize valid Swagger 2.0 version values", function () {
expect(isSwagger2Shorthand("2.0")).toEqual(true)
expect(isSwagger2Shorthand("2.0-rc0")).toEqual(true)
expect(isSwagger2Shorthand("2.0-rc0")).toEqual(false)
})
it("should fail for invalid Swagger 2.0 version values", function () {

View File

@@ -26,7 +26,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -55,7 +56,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -88,7 +90,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -124,7 +127,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -167,7 +171,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -207,7 +212,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -261,7 +267,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -314,7 +321,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}
@@ -342,7 +350,8 @@ describe("OAS3 plugin - state", function() {
specSelectors: {
specJson: () => {
return fromJS({ openapi: "3.0.0" })
}
},
isOAS3: () => true,
}
}
}

View File

@@ -17,6 +17,7 @@ describe("oas3 plugin - auth extensions - wrapSelectors", function(){
specJson: () => fromJS({
openapi: "3.0.0"
}),
isOAS3: () => true,
securityDefinitions: () => {
return fromJS({
"oauth2AuthorizationCode": {

View File

@@ -1,8 +1,5 @@
import { fromJS } from "immutable"
import {
definitions
} from "corePlugins/oas3/spec-extensions/wrap-selectors"
import { definitions } from "corePlugins/oas3/spec-extensions/wrap-selectors"
describe("oas3 plugin - spec extensions - wrapSelectors", function(){
@@ -28,6 +25,7 @@ describe("oas3 plugin - spec extensions - wrapSelectors", function(){
getSystem: () => system,
specSelectors: {
specJson: () => spec,
isOAS3: () => true,
}
}
@@ -57,6 +55,7 @@ describe("oas3 plugin - spec extensions - wrapSelectors", function(){
getSystem: () => system,
specSelectors: {
specJson: () => spec,
isOAS3: () => true,
}
}
@@ -82,7 +81,8 @@ describe("oas3 plugin - spec extensions - wrapSelectors", function(){
getSystem: () => system,
specSelectors: {
specJson: () => spec,
}
isOAS3: () => true,
},
}
// When

View File

@@ -1,7 +1,9 @@
import React from "react"
import { render } from "enzyme"
import { fromJS } from "immutable"
import Info, { InfoUrl, License } from "components/info"
import Info, { InfoUrl } from "components/info"
import Contact from "components/contact"
import License from "components/license"
import { Link } from "components/layout-utils"
import Markdown from "components/providers/markdown"
@@ -11,7 +13,8 @@ describe("<Info/> Anchor Target Safety", function(){
Markdown,
InfoUrl,
License,
Link
Contact,
Link,
}
const baseProps = {
getComponent: c => components[c] || dummyComponent,