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

Example request string is not populated #3233

Open
ekazakas opened this issue Jun 13, 2017 · 15 comments · May be fixed by #10371
Open

Example request string is not populated #3233

ekazakas opened this issue Jun 13, 2017 · 15 comments · May be fixed by #10371

Comments

@ekazakas
Copy link

ekazakas commented Jun 13, 2017

Trying to migrate from swagger-ui 2x to 3.0.12. It seems that swagger-ui 3.x is not able to render x-examples data.

"/data/targets" : {
"post" : {
"tags" : [ "dummy" ],
"summary" : "Returns validation results of given list of targets.",
"description" : "",
"operationId" : "dataTargets",
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "body",
"name" : "body",
"description" : "Targets list in JSON format.",
"required" : true,
"schema" : {
"type" : "string"
},
"x-examples" : {
"default" : "{\"targets\": \"[1, 2, 3, 4]\"}"
}
}
<...>
}

In version 2.x swagger-ui was able to use the value from x-examples as example request. As a quick and dirty hack, I have made some changes in src/core/components/param-body.jsx

updateValues = (props) => {
let { specSelectors, pathMethod, param, isExecute, consumesValue="" } = props
let parameter = specSelectors ? specSelectors.getParameter(pathMethod, param.get("name")) : {}
let isXml = /xml/i.test(consumesValue);
let paramValue = isXml ? parameter.get("value_xml") : parameter.get("value");
if (parameter.get("x-examples") && parameter.get("x-examples").get("default")) {
paramValue = parameter.get("x-examples").get("default")
}
....
}

Is it possible to address this properly? Add support of x-examples into core or maybe create a plugin for this?

@webron
Copy link
Contributor

webron commented Jun 13, 2017

We currently don't have support for x-example/s in 3.X.

@ekazakas
Copy link
Author

ekazakas commented Jun 14, 2017

@webron any idea / hints how this could be done? I could try and make a contribution.

@webron
Copy link
Contributor

webron commented Jun 14, 2017

Thanks for the offer. Unfortunately, I can't point you in the right direction, and while @shockey can, he's really focused on finishing a different task right now. I'll assign the ticket to him so he could hopefully get back to you next week.

@ekazakas
Copy link
Author

Sure, that would be great!

@shockey
Copy link
Contributor

shockey commented Jun 27, 2017

@kamiKAZIK, apologies for the delay in my reply.

Your change to param-body.jsx seems like a step in the right direction - if you'd like to open a PR for this feature, I'd be happy to review it.

To you, and to anyone else considering implementing this feature, here's some prior art on x-example: #1980

@heldersepu
Copy link
Contributor

heldersepu commented Jul 3, 2017

@kamiKAZIK I use examples too but just the regular examples (not the "x-examples" never had a need for those) and they do work on v3.x.

Take a look here:
http://swashbuckletest.azurewebsites.net/swagger/ui/index#/Dictionary/Dictionary_PostEcho

image

@QuasiSoDo
Copy link

QuasiSoDo commented Jul 7, 2017

I am currently in the same boat of having missing x-example value display for my parameters in swagger-ui 3.x.
I noticed that java-package io.swagger.models.parameters.AbstractSerializableParameter has:

@JsonProperty("x-example")
public Object getExample() {

So a swagger.json generated with swagger.jaxrs.listing.SwaggerSerializers will only have "x-example" but not "example" fields

Now i am unsure why this is the case. Is "example" not a valid field for a Parameter and "x-example" is required?

Am i understanding correctly that x-example support is supposed to be added to be supported by swagger-ui and the Parameter-Objects should keep their x-example Fields?

@gmartinezsan
Copy link

hi @shockey, any workaround so we can get the values populated in the UI?
I'm using v 2.0 and can't seem to find any way to make the UI shows the values I have in the x-examples or examples element.
Thanks!

@heldersepu
Copy link
Contributor

heldersepu commented Oct 26, 2017

@gmartinezsan Do you still have the problem? Can you send us your swagger.json?

@mmamyan
Copy link

mmamyan commented Apr 2, 2020

Hello, is this problem fixed for swagger 2.0 and swagger ui 3.25.0? I still have this problem.

@hkosova
Copy link
Contributor

hkosova commented Mar 24, 2021

By the way, OpenAPI 3 has built-in support for request body examples. You can provide one or multiple examples and also reference external examples.

openapi: 3.0.0

paths:
  /something:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
            example:   # <------
              targets: [1, 2, 3, 4]

@cxx5208
Copy link

cxx5208 commented Feb 15, 2024

Hey Can you assign this to me? I will try to fix the issue
Thank you

@heldersepu
Copy link
Contributor

heldersepu commented Feb 15, 2024

@cxx5208 this is an open source project ... you don't need anything assigned to you ... just submit a PR with your fix and add a comment referencing this issue

@mattdelashaw
Copy link

@cxx5208 this is an open source project ... you don't need anything assigned to you ... just submit a PR with your fix and add a comment referencing this issue

What day and time are the sprint retrospectives?

@heldersepu
Copy link
Contributor

@cxx5208 this is an open source project ... you don't need anything assigned to you ... just submit a PR with your fix and add a comment referencing this issue

What day and time are the sprint retrospectives?

“At 20:04 on day-of-month 12.”
cron 4 20 12 * *

@userwiths userwiths linked a pull request Mar 15, 2025 that will close this issue
17 tasks
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.

10 participants