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

@ExampleProperty/value is getting ignored #3037

Closed
napolev opened this issue Jul 7, 2019 · 24 comments
Closed

@ExampleProperty/value is getting ignored #3037

napolev opened this issue Jul 7, 2019 · 24 comments
Labels
Milestone

Comments

@napolev
Copy link

napolev commented Jul 7, 2019

What version of the library are you using?

2.9.2

What kind of issue is this?

Bug

Example Repository

https://github.com/napolev/springfox-swagger2-issue

How to recreate the issue

$ git clone https://github.com/napolev/springfox-swagger2-issue
$ cd springfox-swagger2-issue
$ gradle bootRun

Description of the issue

On the repository pointed above there is a very simple project which contains the following file:

/src/main/java/com/example/demo/car/CarController.java

Preview

The issue is that the @ExampleProperty / value is getting ignored as you can see on the image below:

Preview

Other than that, everything works fine. For example, for the following payload the response is correct:

Preview

@ironijunior
Copy link

+1

2 similar comments
@charlycou
Copy link

+1

@trevarmand
Copy link

+1

@dilipkrish dilipkrish added the bug label Aug 6, 2019
@dilipkrish dilipkrish added this to the 3.0 milestone Aug 6, 2019
@dilipkrish
Copy link
Member

@napolev thank you for a detailed issue. I'll look into this issue. Can you see what the json looks like for the endpoint? Im curious if this is an issue with swagger-ui

@denbard
Copy link

denbard commented Aug 26, 2019

+1

@Maegner
Copy link

Maegner commented Sep 6, 2019

@dilipkrish seems like a UI issue since the examples actually get to the FE but are never displayed.
Screenshot 2019-09-06 at 16 30 45

@markewallace
Copy link

+1

@napolev
Copy link
Author

napolev commented Oct 17, 2019

Hi @dilipkrish, any update on this? Thanks!

@marciosindeaux
Copy link

+1

@shantis
Copy link

shantis commented Dec 18, 2019

@dilipkrish Any update on this issue? The examples are not working in 2.9.2. For us examples are a must for documentation. Please help!

@tlg-265
Copy link

tlg-265 commented Dec 18, 2019

is this project discontinued maybe?

@shantis
Copy link

shantis commented Dec 18, 2019

So examples will never work in springfox -- I wonder how other organizations used swagger with examples in 2.0. Any pointers would really help. Thanks!

@tobHai
Copy link

tobHai commented Jan 10, 2020

Like @Maegner said the x-examples are loaded properly however they are not displayed in the UI.
Any hints on how to solve this ?
As far as I understand the index.html in swagger-ui folder loads a certain webjar version of the UI but how can a change be made to this webjar?
Is it possible to load another version of the webjar?

@vemonet
Copy link

vemonet commented Feb 23, 2020

Apparently x-examples are already a workaround for POST queries:
swagger-api/swagger-ui#1980

I did not have issue using examples for post queries with OAS3 (which should be normal, I don't see why we should use a different property label for POST queries) resolved by https://smart-api.info/

@nikosvaggalis
Copy link

I discovered that springfox produces x-examples in the json description file which is not recognized by spring-ui.The right format that spring ui correctly renders is having the example as part of the schema block of the field.Also called example not x-examples

"schema":{ "type":"string", "example" : { "property":"this is a test" }}

all libraries versions are 2.9.2.
Can someone please verify?
thanks

@mdfass
Copy link

mdfass commented Apr 1, 2020

Has anybody tried this with 3.0.0.-SNAPSHOT? I have the same issue with 2.9.2

@indicasta
Copy link

Hi! @mdfass I already tried with 3.0.0-SNAPSHOT and still the same issue with 2.9.2. No change about it!

@nikosvaggalis
Copy link

yes,I've tried with 3.0.0-SNAPSHOT and it's still the same.Can you try to do what I've suggested to see if it works for you?

@indicasta
Copy link

Hi! @nikosvaggalis I have tried what you suggested before about changing the JSON file produced by Springfox , replacing the "x-examples" by:

"schema":{ "type":"string", "example" : { "property":"this is a test" }}

For this purpose I took the first example in this issue provided by @napolev, first of all I changed the Springfox version from 2.9.2 to 3.0.0-SNAPSHOT and reduced the JSON file obtained with this last version, then I converted the JSON file to YML using the swagger editor. You can find the result in https://github.com/indicasta/springfox-swagger2-issue/blob/master/api-docs-reduced.yml. Finally with this reduction I got the expected result shown in the image below.

image

Do you have any idea on how can I get that result by using Springfox automatically?

Just in case here you have the repo I created for this purpose:

https://github.com/indicasta/springfox-swagger2-issue

Thanks!

@tlg-265
Copy link

tlg-265 commented Apr 2, 2020

thank you @indicasta for your clear feedback. I think we need to know what Springfox annotations to use on top of the controller method in order to let Springfox to do the proper conversion from Java to Swagger syntax (left panel on the image above). In my opinion this is a very common use case. Hopefully @dilipkrish can provide some light on this.

@napolev
Copy link
Author

napolev commented Apr 3, 2020

Bingo! Finally on this commit I was able to find the way to make Sprinfox Swagger to auto populate the values on the Swagger UI:

napolev/springfox-swagger2-issue@7e2591d

Here you have a screenshot of it:

image

Thank you guys for all your help including @indicasta.

@napolev napolev closed this as completed Apr 3, 2020
@prabhushrikant
Copy link

Has anybody tried this with 3.0.0.-SNAPSHOT? I have the same issue with 2.9.2

I tried with 3.0.0-SNAPSHOT and issue still persists

@prabhushrikant
Copy link

prabhushrikant commented Jul 9, 2020

Hi! @nikosvaggalis I have tried what you suggested before about changing the JSON file produced by Springfox , replacing the "x-examples" by:

"schema":{ "type":"string", "example" : { "property":"this is a test" }}

For this purpose I took the first example in this issue provided by @napolev, first of all I changed the Springfox version from 2.9.2 to 3.0.0-SNAPSHOT and reduced the JSON file obtained with this last version, then I converted the JSON file to YML using the swagger editor. You can find the result in https://github.com/indicasta/springfox-swagger2-issue/blob/master/api-docs-reduced.yml. Finally with this reduction I got the expected result shown in the image below.

image

Do you have any idea on how can I get that result by using Springfox automatically?

Just in case here you have the repo I created for this purpose:

https://github.com/indicasta/springfox-swagger2-issue

Thanks!

I confirm it works in editor.swagger.io if you manual add example section but springfox simply ignores it if it finds a reference model and tries to infer the schema from model. However this approach doesn't work if your model going to have dynamic property names e.g. model has <string, object> response property.

@dilipkrish
Copy link
Member

This has be fixed via #2767

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

No branches or pull requests