Skip to content

Fix wrong content-type for SVG #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/main/java/org/gridsuite/study/server/StudyConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
*/
package org.gridsuite.study.server;

import org.springframework.http.MediaType;

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
*/

public final class StudyConstants {

private StudyConstants() {
}

public static final String IMAGE_SVG_VALUE = "image/svg+xml";
public static final MediaType IMAGE_SVG = MediaType.parseMediaType(IMAGE_SVG_VALUE);

public static final String CASE_API_VERSION = "v1";
public static final String SINGLE_LINE_DIAGRAM_API_VERSION = "v1";
public static final String NETWORK_CONVERSION_API_VERSION = "v1";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public ResponseEntity<byte[]> getVoltageLevelDiagram(
voltageLevelId,
diagramParameters,
nodeUuid);
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(result) :
return result != null ? ResponseEntity.ok().contentType(IMAGE_SVG).body(result) :
ResponseEntity.noContent().build();
}

Expand Down Expand Up @@ -931,7 +931,7 @@ public ResponseEntity<ShortCircuitParametersInfos> getShortCircuitParameters(
return ResponseEntity.ok().body(studyService.getShortCircuitParametersInfo(studyUuid));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network/substations/{substationId}/svg")
@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/network/substations/{substationId}/svg", produces = IMAGE_SVG_VALUE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add produces = IMAGE_SVG_VALUE as well on getVoltageLevelDiagram ?

@Operation(summary = "get the substation diagram for the given network and substation")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The svg"),
@ApiResponse(responseCode = "404", description = "The substation has not been found")})
Expand All @@ -956,7 +956,7 @@ public ResponseEntity<byte[]> getSubstationDiagram(
.build();
byte[] result = studyService.getSubstationSvg(studyUuid, substationId,
diagramParameters, substationLayout, nodeUuid);
return result != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(result) :
return result != null ? ResponseEntity.ok().contentType(IMAGE_SVG).body(result) :
ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void testDiagramsAndGraphics() throws Exception {
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/voltage-levels/{voltageLevelId}/svg?useName=false&language=en",
studyNameUserIdUuid, rootNodeUuid, "voltageLevelId")).andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_XML),
content().contentType(IMAGE_SVG),
content().string("byte"));

assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format(
Expand All @@ -286,7 +286,7 @@ public void testDiagramsAndGraphics() throws Exception {
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/voltage-levels/{voltageLevelId}/svg?useName=false",
studyNameUserIdUuid, rootNodeUuid, "voltageLevelId")).andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_XML),
content().contentType(IMAGE_SVG),
content().string("byte"));

assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format(
Expand Down Expand Up @@ -338,7 +338,7 @@ public void testDiagramsAndGraphics() throws Exception {
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/substations/{substationId}/svg?useName=false",
studyNameUserIdUuid, rootNodeUuid, "substationId")).andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_XML),
content().contentType(IMAGE_SVG),
content().string("substation-byte"));

assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format(
Expand Down
Loading