Skip to content

Conversation

@tim-lai
Copy link
Contributor

@tim-lai tim-lai commented Jul 10, 2020

fixes #5181

Description

Changed how UI receives x-www-form-urlencoded form data. Specifically, set requestBodyValue values to be an immutable Map, as "value". Previously stored as a normal String.

This change enables the ability to add "errors" to a Map that can be used by validation.
This change also matches the existing behavior of OAS2, and OAS3 Parameters

For application/json and application/xml, the "errors" field is added directly to the bodyValue Map

Example: 
Old: ...pathMethod,..., bodyValue Map { "id": 10, "name": "doggie" }
New: ...pathMethod,..., bodyValue Map { id: Map { value: 10, errors: List[] }, name: Map { value: "doggie", errors: List[] } }

For all other Request Bodies, e.g. Markdown, 
Old: ...pathMethod,..., bodyValue Map { value: ""}
New: ...pathMethod,..., bodyValue Map { value: "", errors: List[] }
  • Dev note: getOAS3RequiredRequestBodyContentType requires state.spec, which is not available to state.oas3

Motivation and Context

Fixes #5181

For OAS3 Request Body, if required fields are empty, user should not be able to "Execute" and get a response. In addition, the missing required fields should be highlighted in Red.

How Has This Been Tested?

new cypress and mocha tests

Screenshots (if appropriate):

application/x-www-form-urlencoded
oas3-required-validation-urlencoded

application/json (application/xml is similar)
oas3-required-validation-json

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@tim-lai tim-lai marked this pull request as draft July 10, 2020 23:29
@tim-lai tim-lai requested a review from char0n July 10, 2020 23:30
@tim-lai tim-lai self-assigned this Jul 10, 2020
@tim-lai tim-lai added this to the M5 milestone Jul 10, 2020
@tim-lai tim-lai force-pushed the feat/oas3-request-body-required-validation branch from ea767df to caa2212 Compare July 15, 2020 23:10
@tim-lai tim-lai marked this pull request as ready for review July 15, 2020 23:21
@tim-lai
Copy link
Contributor Author

tim-lai commented Jul 17, 2020

please build

tim-lai added 4 commits July 16, 2020 17:44
fixes swagger-api#5181

* application/json
* application/xml
* application/x-www-form-urlencoded

* Set requestBodyValue values to be an immutable Map, as "value". Previously stored as a normal String.
* This enables adding "errors" to the Map, for validation use

* note: getOAS3RequiredRequestBodyContentType requires state.spec,
* which is not available to state.oas3
* requestBody
* requestBody - fields for application/json
* requestBody - fields for application/x-www-form-urlencoded
* switching between content types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required parameter in requestBody doesn't block request from executing.

1 participant