Skip to content
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

Add -AllowNonStandardBody Parameter to Enable Request Bodies for Non-Standard HTTP Methods in OpenAPI #1436

Merged
merged 5 commits into from
Oct 28, 2024

Conversation

mdaneri
Copy link
Contributor

@mdaneri mdaneri commented Oct 26, 2024

Description

This pull request introduces a new -AllowNonStandardBody parameter to enable request bodies for HTTP methods that typically do not support them, such as GET and DELETE. By default, Pode adheres to the RFC 7231 standards, which generally reserve request bodies for POST, PUT, and PATCH methods. However, this update provides flexibility for users who require bodies for other HTTP methods, addressing the feature request and limitations outlined in issue #1432.

Changes

  • New Parameter: The -AllowNonStandardBody switch is added to the Set-PodeOARequest function. When specified, this parameter overrides the default behavior, allowing non-standard HTTP methods to include a request body.
  • Enhanced Error Messaging: The exception message has been updated to suggest using -AllowNonStandardBody for methods where request bodies are typically disallowed, improving guidance for users.
  • Localization: The updated error message has been translated into multiple languages, including Arabic, German, Spanish, French, Italian, Japanese, Korean, Dutch, Polish, Portuguese, and Chinese, to support international users.

Example

To define a route that allows a request body for a DELETE operation:

Add-PodeRoute -Method DELETE -Path '/resource' -PassThru | Set-PodeOARequest -RequestBody (New-PodeOARequestBody -Schema 'DeleteRequestSchema') -AllowNonStandardBody

Issue Addressed

Testing

  • Unit tests were added to ensure that the -AllowNonStandardBody parameter enables request bodies for HTTP methods like DELETE.
  • Tests verify that without -AllowNonStandardBody, the function continues to restrict bodies to POST, PUT, and PATCH.

src/Public/OpenApi.ps1 Outdated Show resolved Hide resolved
@Badgerati Badgerati added this to the 2.11.1 milestone Oct 28, 2024
@Badgerati Badgerati changed the title Add -AllowNonStandardBody Parameter to Enable Request Bodies for Non-Standard HTTP Methods (Address #1432) Add -AllowNonStandardBody Parameter to Enable Request Bodies for Non-Standard HTTP Methods in OpenAPI Oct 28, 2024
@Badgerati Badgerati merged commit dc646a8 into Badgerati:develop Oct 28, 2024
14 checks passed
@Badgerati Badgerati mentioned this pull request Nov 2, 2024
@mdaneri mdaneri deleted the issue-1432 branch November 6, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI 3.1 supports Body for DELETE method
2 participants