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

Unable to add example value for body #3208

Open
akash19901990 opened this issue May 24, 2019 · 2 comments
Open

Unable to add example value for body #3208

akash19901990 opened this issue May 24, 2019 · 2 comments

Comments

@akash19901990
Copy link

akash19901990 commented May 24, 2019

Version: swagger core 2.0.8, (openapi 3)

I am following the Swagger 2.0 Annotation docs , but I am unable to view example value for body in swagger UI.

public Response updateUserInfo(@RequestBody(description = "", required = true, content = @Content(mediaType = "application/json")}) final String userInfo)

Is there any equivalent of @ApiImplicitParams or @ExampleProperty (from swagger 1.x) for body in swagger 2.x.

Though the above doc states an example for @ApiResponse :

examples = { @ExampleObject(name = "boo", value = "example",summary = "example of boo", externalValue = "example of external value") }
but this is not working for body.

I have also tried this but the example does not show up in swagge UI:

public Response updateUserInfo(@Parameter(examples = {@ExampleObject(name = "userInfo", value = "some example")})) final String userInfo)

@matteosilv
Copy link

matteosilv commented Sep 16, 2019

This works for me in swagger core 2.0.6:

 public MyResponse myMethod(@RequestBody(description = "test body",
                content = { @Content(mediaType = "application/json",
                     examples = @ExampleObject(
                         name = "test", 
                         summary = "test example",
                         value = "{ \"key\" : \"value\"}"),
                schema = @Schema(example = "{ \"key\" : \"value\"}")) }) MyRequest request)

generates the following output in openapi.json:

requestBody": {
    "description": "test body",
    "content": {
        "application/json": {
            "schema": {
                "type": "string",
                "example": {
                    "key": "value"
                }
            },
           "examples": {
               "test": {
                   "summary": "test example",
                   "description": "test",
                   "value": {
                         "key": "value"
                    }
               }
           }
       }
   }
}

Then if you use the latest swagger ui (check this out swagger-api/swagger-ui#2651), you'll have it rendered. externalValue is still not working as of bug swagger-api/swagger-ui#5433

@PatrikScully
Copy link

PatrikScully commented May 6, 2022

I put the following swagger annotation to a request body method argument, but the externalValue property not worked for me.

@RequestBody(content = {
  @Content(mediaType = "application/json", 
           examples = @ExampleObject(name = "Example", externalValue = "http://localhost:8080/example.json"))
})

The swagger shows the @ExampleObject name and a description with the name's value, but the example value is the default Swagger generated value and not the example json file content. The response json is in the Spring boot resource/static folder, so I can access it successfully via web browser.

If I change the externalValue property to the simple value property, it's works fine.

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

No branches or pull requests

3 participants