@Test public void shouldServeSpecificationsWithoutContentTypeMeta() { final byte[] specificationBytes = "this is the specification".getBytes(StandardCharsets.UTF_8); when(dataManager.fetch(Integration.class, "integration-id")).thenReturn( new Integration.Builder() .addResource( new ResourceIdentifier.Builder() .id("resource-id") .kind(Kind.OpenApi) .build()) .build()); when(resourceManager.loadOpenApiDefinition("resource-id")) .thenReturn(Optional.of(new OpenApi.Builder() .document(specificationBytes) .build())); try (Response response = handler.fetch("integration-id")) { assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(IntegrationSpecificationHandler.DEFAULT_CONTENT_TYPE); assertThat(response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION)) .isEqualTo("attachment; filename=" + IntegrationSpecificationHandler.DEFAULT_FILE_NAME); assertThat((byte[]) response.getEntity()).isEqualTo(specificationBytes); } }
@GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) public Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id) { final Integration integration = integrationHandler.getIntegration(id); return ApiGeneratorHelper.specificationFrom(resourceManager, integration) .map(IntegrationSpecificationHandler::createResponseFrom) .orElse(NOT_FOUND); }
IntegrationSpecificationHandler { @GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) public Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id) { final Integration integration = integrationHandler.getIntegration(id); return ApiGeneratorHelper.specificationFrom(resourceManager, integration) .map(IntegrationSpecificationHandler::createResponseFrom) .orElse(NOT_FOUND); } }
IntegrationSpecificationHandler { @GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) public Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id) { final Integration integration = integrationHandler.getIntegration(id); return ApiGeneratorHelper.specificationFrom(resourceManager, integration) .map(IntegrationSpecificationHandler::createResponseFrom) .orElse(NOT_FOUND); } IntegrationSpecificationHandler(final IntegrationHandler integrationHandler, final IntegrationResourceManager resourceManager); }
IntegrationSpecificationHandler { @GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) public Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id) { final Integration integration = integrationHandler.getIntegration(id); return ApiGeneratorHelper.specificationFrom(resourceManager, integration) .map(IntegrationSpecificationHandler::createResponseFrom) .orElse(NOT_FOUND); } IntegrationSpecificationHandler(final IntegrationHandler integrationHandler, final IntegrationResourceManager resourceManager); @GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id); @PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(description = "For an integration that is generated from a specification updates it so it conforms to the updated specification") @RequestBody(content = @Content(mediaType = "multipart/form-data", schema = @Schema(implementation = ApiHandler.APIFormData.class)), description = "Next revision of the specification") void update(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id,
        @NotNull @MultipartForm final ApiHandler.APIFormData apiFormData); }
IntegrationSpecificationHandler { @GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) public Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id) { final Integration integration = integrationHandler.getIntegration(id); return ApiGeneratorHelper.specificationFrom(resourceManager, integration) .map(IntegrationSpecificationHandler::createResponseFrom) .orElse(NOT_FOUND); } IntegrationSpecificationHandler(final IntegrationHandler integrationHandler, final IntegrationResourceManager resourceManager); @GET @Operation(description = "Responds with specification that defines this integration") @ApiResponse(responseCode = "404", description = "No specification resource defines this integration") @ApiResponse(responseCode = "204", description = "Empty specification provided when definining this integration") @ApiResponse(responseCode = "200", description = "Specification resource follows", headers = { @Header(name = "Content-Type", description = "The content type of the specification, e.g. `application/vnd.oai.openapi+json`"), @Header(name = "Content-Disposition", description = "Contains the `filename` parameter") }) Response fetch(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id); @PUT @Consumes(MediaType.MULTIPART_FORM_DATA) @Operation(description = "For an integration that is generated from a specification updates it so it conforms to the updated specification") @RequestBody(content = @Content(mediaType = "multipart/form-data", schema = @Schema(implementation = ApiHandler.APIFormData.class)), description = "Next revision of the specification") void update(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id,
        @NotNull @MultipartForm final ApiHandler.APIFormData apiFormData);  }