spring-restdocs icon indicating copy to clipboard operation
spring-restdocs copied to clipboard

Support multiple types on a field descriptor and assert that actual type matches one of them

Open victorherraiz opened this issue 8 years ago • 7 comments

The following code produce a nice output in the type column, but It does not perform the assertion:

fieldWithPath("uid").type(Arrays.asList(JsonFieldType.STRING, JsonFieldType.NULL));

Is there a better way to do it? Would you accept a pull request about this?

victorherraiz avatar Feb 20 '17 00:02 victorherraiz

That sounds like a nice improvement. A PR would be welcome. Looks like the assertion could be performed whenever a collection or array of JsonFieldType is passed in.

wilkinsona avatar Feb 20 '17 07:02 wilkinsona

OK, I will do a pull request these week. What do you think about adding .type(JsonFieldType... types), .type(JsonFieldType type) and deprecate .type(Object obj).

is there any reason to use an object instead of JsonFiledType?

victorherraiz avatar Feb 20 '17 08:02 victorherraiz

OK, I will do a pull request these week.

Thanks

What do you think about adding .type(JsonFieldType... types), .type(JsonFieldType type) and deprecate .type(Object obj)

Overloading with (JsonFieldType... types) and (JsonFieldType type) is worth considering, although I'm not sure that I want JSON-specific classes on FieldDescriptor.

Is there any reason to use an Object instead of JsonFieldType?

Yes, the payload may not be JSON. For example, REST Docs also supports XML payloads.

wilkinsona avatar Feb 20 '17 08:02 wilkinsona

@victorherraiz @wilkinsona Is there any progress or any plan to add this feature?

BK-Choi avatar Apr 18 '17 12:04 BK-Choi

I have this already implemented in my local repo, but I have not had time to updated and push it, I have to help other projects in my company and I abandoned the POC I was doing. I will do it this week. Sorry for the late reply.

victorherraiz avatar Apr 18 '17 16:04 victorherraiz

@victorherraiz good news. thanks!

BK-Choi avatar Apr 21 '17 05:04 BK-Choi

https://github.com/wilkinsona/spring-restdocs/tree/gh-352

wilkinsona avatar Mar 28 '18 10:03 wilkinsona