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

requestBody sample Try-out should use content-type to generate matching example if switched. #6476

Closed
mathis-m opened this issue Oct 6, 2020 · 1 comment · Fixed by #6518

Comments

@mathis-m
Copy link
Contributor

mathis-m commented Oct 6, 2020

Q&A (please complete the following information)

OS: [e.g. macOS] Windows 10 Pro
Browser: [e.g. chrome, safari] chrome
Version: [e.g. 22] Version 85.0.4183.102 (Official Build) (64-bit)
Method of installation: [e.g. npm, dist assets] raw code
Swagger-UI version: [e.g. 3.10.0] master
Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0] 3.0.1

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.1
info:
 title: Example Swagger
 version: '1.0'
servers:
 - url: /api/v1
paths:
 /xmlTest:
   post:
     summary: sample issues
     operationId: registerSubscription
     parameters: []
     requestBody:
       description: Simple Test
       content:
           application/xml:
             schema:
               $ref: "#/components/schemas/Test"
           application/json:
             schema:
               $ref: "#/components/schemas/Test"
     responses:
       '200':
         description: Simple example
         content:
           application/xml:
             schema:
               $ref: "#/components/schemas/Test"
           application/json:
             schema:
               $ref: "#/components/schemas/Test"
components:
 schemas:
   Test:
     type: object
     xml:
       name: root
     properties:
       x:
         type: string
       other:
         type: string
         format: email
     example: 
       x: what the f

Describe the bug you're encountering

Go into requestBody try out mode. Switch the content-type.
Example will not be updated to respect content-type.

To reproduce...

Open yaml at editor and try out and switch content-type.

Expected behavior

Should use current example-value to generate new example for content-type, when new content-type is selected.

@mathis-m mathis-m changed the title requestBody Try-out should use content-type requestBody sample Try-out should use content-type to generate matching example if switched. Oct 6, 2020
@tim-lai
Copy link
Contributor

tim-lai commented Oct 6, 2020

related to #6250 and #6201, likely same root cause. specifically, neeed to re-resolve the operation subtree if content-type is changed.

tim-lai added a commit that referenced this issue Oct 14, 2020
* When the media-type is changed, there is a new `onChangeMediaType` method to handle actions.
* If target schema properties key/value pairs does NOT equals current schema properties, clear the requestBodyValue, try-it-out request/response and validation params.
* If target schema properties key/value pairs DOES equals current schema properties, do not change or re-render schema properties
* oas3Selector `validateShallowRequired` now also validates required keys against target media-type

Fixes #6201, #6250, #6476
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 a pull request may close this issue.

2 participants