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

x-examples for request body param does not display #1743

Closed
MarcLevisse opened this issue Sep 8, 2021 · 12 comments · Fixed by #1826
Closed

x-examples for request body param does not display #1743

MarcLevisse opened this issue Sep 8, 2021 · 12 comments · Fixed by #1826
Assignees

Comments

@MarcLevisse
Copy link

MarcLevisse commented Sep 8, 2021

If I use the x-examples vendor extension with ReDoc 2.0.0-rc56 (idem 48) the custom example does not display and generated one from schema is displayed in place

simple_requestbody_example

simple_swagger2_test_with_x-examples.txt

any idea if I'm doing something wrong or if there is a bug somewhere ?

thx a lot

@MarcLevisse
Copy link
Author

MarcLevisse commented Sep 8, 2021

{
    "swagger": "2.0",
    "info": {
        "description": "test",
        "version": "v4",
        "title": "test",
        "license": {
            "name": "test"
        }
    },
    "basePath": "/v4",
    "x-stoplight": {
        "docs": {
            "showModels": false
        }
    },
    "paths": {
        "/test": {
            "post": {
                "operationId": "test",
                "summary": "test",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "test",
                        "description": "test",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "key": {
                                    "type": "string"
                                }
                            }
                        },
                        "x-examples": {
                            "application/json": {
                                "key": "customerId"
                            }
                        }
                    }
                ]
            }
        }
    }
}

@RomanHotsiy
Copy link
Member

This is expected behaviour. We do not show request body examples in the middle panel. They are shown in the right panel.

@MarcLevisse
Copy link
Author

MarcLevisse commented Sep 8, 2021

that's indeed my issue, it does not show in the right panel ...

the example displayed is

{
   "key": "string"
}

(generated)
but should have been

{
   "key": "customerId"
}

(custom one from x-examples)

@RomanHotsiy
Copy link
Member

Ah, I apologize, looks like x-examples support was missed during react rewrite 😳 .

We'll fix that.

@RomanHotsiy RomanHotsiy reopened this Sep 8, 2021
@MarcLevisse
Copy link
Author

you're welcome ! ;)

@adamaltman
Copy link
Member

adamaltman commented Oct 6, 2021

https://redoc.ly/docs/api-reference-docs/specification-extensions/x-examples/

It seems the usage is slightly incorrect too. It should be like:

                        "x-examples": {
                                "application/json": {
                                   "your-example-name": {
                                      "value": {
                                          "key": "customerId"
                                       }
                                   }
                               }
                         }

@MarcLevisse
Copy link
Author

indeed

anyway tried with this:

{
    "swagger": "2.0",
    "info": {
        "title": "test",
        "version": "v4",
        "description": "test",
        "license": {
            "name": "test"
        }
    },
    "basePath": "/v4",
    "paths": {
        "/test": {
            "post": {
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "name": "test",
                        "description": "test",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "key": {
                                    "type": "string"
                                }
                            }
                        },
                        "in": "body",
                        "x-examples": {
                            "application/json": {
                                "a-sample": {
                                    "summary": "Some Example",
                                    "value": {
                                        "key": "customerId"
                                    }
                                },
                                "another-sample": {
                                    "summary": "Some Other Example",
                                    "value": {
                                        "key": "anotherKey"
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "201": {
                        "description": "Created"
                    }
                },
                "operationId": "test",
                "summary": "test"
            }
        }
    }
}

and result is the same :

x-examples_with_correct_usage

none of my two samples are displayed and no dropdown to choose between two samples

@MarcLevisse
Copy link
Author

Hi guys ! Is there a chance that this regression bug is being addressed soon ?
(I would be glad not to have to migrate dozens of swagger 2.0 spec files to 3.0)

thx !

@Oprysk Oprysk linked a pull request Dec 9, 2021 that will close this issue
3 tasks
Oprysk added a commit that referenced this issue Dec 9, 2021
* fix: x-examples for request body param does not display #1743

* lint

* fix ts
@MarcLevisse
Copy link
Author

thx for the fix
anyway, can you provide me with a working x-examples Swagger 2.0 sample ?
I've upgraded to 2.0.0-rc59 and I can't face why it still does not work

thx

@RomanHotsiy
Copy link
Member

@MarcLevisse
Copy link
Author

MarcLevisse commented Dec 10, 2021

ok your sample matches mine
but in fact through openapi-cli "preview" command it works
I guess I have an issue with my upgrade to 2.0.0-rc59 in my ReDoc standalone integration

@MarcLevisse
Copy link
Author

perfect, re run yarn install on my docusaurus project and it cleaned unused but still present redoc 2.0.0-rc57
that works ! thx a lot for your kind support !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants