use of io.swagger.v3.oas.annotations.responses.ApiResponses in project carbon-apimgt by wso2.
the class OASParserUtil method setRefOfApiResponseHeaders.
private static void setRefOfApiResponseHeaders(ApiResponses responses, SwaggerUpdateContext context) {
if (responses != null) {
for (ApiResponse response : responses.values()) {
Map<String, Header> headers = response.getHeaders();
if (headers != null) {
for (Header header : headers.values()) {
Content content = header.getContent();
extractReferenceFromContent(content, context);
}
}
}
}
}
use of io.swagger.v3.oas.annotations.responses.ApiResponses in project atlasmap by atlasmap.
the class CsvService method inspect.
/**
* Inspect a CSV instance and return a Document object.
* @param request request
* @param format format
* @param delimiter delimiter
* @param firstRecordAsHeader first record as header
* @param skipHeaderRecord skip header record
* @param headers headers
* @param commentMarker comment marker
* @param escape escape
* @param ignoreEmptyLines ignore empty lines
* @param ignoreHeaderCase ignore header case
* @param ignoreSurroundingSpaces ignore surrounding spaces
* @param nullString null string
* @param quote quote
* @param allowDuplicateHeaderNames allow duplicate header names
* @param allowMissingColumnNames allow missing column names
* @return {@link CsvInspectionResponse}
* @throws IOException unexpected error
*/
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("/inspect")
@Operation(summary = "Inspect CSV", description = "Inspect a CSV instance and return a Document object")
@RequestBody(description = "Csv", content = @Content(mediaType = "text/csv", schema = @Schema(implementation = String.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = CsvInspectionResponse.class)), description = "Return a Document object"))
public Response inspect(InputStream request, @QueryParam("format") String format, @QueryParam("delimiter") String delimiter, @QueryParam("firstRecordAsHeader") Boolean firstRecordAsHeader, @QueryParam("skipRecordHeader") Boolean skipHeaderRecord, @QueryParam("headers") String headers, @QueryParam("commentMarker") String commentMarker, @QueryParam("escape") String escape, @QueryParam("ignoreEmptyLines") Boolean ignoreEmptyLines, @QueryParam("ignoreHeaderCase") Boolean ignoreHeaderCase, @QueryParam("ignoreSurroundingSpaces") Boolean ignoreSurroundingSpaces, @QueryParam("nullString") String nullString, @QueryParam("quote") String quote, @QueryParam("allowDuplicateHeaderNames") Boolean allowDuplicateHeaderNames, @QueryParam("allowMissingColumnNames") Boolean allowMissingColumnNames) throws IOException {
long startTime = System.currentTimeMillis();
CsvInspectionResponse response = new CsvInspectionResponse();
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Options: delimiter={}, firstRecordAsHeader={}", delimiter, firstRecordAsHeader);
}
CsvConfig csvConfig = new CsvConfig(format);
if (delimiter != null) {
csvConfig.setDelimiter(delimiter.charAt(0));
}
csvConfig.setFirstRecordAsHeader(firstRecordAsHeader);
csvConfig.setSkipHeaderRecord(skipHeaderRecord);
csvConfig.setHeaders(headers);
if (commentMarker != null) {
csvConfig.setCommentMarker(commentMarker.charAt(0));
}
if (escape != null) {
csvConfig.setEscape(escape.charAt(0));
}
csvConfig.setIgnoreEmptyLines(ignoreEmptyLines);
csvConfig.setIgnoreHeaderCase(ignoreHeaderCase);
csvConfig.setIgnoreSurroundingSpaces(ignoreSurroundingSpaces);
csvConfig.setNullString(nullString);
if (quote != null) {
csvConfig.setQuote(quote.charAt(0));
}
csvConfig.setAllowDuplicateHeaderNames(allowDuplicateHeaderNames);
csvConfig.setAllowMissingColumnNames(allowMissingColumnNames);
CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig);
csvFieldReader.setDocument(request);
Document document = csvFieldReader.readSchema();
response.setCsvDocument(document);
request.close();
} catch (Exception e) {
LOG.error("Error inspecting CSV: " + e.getMessage(), e);
response.setErrorMessage(e.getMessage());
} finally {
request.close();
;
response.setExecutionTime(System.currentTimeMillis() - startTime);
}
if (LOG.isDebugEnabled()) {
LOG.debug(("Response: {}" + new ObjectMapper().writeValueAsString(response)));
}
return Response.ok().entity(toJson(response)).build();
}
use of io.swagger.v3.oas.annotations.responses.ApiResponses in project carbon-apimgt by wso2.
the class RestApiCommonUtil method generateOpenAPIForAsync.
/**
* Generate a basic OpenAPI definition with given details.
*
* @param name name of the API.
* @param version version of the API.
* @param context context of the API.
* @param callbackEndpoint callback URL of the async API.
* @return OpenAPI definition as String.
* @throws JsonProcessingException Error occurred while generating the OpenAPI.
*/
public static String generateOpenAPIForAsync(String name, String version, String context, String callbackEndpoint) throws JsonProcessingException {
OpenAPI openAPI = new OpenAPI();
Info info = new Info();
info.setTitle(name);
info.setDescription("API Definition of " + name);
info.setVersion(version);
openAPI.setInfo(info);
ArrayList<Server> servers = new ArrayList<>();
Server server = new Server();
server.setUrl("/");
servers.add(server);
openAPI.setServers(Arrays.asList(server));
Paths paths = new Paths();
PathItem pathItem = new PathItem();
Operation operation = new Operation();
ApiResponses apiResponses = new ApiResponses();
ApiResponse apiResponse = new ApiResponse();
apiResponse.setDescription("Default response");
apiResponses.addApiResponse("default", apiResponse);
operation.setResponses(apiResponses);
pathItem.setPost(operation);
paths.addPathItem("/*", pathItem);
openAPI.paths(paths);
List<String> urls = new ArrayList<>();
urls.add(callbackEndpoint);
Map<String, Object> tempMap = new HashMap();
tempMap.put("type", "http");
tempMap.put("urls", urls);
openAPI.addExtension(X_WSO2_PRODUCTION_ENDPOINTS, tempMap);
openAPI.addExtension(X_WSO2_SANDBOX_ENDPOINTS, tempMap);
openAPI.addExtension(X_WSO2_AUTH_HEADER, "Authorization");
openAPI.addExtension(X_WSO2_BASEPATH, context + "/" + version);
openAPI.addExtension(X_WSO2_DISABLE_SECURITY, true);
return Json.mapper().writeValueAsString(openAPI);
}
use of io.swagger.v3.oas.annotations.responses.ApiResponses in project atlasmap by atlasmap.
the class JavaService method inspectClass.
/**
* Inspects a Java Class with specified fully qualified class name and return a Document object.
* @param requestIn request
* @return {@link ClassInspectionResponse}
*/
@POST
@Path("/class")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Inspect Class", description = "Inspect a Java Class with specified fully qualified class name and return a Document object")
@RequestBody(description = "ClassInspectionRequest object", content = @Content(schema = @Schema(implementation = ClassInspectionRequest.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ClassInspectionResponse.class)), description = "Return a Document object represented by JavaClass"))
public Response inspectClass(InputStream requestIn) {
ClassInspectionRequest request = fromJson(requestIn, ClassInspectionRequest.class);
ClassInspectionResponse response = new ClassInspectionResponse();
ClassInspectionService classInspectionService = new ClassInspectionService();
classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
configureInspectionService(classInspectionService, request);
if (LOG.isDebugEnabled()) {
LOG.debug("Class inspection request: {}", new String(toJson(request)));
}
long startTime = System.currentTimeMillis();
try {
JavaClass c = null;
if (request.getClasspath() == null || request.getClasspath().isEmpty()) {
AtlasService atlasService = resourceContext.getResource(AtlasService.class);
c = classInspectionService.inspectClass(atlasService.getLibraryLoader(), request.getClassName(), request.getCollectionType(), request.getCollectionClassName());
} else {
c = classInspectionService.inspectClass(request.getClassName(), request.getCollectionType(), request.getClasspath());
}
response.setJavaClass(c);
} catch (Throwable e) {
String msg = String.format("Error inspecting class %s - %s: %s", request.getClassName(), e.getClass().getName(), e.getMessage());
LOG.error(msg, e);
response.setErrorMessage(msg);
} finally {
response.setExecutionTime(System.currentTimeMillis() - startTime);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Class inspection response: {}", new String(toJson(response)));
}
return Response.ok().entity(toJson(response)).build();
}
use of io.swagger.v3.oas.annotations.responses.ApiResponses in project atlasmap by atlasmap.
the class AtlasService method validateMappingRequest.
/**
* Validates the mapping file.
* @param mapping mapping
* @param mappingDefinitionId mapping definition ID
* @param uriInfo URI info
* @return {@link Validations} validation result
*/
@PUT
@Path("/mapping/validate/{mappingDefinitionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Validate Mapping", description = "Validate mapping file")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Validations.class)), description = "Return a validation result"))
public Response validateMappingRequest(InputStream mapping, @Parameter(description = "Mapping ID") @PathParam("mappingDefinitionId") Integer mappingDefinitionId, @Context UriInfo uriInfo) {
try {
AtlasMapping atlasMapping = fromJson(mapping, AtlasMapping.class);
LOG.debug("Validate mappings: {}", atlasMapping.getName());
return validateMapping(mappingDefinitionId, atlasMapping, uriInfo);
} catch (AtlasException | IOException e) {
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations