-
Notifications
You must be signed in to change notification settings - Fork 9.3k
feat(oas31): add support for file upload #10335
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * @prettier | ||
| */ | ||
|
|
||
| export const getIsFileFormat = (schema) => { | ||
| if (!schema) return false | ||
|
|
||
| const isStringType = schema.get("type") === "string" | ||
| const format = schema.get("format") | ||
| const isBinaryFormat = format === "binary" | ||
| const isBase64Format = format === "base64" || format === "byte" | ||
|
|
||
| return isStringType && (isBinaryFormat || isBase64Format) | ||
| } | ||
|
|
||
| export const getIsFileContentType = (contentType) => | ||
| contentType === "application/octet-stream" || | ||
| contentType?.indexOf("image/") === 0 || | ||
| contentType?.indexOf("audio/") === 0 || | ||
| contentType?.indexOf("video/") === 0 | ||
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,23 @@ | ||
| /** | ||
| * @prettier | ||
| */ | ||
| import { immutableToJS } from "core/utils" | ||
|
|
||
| export const makeGetIsFileFormat = (fn) => { | ||
| const getIsFileFormat = (schema) => { | ||
| if (!schema) return null | ||
|
|
||
| const type = fn.jsonSchema202012.getType(immutableToJS(schema)) | ||
| const isFileContentMediaType = fn.getIsFileContentType( | ||
| schema.get("contentMediaType") | ||
| ) | ||
| const isBase64Encoding = schema.get("contentEncoding") === "base64" | ||
|
|
||
| return ( | ||
| (type === "string" || type === "any") && | ||
|
char0n marked this conversation as resolved.
|
||
| (isFileContentMediaType || isBase64Encoding) | ||
| ) | ||
| } | ||
|
|
||
| return getIsFileFormat | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
test/e2e-cypress/e2e/features/plugins/oas31/oas31-file-upload.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,65 @@ | ||
| /** | ||
| * @prettier | ||
| */ | ||
|
|
||
| describe("OpenAPI 3.1.0 file upload", () => { | ||
| beforeEach(() => { | ||
| cy.visit("/?url=/documents/features/oas31-file-upload.yaml") | ||
| }) | ||
|
|
||
| it("should render file input when contentMediaType of request body schema is application/octet-stream", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/requestBody-contentMediaType") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".opblock-description-wrapper input[type=file]").should("exist") | ||
| }) | ||
|
|
||
| it("should render file input when contentEncoding of request body schema is base64", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/requestBody-contentEncoding") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".opblock-description-wrapper input[type=file]").should("exist") | ||
| }) | ||
|
|
||
| it("should render file input when Media Type Object for file upload is empty", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/requestBody-noSchema") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".opblock-description-wrapper input[type=file]").should("exist") | ||
| }) | ||
|
|
||
| it("should render file input when contentMediaType of a parameter schema is application/octet-stream", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/parameter-contentMediaType") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".parameters-col_description input[type=file]").should("exist") | ||
| }) | ||
|
|
||
| it("should render file input when contentEncoding of a parameter schema is base64", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/parameter-contentEncoding") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".parameters-col_description input[type=file]").should("exist") | ||
| }) | ||
|
|
||
| it("should render file input when contentMediaType of a multipart/form-data object property is application/octet-stream", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/property-contentMediaType") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".opblock-description-wrapper input[type=file]").should("exist") | ||
| }) | ||
|
|
||
| it("should render file input when contentEncoding of a multipart/form-data object property is base64", () => { | ||
| cy.get(".opblock-summary-path span") | ||
| .contains("/property-contentEncoding") | ||
| .click() | ||
| cy.contains("Try it out").click() | ||
| cy.get(".opblock-description-wrapper input[type=file]").should("exist") | ||
| }) | ||
| }) |
59 changes: 59 additions & 0 deletions
59
test/e2e-cypress/static/documents/features/oas31-file-upload.yaml
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,59 @@ | ||
| openapi: 3.1.0 | ||
| paths: | ||
| /requestBody-contentMediaType: | ||
| post: | ||
| requestBody: | ||
| content: | ||
| application/unknown: | ||
| schema: | ||
| contentMediaType: application/octet-stream | ||
| /requestBody-contentEncoding: | ||
| post: | ||
| requestBody: | ||
| content: | ||
| application/unknown: | ||
| schema: | ||
| contentEncoding: base64 | ||
| /requestBody-noSchema: | ||
| post: | ||
| requestBody: | ||
| content: | ||
| application/octet-stream: {} | ||
| /parameter-contentMediaType: | ||
| post: | ||
| parameters: | ||
| - in: query | ||
| name: file | ||
| schema: | ||
| type: string | ||
| contentMediaType: application/octet-stream | ||
| /parameter-contentEncoding: | ||
| post: | ||
| parameters: | ||
| - in: query | ||
| name: file | ||
| schema: | ||
| type: string | ||
| contentEncoding: base64 | ||
| /property-contentMediaType: | ||
| post: | ||
| requestBody: | ||
| content: | ||
| multipart/form-data: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| file: | ||
| type: string | ||
| contentMediaType: application/octet-stream | ||
| /property-contentEncoding: | ||
| post: | ||
| requestBody: | ||
| content: | ||
| multipart/form-data: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| file: | ||
| type: string | ||
| contentEncoding: base64 |
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.