/** * Writes a property optional. That means it will not writes the property if the value is null. */ default JsonWriter propertyOptional(String key, Float v) { if(null != v){ property(key, v); } return this; }
protected void error(Response response, int status, String error, String desc){ response.setStatus(status); response.setContentType(ContentTypes.APPLICATION_JSON_UTF8); response.getJsonWriter() .startObject() .property("error", error) .propertyOptional("error_description", desc) .endObject(); } }
/** * Writes a property optional. That means it will not writes the property if the array is null or empty. */ default JsonWriter propertyOptional(String key, Number[] a) { return null == a || a.length == 0 ? this : property(key, a); }
public static void response(Response response, OAuth2Error error) { response.setStatus(error.getStatus()); response.setContentType(ContentTypes.APPLICATION_JSON_UTF8); JsonWriter w = JSON.createWriter(response.getWriter()); w.startObject() .property("error", error.getError()) .property("error_code", error.getErrorCode()) .propertyOptional("referral", error.getReferral()) .propertyOptional("error_description", error.getErrorDescription()) .endObject(); }
/** * Writes a property optional. That means it will not writes the property if the value is null. */ default JsonWriter propertyOptional(String key, Double v) { if(null != v){ property(key, v); } return this; }
/** * Writes a property optional. That means it will not writes the property if the array is null or empty. */ default JsonWriter propertyOptional(String key, int[] a) { return null == a || a.length == 0 ? this : property(key, a); }
/** * Writes a property optional. That means it will not writes the property if the array is null or empty. */ default JsonWriter propertyOptional(String key, long[] a) { return null == a || a.length == 0 ? this : property(key, a); }
protected SwaggerType writeSimpleType(WriteContext context, ApiMetadata m, JsonWriter w, MSimpleType st) { SwaggerType type = convertSimpleType(st); if(null == type) { throw new IllegalStateException("Unsupported type '" + st + "' in swagger"); } w.property(TYPE, type.type()); if(null != type.format()) { w.property(FORMAT, type.format()); } return type; } }
protected void writeOAuth2Scopes(WriteContext context, ApiMetadata m, JsonWriter w, MOAuth2ApiSecurityDef d, MApiPermission[] scopes) { w.property(SCOPES, () -> { w.startObject(); if(null != scopes) { for (MApiPermission scope : scopes) { w.property(scope.getValue(), Strings.trim(scope.getDescription())); } } w.endObject(); }); }
protected void writeSecurity(WriteContext context, ApiMetadata m, JsonWriter w, MApiSecurityReq sc){ w.startObject(); w.property(sc.getName(),sc.getScopes()); w.endObject(); }
@Override public void toJson(JsonWriter writer) { writer.startObject(); writer.property("name", name) .key("columns").array(columnNames); writer.endObject(); }
protected void writePath(WriteContext context, ApiMetadata m, JsonWriter w, MApiPath p) { w.startObject(); for(MApiOperation o : p.getOperations()) { if (checkProfile(o)) continue; w.property(o.getMethod().name().toLowerCase(), () -> { writeOperation(context, m, w, p, o); }); } w.endObject(); }