-
Notifications
You must be signed in to change notification settings - Fork 9.1k
fix: align OpenAPI 3.x.y file uploads with specification #10409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
23379f6
fix: align OpenAPI 3.x.y file uploads with specification
glowcloud 64d09d4
test: add tests for empty Media Type Object
glowcloud 0579584
feat: add config option for file upload media types
glowcloud 790d34b
refactor: get configs internally and transform schema to object
glowcloud 0f0c5cd
test: fix function usage in unit tests
glowcloud 9782dd0
feat: add function for checking if schema has certain types
glowcloud 0c10671
test: add missing functions for unit tests
glowcloud aa33415
feat: support single type comparison
glowcloud defc034
Merge branch 'master' into file-upload-spec-alignment
glowcloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
|
||
export const isFileUploadIntended = (schema, mediaType = null) => { | ||
if ( | ||
typeof mediaType === "string" && | ||
(mediaType.startsWith("application/octet-stream") || | ||
mediaType.startsWith("image/") || | ||
mediaType.startsWith("audio/") || | ||
mediaType.startsWith("video/")) | ||
) { | ||
return true | ||
} | ||
|
||
if (!schema) return false | ||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const type = schema.get("type") | ||
const format = schema.get("format") | ||
|
||
return type === "string" && (format === "binary" || format === "byte") | ||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import { immutableToJS } from "core/utils" | ||
|
||
export const isFileUploadIntended = (schema, mediaType = null) => { | ||
if ( | ||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
typeof mediaType === "string" && | ||
(mediaType.startsWith("application/octet-stream") || | ||
mediaType.startsWith("image/") || | ||
mediaType.startsWith("audio/") || | ||
mediaType.startsWith("video/")) | ||
) { | ||
return true | ||
} | ||
|
||
if (!schema) return null | ||
|
||
const type = immutableToJS(schema.get("type")) | ||
const isTypeString = | ||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type === "string" || (Array.isArray(type) && type.includes("string")) | ||
const format = schema.get("format") | ||
|
||
return isTypeString && (format === "binary" || format === "byte") | ||
} |
189 changes: 189 additions & 0 deletions
189
test/e2e-cypress/e2e/features/plugins/oas3/request-body-upload-file.cy.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
|
||
describe("OpenAPI 3.0 Request Body upload file button", () => { | ||
beforeEach(() => { | ||
cy.visit("/?url=/documents/features/oas3-request-body-upload-file.yaml") | ||
}) | ||
|
||
describe("application/octet-stream", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadApplicationOctetStream").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("image/png", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadImagePng").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("audio/wav", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadAudioWav").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("video/mpeg", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadVideoMpeg").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("application/octet-stream with empty Media Type Object", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadApplicationOctetStreamEmpty").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("schema type string and format binary", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadSchemaFormatBinary").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("schema type string and format byte", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadSchemaFormatByte").click() | ||
}) | ||
|
||
it("should display description with the correct content type", () => { | ||
cy.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.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("multipart/form-data object property with schema type string and format binary", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadPropertySchemaFormatBinary").click() | ||
}) | ||
|
||
it("should display a file upload button", () => { | ||
cy.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
|
||
describe("multipart/form-data object property with schema type string and format byte", () => { | ||
beforeEach(() => { | ||
cy.get("#operations-default-uploadPropertySchemaFormatByte").click() | ||
}) | ||
|
||
it("should display a file upload button", () => { | ||
cy.get(".try-out__btn").click() | ||
cy.get( | ||
".opblock-section-request-body .opblock-description-wrapper input" | ||
).should("have.prop", "type", "file") | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.