Skip to content

Commit

Permalink
use the "Of" convetion instead of Generics types in Swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovanni007 committed Oct 21, 2021
1 parent 8b7a065 commit 2737ae0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public Docket customize(final Docket docket) {
WildcardType.class,
CloudRuntimeEventType.class);

return docket.forCodeGeneration(true)
.alternateTypeRules(AlternateTypeRules.newRule(resourceTypeWithWildCard,
return docket.alternateTypeRules(AlternateTypeRules.newRule(resourceTypeWithWildCard,
CloudRuntimeEventModel.class)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand Down Expand Up @@ -52,10 +56,20 @@ public void should_swaggerDefinitionHavePathsAndDefinitionsAndInfo() throws Exce
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.paths").isNotEmpty())
.andExpect(jsonPath("$.components.schemas").isNotEmpty())
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("ListResponseContent"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntriesResponseContent"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntryResponseContent"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("ListResponseContentOf"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntriesResponseContentOf"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntryResponseContentOf"))))
.andExpect(jsonPath("$.info.title").value("Activiti Cloud Query :: Starter :: Query ReST API"))
.andExpect(content().string(
both(notNullValue(String.class))
.and(not(containsString("ListResponseContent«")))
.and(not(containsString("EntriesResponseContent«")))
.and(not(containsString("EntryResponseContent«")))
.and(not(containsString("PagedResources«")))
.and(not(containsString("PagedResources«")))
.and(not(containsString("Resources«Resource«")))
.and(not(containsString("Resource«")))
))
.andReturn();

assertThatJson(result.getResponse().getContentAsString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ public void should_swaggerDefinitionHavePathsAndDefinitionsAndInfo() throws Exce
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.paths").isNotEmpty())
.andExpect(jsonPath("$.components.schemas").isNotEmpty())
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("ListResponseContent"))))
.andExpect(
jsonPath("$.components.schemas").value(hasKey(startsWith("EntriesResponseContent"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntryResponseContent"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("ListResponseContentOf"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntriesResponseContentOf"))))
.andExpect(jsonPath("$.components.schemas").value(hasKey(startsWith("EntryResponseContentOf"))))
.andExpect(jsonPath("$.components.schemas[\"SaveTaskPayload\"].properties")
.value(hasKey("payloadType")))
.andExpect(jsonPath("$.info.title")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ private Docket baseDocket() {
if (apiInfo != null) {
baseDocket.apiInfo(apiInfo);
}

baseDocket.forCodeGeneration(true);
return applyCustomizations(baseDocket);
}

Expand Down

0 comments on commit 2737ae0

Please sign in to comment.