-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Spring-MVC: date and date-time format #1235
Comments
Hi again, I'm trying to find where the parameters are added in the Thanks |
@glederrey for the datetime format, I think it's worthwhile to consider the datetime format use by the Java API client: ApiClient.mustache#L60
For your 2nd question (where the parameters are added in the
{{>queryParams}} means using the template file queryParams.mustache. In other words, |
@wing328 Thanks a lot for your answer.. So, the thing is that it doesn't work.. I tried with this new format.. And I still get the 400 errors.. For the 2nd question, I understood that.. The thing I'd like to know is where in the JAVA code are these mustache files used.. (My idea would be to change these files and add some if conditions) Do you see what I mean? |
@glederrey For the 400 error, did you get an exception in the server side? Have you used tcpdump or other tool to inspect the request to ensure it's what your API client has sent out? If I understand correctly, you would like to add |
@wing328 I didn't get any exception.. Here is the full 400 error:
If I add this And that's exactly what I want to do.. =) |
@wing328 |
@wing328 I found a very ugly solution to do this.. I added this |
Hi I need to generate date format ("format": "date") in swagger json doc for GET parameters. Im using spring rest @RequestParam with @ApiParam() but in @ApiParma we dont have property like dataType then how can i generate format property in json doc . ("format": "date").if someone help on this it will be great help to me. Thanks in advance. |
Not from Swagger dev Team Hi, What do you mean exactly?? I don't understand your problem.. Is your problem linked to Spring-MVC or to the spec?? |
Hi @glederrey, we need to generate "format": "date" json propery for the GET serive parameter like below { we have this dateType option in @ApiModelProperty(dataType="java.sql.Date",notes="The toDate is ending data range of given dateType value. format should be YYYY-MM-DD.") but dateType property not in not in @ApiParam? so not able to generate the "format": "date" attibute in json doc?? |
working- this is in @apimodel -used in POST Method @ApiModelProperty(dataType="java.sql.Date",notes="The toDate is ending data range of given dateType value. format should be YYYY-MM-DD.") not working - this is in method parameter-used for GET method @ApiParam(value="The toDate is ending data range of given dateType value. format should be YYYY-MM-DD.") |
I think you have the same problem that I had.. Here is the trick I used to get rid of this problem. Go there: swagger-codegen/modules/swagger-codegen/src/main/resources/JavaSpringMVC and open the file called queryParams.mustache.. Then, in this file, just before this: Then, you can regenerate your Spring-MVC server and test it.. |
@glederrey I already use @DateTimeFormat(pattern = "yyyy-MM-dd") this annotation but not worked. like below @ApiParam(value="The toDate is ending data range of given dateType value. format should be YYYY-MM-DD.") what is mustache? its need any configuration or need to addd queryParams.mustache. file in my classpath? |
@anand4sn The mustache files are used to generate the Spring MVC stub server.. I don't know if you're using Swagger Codegen to generate your server or if you're building it from scratch.. In my endpoint definition (in the Spring MVC server), I have something like this: The only things that changes between your definition and mine is the order of Try changing this order.. If it doesn't fix, you should wait until a guy from Swagger answer you.. |
@glederrey Many Thanks . Let me try changing the order. |
Hi All, I have a similar problem. In my swagger the header is defined like the following: The generated code is: We expected that input like the following are accpeted:
does it make sense? Thanks |
any updates on this issue? |
Hi,
I'm working with a Spring MVC stub server.. I have some
date
anddate-time
formats too.. I just found that there is a problem when you're giving adate
or adate-time
format as a parameter in an endpoint..I may be wrong, but it seems that you need to specify the format of the Date if you want to use it as a parameter.. Therefore, I propose you to add this:
For the
date-time
format,@DateTimeFormat(pattern="yyyy-MM-dd'T'hh:mm:ss'Z'")
if we assume UTC. And for thedate
format,@DateTimeFormat(pattern="yyyy-MM-dd")
..This should give something like this at the end:
public ResponseEntity<String> endSession(@ApiParam(value = "ID of the session", required = true) @RequestParam(value = "sessionId", required = true) String sessionId, @ApiParam(value = "End time of the session using the format date-time.", required = true) @RequestParam(value = "sessionEnd", required = true) @DateTimeFormat(pattern="yyyy-MM-dd'T'hh:mm:ss'Z'") Date sessionEnd)
Is it clear??
The text was updated successfully, but these errors were encountered: