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")
})
})
})
})
})