Skip to content

Commit 6bebe5c

Browse files
committed
Update openapi spec and improve determinism
1 parent 7b7a152 commit 6bebe5c

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/main/java/no/entur/mummu/config/SwaggerConfiguration.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@
55
import com.fasterxml.jackson.databind.SerializationFeature;
66
import io.swagger.v3.core.converter.ModelConverters;
77
import io.swagger.v3.core.jackson.ModelResolver;
8+
import io.swagger.v3.core.util.Json;
89
import io.swagger.v3.oas.models.OpenAPI;
910
import io.swagger.v3.oas.models.servers.Server;
11+
import org.springdoc.core.customizers.SpringDocCustomizers;
12+
import org.springdoc.core.properties.SpringDocConfigProperties;
13+
import org.springdoc.core.providers.ObjectMapperProvider;
1014
import org.springframework.beans.factory.annotation.Value;
1115
import org.springframework.context.annotation.Bean;
1216
import org.springframework.context.annotation.Configuration;
13-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
1417

1518
import java.util.List;
1619

1720
@Configuration
1821
public class SwaggerConfiguration {
1922

23+
static {
24+
// Configure swagger-core's global JSON mapper for OpenAPI serialization
25+
// This must be done in a static block to run before any OpenAPI processing
26+
ObjectMapper globalMapper = Json.mapper();
27+
globalMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
28+
globalMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
29+
}
30+
2031
@Value("${no.entur.mummu.swagger.host.url}")
2132
private String hostUrl;
2233

@@ -26,24 +37,28 @@ public SwaggerConfiguration() {
2637
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
2738
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
2839

40+
// Configure swagger-core's JSON mapper for schema generation
2941
ModelConverters.getInstance().addConverter(new ModelResolver(objectMapper));
3042
ModelConverters.getInstance().addConverter(new CustomConverters());
3143
}
3244

33-
@Bean
34-
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
35-
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
36-
builder.featuresToEnable(
37-
SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
38-
MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
39-
);
40-
return builder;
41-
}
42-
4345
@Bean
4446
public OpenAPI customOpenAPI() {
4547
Server server = new Server();
4648
server.setUrl(hostUrl);
4749
return new OpenAPI().servers(List.of(server));
4850
}
51+
52+
@Bean
53+
public ObjectMapperProvider springDocObjectMapperProvider() {
54+
return new ObjectMapperProvider(new SpringDocConfigProperties()) {
55+
@Override
56+
public ObjectMapper jsonMapper() {
57+
ObjectMapper mapper = super.jsonMapper();
58+
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
59+
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
60+
return mapper;
61+
}
62+
};
63+
}
4964
}

src/main/resources/public/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)