@Override public BinarySchema createProperty() { return new BinarySchema(); } },
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class BinarySchema {\n"); sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" format: ").append(toIndentedString(format)).append("\n"); sb.append(" _default: ").append(toIndentedString(_default)).append("\n"); sb.append(" _enum: ").append(toIndentedString(_enum)).append("\n"); sb.append("}"); return sb.toString(); }
@Test public void testByteArray() { Schema model = new Schema() .addProperties("byteArray", new ArraySchema().items(new BinarySchema())); assertEquals(Json.pretty(model), "{" + NEWLINE + " \"properties\" : {" + NEWLINE + " \"byteArray\" : {" + NEWLINE + " \"type\" : \"array\"," + NEWLINE + " \"items\" : {" + NEWLINE + " \"type\" : \"string\"," + NEWLINE + " \"format\" : \"binary\"" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + "}"); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class BinarySchema {\n"); sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" type: ").append(toIndentedString(type)).append("\n"); sb.append(" format: ").append(toIndentedString(format)).append("\n"); sb.append(" _default: ").append(toIndentedString(_default)).append("\n"); sb.append(" _enum: ").append(toIndentedString(_enum)).append("\n"); sb.append("}"); return sb.toString(); }
@Test public void testReadOnlyByteArray() { Schema model = new Schema() .addProperties("byteArray", new ArraySchema().items(new BinarySchema()).readOnly(true)); assertEquals(Json.pretty(model), "{" + NEWLINE + " \"properties\" : {" + NEWLINE + " \"byteArray\" : {" + NEWLINE + " \"type\" : \"array\"," + NEWLINE + " \"readOnly\" : true," + NEWLINE + " \"items\" : {" + NEWLINE + " \"type\" : \"string\"," + NEWLINE + " \"format\" : \"binary\"" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + " }" + NEWLINE + "}"); }
@Override public BinarySchema createProperty() { return new BinarySchema(); } },
return new BinarySchema();
private void declareGetResponseFormats(OpenAPI api, String path, Class<?> binding) { PathItem pi = api.getPaths().get(path); Operation get = pi.getGet(); Content content = get.getResponses().get("200").getContent(); List<String> formats = DefaultWebFeatureService30.getAvailableFormats(binding); // first remove the ones missing Set<String> missingFormats = new HashSet<>(content.keySet()); missingFormats.removeAll(formats); missingFormats.forEach(f -> content.remove(f)); // then add the ones not already declared Set<String> extraFormats = new HashSet<>(formats); extraFormats.removeAll(content.keySet()); for (String extraFormat : extraFormats) { MediaType mediaType = new MediaType(); if (extraFormat.contains("yaml") && content.get("application/json") != null) { // same schema as JSON mediaType.schema(content.get("application/json").getSchema()); } else if (extraFormat.contains("text")) { mediaType.schema(new StringSchema()); } else { mediaType.schema(new BinarySchema()); } content.addMediaType(extraFormat, mediaType); } }