Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
Schema schema = (chain.hasNext()) ? chain.next().resolve(type, context, chain) : null;

if (isPageType && !replacePageWithPagedModel)
sortPageSchemaProperties(schema, context);
customizePageSchema(schema, context);
return schema;
}

Expand Down Expand Up @@ -161,12 +161,12 @@ private Type pagedModelType(JavaType type) {
}

/**
* Sort page schema properties.
* Require and sort page schema properties.
*
* @param schema the schema
* @param context the context
*/
private void sortPageSchemaProperties(Schema schema, ModelConverterContext context) {
private void customizePageSchema(Schema schema, ModelConverterContext context) {
Schema pageSchema = resolveReferencedSchema(schema, context);
if (pageSchema == null || pageSchema.getProperties() == null)
return;
Expand All @@ -179,6 +179,7 @@ private void sortPageSchemaProperties(Schema schema, ModelConverterContext conte
PAGE_PROPERTY_ORDER.forEach(property -> sortedProperties.put(property, properties.get(property)));
properties.forEach(sortedProperties::putIfAbsent);
pageSchema.setProperties(sortedProperties);
pageSchema.setRequired(PAGE_PROPERTY_ORDER);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@
}
},
"PageHelloWorld_Hello": {
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
],
"type": "object",
"properties": {
"totalElements": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@
}
},
"PageHelloWorld_Hello": {
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
],
"type": "object",
"properties": {
"totalPages": {
Expand Down Expand Up @@ -166,4 +179,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"PageableObject": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"PageableObject": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.web.config.EnableSpringDataWebSupport;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
Expand All @@ -47,6 +48,9 @@ protected void testApp() throws Exception {
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL))
.andExpect(status().isOk())
.andExpect(jsonPath("$.openapi", is("3.0.1")))
.andExpect(jsonPath("$.components.schemas.PageString.required", containsInAnyOrder(
"totalPages", "totalElements", "size", "content", "number", "sort", "pageable",
"numberOfElements", "first", "last", "empty")))
.andExpect(content().json(getContent("results/3.0.1/app10-direct.json"), true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.web.config.EnableSpringDataWebSupport;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
Expand All @@ -47,6 +48,9 @@ protected void testApp() throws Exception {
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL))
.andExpect(status().isOk())
.andExpect(jsonPath("$.openapi", is("3.1.0")))
.andExpect(jsonPath("$.components.schemas.PageString.required", containsInAnyOrder(
"totalPages", "totalElements", "size", "content", "number", "sort", "pageable",
"numberOfElements", "first", "last", "empty")))
.andExpect(content().json(getContent("results/3.1.0/app10-direct.json"), true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"PageableObject": {
"type": "object",
Expand Down Expand Up @@ -398,7 +411,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"UserDto": {
"type": "object",
Expand Down Expand Up @@ -455,7 +481,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"PageDummyListString": {
"type": "object",
Expand Down Expand Up @@ -501,7 +540,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"DummyPageString": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"PageableObject": {
"type": "object",
Expand Down Expand Up @@ -374,7 +387,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"PageDummyListString": {
"type": "object",
Expand Down Expand Up @@ -420,7 +446,20 @@
"empty": {
"type": "boolean"
}
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
]
},
"DummyPageString": {
"type": "object",
Expand Down
Loading