|
44 | 44 |
|
45 | 45 | import com.fasterxml.jackson.annotation.JsonView;
|
46 | 46 | import com.fasterxml.jackson.core.JsonProcessingException;
|
| 47 | +import com.fasterxml.jackson.databind.MapperFeature; |
47 | 48 | import com.fasterxml.jackson.databind.ObjectMapper;
|
48 | 49 | import com.fasterxml.jackson.databind.SerializationFeature;
|
49 | 50 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
|
61 | 62 | import io.swagger.v3.oas.models.PathItem;
|
62 | 63 | import io.swagger.v3.oas.models.PathItem.HttpMethod;
|
63 | 64 | import io.swagger.v3.oas.models.Paths;
|
| 65 | +import io.swagger.v3.oas.models.media.Schema; |
64 | 66 | import io.swagger.v3.oas.models.media.StringSchema;
|
65 | 67 | import io.swagger.v3.oas.models.parameters.Parameter;
|
66 | 68 | import io.swagger.v3.oas.models.responses.ApiResponses;
|
67 | 69 | import org.apache.commons.lang3.ArrayUtils;
|
68 | 70 | import org.apache.commons.lang3.StringUtils;
|
69 | 71 | import org.slf4j.Logger;
|
70 | 72 | import org.slf4j.LoggerFactory;
|
| 73 | +import org.springdoc.api.mixins.SortedOpenAPIMixin; |
| 74 | +import org.springdoc.api.mixins.SortedSchemaMixin; |
71 | 75 | import org.springdoc.core.AbstractRequestService;
|
72 | 76 | import org.springdoc.core.ActuatorProvider;
|
73 | 77 | import org.springdoc.core.GenericParameterService;
|
@@ -1025,7 +1029,7 @@ protected String writeYamlValue(OpenAPI openAPI) throws JsonProcessingException
|
1025 | 1029 | String result;
|
1026 | 1030 | ObjectMapper objectMapper = Yaml.mapper();
|
1027 | 1031 | if (springDocConfigProperties.isWriterWithOrderByKeys())
|
1028 |
| - objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); |
| 1032 | + sortOutput(objectMapper); |
1029 | 1033 | YAMLFactory factory = (YAMLFactory) objectMapper.getFactory();
|
1030 | 1034 | factory.configure(Feature.USE_NATIVE_TYPE_ID, false);
|
1031 | 1035 | if (!springDocConfigProperties.isWriterWithDefaultPrettyPrinter())
|
@@ -1090,7 +1094,7 @@ protected String writeJsonValue(OpenAPI openAPI) throws JsonProcessingException
|
1090 | 1094 | String result;
|
1091 | 1095 | ObjectMapper objectMapper = Json.mapper();
|
1092 | 1096 | if (springDocConfigProperties.isWriterWithOrderByKeys())
|
1093 |
| - objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); |
| 1097 | + sortOutput(objectMapper); |
1094 | 1098 | if (!springDocConfigProperties.isWriterWithDefaultPrettyPrinter())
|
1095 | 1099 | result = objectMapper.writeValueAsString(openAPI);
|
1096 | 1100 | else
|
@@ -1158,4 +1162,11 @@ enum ConditionType {
|
1158 | 1162 | */
|
1159 | 1163 | HEADERS
|
1160 | 1164 | }
|
| 1165 | + |
| 1166 | + private void sortOutput(ObjectMapper objectMapper) { |
| 1167 | + objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); |
| 1168 | + objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); |
| 1169 | + objectMapper.addMixIn(OpenAPI.class, SortedOpenAPIMixin.class); |
| 1170 | + objectMapper.addMixIn(Schema.class, SortedSchemaMixin.class); |
| 1171 | + } |
1161 | 1172 | }
|
0 commit comments