descriptionBuilder.text(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, response.getDescription()));
public static void correctResponses(Operation operation) { int okCode = Status.OK.getStatusCode(); String strOkCode = String.valueOf(okCode); Response okResponse = null; for (Entry<String, Response> responseEntry : operation.getResponses().entrySet()) { Response response = responseEntry.getValue(); if (StringUtils.isEmpty(response.getDescription())) { response.setDescription("response of " + responseEntry.getKey()); } if (operation.getResponses().get(strOkCode) != null) { continue; } int statusCode = NumberUtils.toInt(responseEntry.getKey()); if ("default".equals(responseEntry.getKey())) { statusCode = okCode; } if (Family.SUCCESSFUL.equals(Family.familyOf(statusCode))) { okResponse = response; } } if (okResponse != null) { operation.addResponse(strOkCode, okResponse); } }
private static void mergeResponse(Operation operation, ResponseConfig responseConfig) { if (operation.getResponses() == null) { operation.response(responseConfig.getCode(), responseConfig.getResponse()); return; } Response response = operation.getResponses().get(String.valueOf(responseConfig.getCode())); if (response == null) { operation.response(responseConfig.getCode(), responseConfig.getResponse()); return; } Response sourceResp = responseConfig.getResponse(); if (StringUtils.isNotEmpty(sourceResp.getDescription()) && StringUtils.isEmpty(response.getDescription())) { response.setDescription(sourceResp.getDescription()); } if (sourceResp.getSchema() != null && response.getSchema() == null) { response.setSchema(sourceResp.getSchema()); } if (sourceResp.getExamples() != null && response.getExamples() == null) { response.setExamples(sourceResp.getExamples()); } if (sourceResp.getHeaders() != null && response.getHeaders() == null) { response.setHeaders(sourceResp.getHeaders()); } if (sourceResp.getVendorExtensions() != null && response.getVendorExtensions() == null) { response.setVendorExtensions(sourceResp.getVendorExtensions()); } }
String generateModelName(Response response) { return generateModelName(response.getDescription()); }
/** * * @param response * @return */ private MockResponse getRandomExamplesfromResponse(String responseCode, Response response) { Map<String, Object> examples = response.getExamples(); MockResponse mockResponse = null; if (examples != null) { Random random = new Random(); List<String> keys = new ArrayList<>(examples.keySet()); String randomKey = keys.get(random.nextInt(keys.size())); mockResponse = new MockResponse(responseCode, examples.get(randomKey), response.getDescription(), "application/json"); } else { LOGGER.log(Level.WARNING, "No Example Object Set for ResponseCode " + responseCode); mockResponse = new MockResponse(responseCode, null, response.getDescription(), "application/json"); } return mockResponse; }
@Override public DataShape createShapeFromResponse(final ObjectNode json, final Swagger swagger, final Operation operation) { final Optional<Response> maybeResponse = findResponse(operation); if (!maybeResponse.isPresent()) { return DATA_SHAPE_NONE; } final Response response = maybeResponse.get(); final Model responseSchema = response.getResponseSchema(); final String description = response.getDescription(); final ObjectNode bodySchema = createSchemaFromModel(json, description, responseSchema); return unifiedJsonSchema("Response", "API response payload", bodySchema, null); }
public static void correctResponses(Operation operation) { int okCode = Status.OK.getStatusCode(); String strOkCode = String.valueOf(okCode); Response okResponse = null; for (Entry<String, Response> responseEntry : operation.getResponses().entrySet()) { Response response = responseEntry.getValue(); if (StringUtils.isEmpty(response.getDescription())) { response.setDescription("response of " + responseEntry.getKey()); } if (operation.getResponses().get(strOkCode) != null) { continue; } int statusCode = NumberUtils.toInt(responseEntry.getKey()); if ("default".equals(responseEntry.getKey())) { statusCode = okCode; } if (Family.SUCCESSFUL.equals(Family.familyOf(statusCode))) { okResponse = response; } } if (okResponse != null) { operation.addResponse(strOkCode, okResponse); } }
@Override public DataShape createShapeFromResponse(final ObjectNode json, final Swagger swagger, final Operation operation) { final Optional<Response> maybeResponse = findResponse(operation); if (!maybeResponse.isPresent()) { return DATA_SHAPE_NONE; } final Response response = maybeResponse.get(); final Model responseSchema = response.getResponseSchema(); final String description = response.getDescription(); final JsonNode schema = createSchemaFromModel(json, description, responseSchema); String schemaString; try { schemaString = Json.writer().writeValueAsString(schema); } catch (final JsonProcessingException e) { throw new IllegalStateException("Unable to serialize given JSON specification in response schema: " + schema, e); } return new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).name("Response").description("API response payload") .specification(schemaString).build(); }
/** * The method generates a mocked response based on the provided {@link Response} and the * <code>httpStatusCode</code>. * @param httpStatusCode The HTTP status code that the mocked response will have. Please note that * any mock response with status code different from OK (200), will be * marked as disabled. * @param response The Swagger response that the mocked response will be based on. * @return A new {@link RestMockResponse} based on the provided {@link Response}. */ private RestMockResponse generateResponse(final int httpStatusCode, final Response response){ RestMockResponse restMockResponse = new RestMockResponse(); restMockResponse.setName(response.getDescription()); restMockResponse.setHttpStatusCode(httpStatusCode); restMockResponse.setUsingExpressions(true); if(httpStatusCode == DEFAULT_RESPONSE_CODE){ restMockResponse.setStatus(RestMockResponseStatus.ENABLED); } else { restMockResponse.setStatus(RestMockResponseStatus.DISABLED); } if(response.getHeaders() != null){ for(Map.Entry<String, Property> headerEntry : response.getHeaders().entrySet()){ String headerName = headerEntry.getKey(); HttpHeader httpHeader = new HttpHeader(); httpHeader.setName(headerName); // Swagger does not include an example value for the response. restMockResponse.getHttpHeaders().add(httpHeader); } } return restMockResponse; }
private static void mergeResponse(Operation operation, ResponseConfig responseConfig) { if (operation.getResponses() == null) { operation.response(responseConfig.getCode(), responseConfig.getResponse()); return; } Response response = operation.getResponses().get(String.valueOf(responseConfig.getCode())); if (response == null) { operation.response(responseConfig.getCode(), responseConfig.getResponse()); return; } Response sourceResp = responseConfig.getResponse(); if (StringUtils.isNotEmpty(sourceResp.getDescription()) && StringUtils.isEmpty(response.getDescription())) { response.setDescription(sourceResp.getDescription()); } if (sourceResp.getSchema() != null && response.getSchema() == null) { response.setSchema(sourceResp.getSchema()); } if (sourceResp.getExamples() != null && response.getExamples() == null) { response.setExamples(sourceResp.getExamples()); } if (sourceResp.getHeaders() != null && response.getHeaders() == null) { response.setHeaders(sourceResp.getHeaders()); } if (sourceResp.getVendorExtensions() != null && response.getVendorExtensions() == null) { response.setVendorExtensions(sourceResp.getVendorExtensions()); } }
response.setDescription(v2Response.getDescription());
response.setDescription(v2Response.getDescription());
response.setDescription(v2Response.getDescription());
descriptionBuilder.text(markupDescription(config.getSwaggerMarkupLanguage(), markupDocBuilder, response.getDescription()));
_builder.newLineIfNotEmpty(); _builder.append(" "); String _description = response.getDescription(); String _docHtml = null; if (_description!=null) {
_builder.newLineIfNotEmpty(); _builder.append(" "); String _description = response.getDescription(); String _docHtml = null; if (_description!=null) {