feat(oas3): Show file upload for schema binary format (#7325)
* fix(ux): display actual content type instead of hard-coded application/octet-stream * feat(ux): show file upload when schema has "format: binary", fixes #5636 * feat(ux): show file upload when schema has "format: base64" According to https://github.com/swagger-api/swagger-ui/pull/7325#issuecomment-861684260 the uploaded file should be converted to base64 automatically. * feat(ux): add cypress tests for displaying an upload button
This commit is contained in:
114
test/e2e-cypress/tests/features/request-body-upload-file.js
Normal file
114
test/e2e-cypress/tests/features/request-body-upload-file.js
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
describe("OpenAPI 3.0 Request Body upload file button", () => {
|
||||
describe("application/octet-stream", () => {
|
||||
it("should display description with the correct content type", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadApplicationOctetStream")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper i")
|
||||
.should("have.text", "Example values are not available for application/octet-stream media types.")
|
||||
})
|
||||
it("should display a file upload button", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadApplicationOctetStream")
|
||||
.click()
|
||||
.get(".try-out__btn")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper input")
|
||||
.should("have.prop", "type", "file")
|
||||
})
|
||||
})
|
||||
describe("image/png", () => {
|
||||
it("should display description with the correct content type", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadImagePng")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper i")
|
||||
.should("have.text", "Example values are not available for image/png media types.")
|
||||
})
|
||||
it("should display a file upload button", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadApplicationOctetStream")
|
||||
.click()
|
||||
.get(".try-out__btn")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper input")
|
||||
.should("have.prop", "type", "file")
|
||||
})
|
||||
})
|
||||
describe("audio/wav", () => {
|
||||
it("should display description with the correct content type", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadAudioWav")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper i")
|
||||
.should("have.text", "Example values are not available for audio/wav media types.")
|
||||
})
|
||||
it("should display a file upload button", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadApplicationOctetStream")
|
||||
.click()
|
||||
.get(".try-out__btn")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper input")
|
||||
.should("have.prop", "type", "file")
|
||||
})
|
||||
})
|
||||
describe("video/mpeg", () => {
|
||||
it("should display description with the correct content type", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadVideoMpeg")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper i")
|
||||
.should("have.text", "Example values are not available for video/mpeg media types.")
|
||||
})
|
||||
it("should display a file upload button", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadApplicationOctetStream")
|
||||
.click()
|
||||
.get(".try-out__btn")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper input")
|
||||
.should("have.prop", "type", "file")
|
||||
})
|
||||
})
|
||||
describe("schema format binary", () => {
|
||||
it("should display description with the correct content type", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadSchemaFormatBinary")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper i")
|
||||
.should("have.text", "Example values are not available for application/x-custom media types.")
|
||||
})
|
||||
it("should display a file upload button", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadSchemaFormatBinary")
|
||||
.click()
|
||||
.get(".try-out__btn")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper input")
|
||||
.should("have.prop", "type", "file")
|
||||
})
|
||||
})
|
||||
describe("schema format base64", () => {
|
||||
it("should display description with the correct content type", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadSchemaFormatBase64")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper i")
|
||||
.should("have.text", "Example values are not available for application/x-custom media types.")
|
||||
})
|
||||
it("should display a file upload button", () => {
|
||||
cy.visit("/?url=/documents/features/request-body-upload-file.yaml")
|
||||
.get("#operations-default-uploadSchemaFormatBinary")
|
||||
.click()
|
||||
.get(".try-out__btn")
|
||||
.click()
|
||||
.get(".opblock-section-request-body .opblock-description-wrapper input")
|
||||
.should("have.prop", "type", "file")
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user