@Override public void toJson(JsonWriter writer) { writer.startObject(); writeName(writer); writer.propertyOptional("minValue", minValue) .propertyOptional("maxValue", maxValue) .propertyOptional("increment",increment) .propertyOptional("start",start) .propertyOptional("cache",cache) .propertyOptional("cycle",cycle); writer.endObject(); } }
protected void writeName(JsonWriter writer) { writer.propertyOptional("catalog", catalog) .propertyOptional("schema", schema) .property("name", name); if(quoted) { writer.property("quoted", true); } } }
@Override public void toJson(JsonWriter w) { w.startObject() .propertyOptional("status", status) .propertyOptional("code", code) .property("error", Strings.isEmpty(error) ? "error" : error) .property("message", message) .propertyOptional("details", details) .endObject(); }
@Override public void toJson(JsonWriter writer) { writer.startObject(); writeName(writer); writer.property("type", type); writer.propertyOptional("comment", comment) .propertyOptional("primaryKeyName", primaryKey == null ? null : primaryKey.getName()); writer.propertyJsonable("columns",columns); if(foreignKeys.length > 0){ writer.propertyJsonable("foreignKeys",foreignKeys); } if(indexes.length > 0){ writer.propertyJsonable("indexes",indexes); } writer.endObject(); }
protected void writeSimpleParameterType(WriteContext context, ApiMetadata m, JsonWriter w, MApiParameterBase p, MSimpleType st) { if(p.isFile()) { w.property(TYPE, FILE); }else{ SwaggerType type = writeSimpleType(context, m, w, st); //format if(null != type && null == type.format()) { w.propertyOptional(FORMAT, p.getFormat()); } } w.propertyOptional(DEFAULT, p.getDefaultValue()); MApiValidation v = p.getValidation(); if(null != v) { w.propertyOptional(PATTERN, v.getPattern()); w.propertyOptional(MAX_LENGTH, v.getMaxLength()); w.propertyOptional(MIN_LENGTH, v.getMinLength()); w.propertyOptional(ENUM, v.getEnumValues()); if(null != v.getMaximum()) { w.property(MAXIMUM, v.getMaximum()); w.property(EXCLUSIVE_MAXIMUM, v.isExclusiveMaximum()); } if(null != v.getMinimum()) { w.property(MINIMUM, v.getMinimum()); w.property(EXCLUSIVE_MINIMUM, v.isExclusiveMinimum()); } } if(null == v || null == v.getEnumValues()) { w.propertyOptional(ENUM, p.getEnumValues()); } }
@Override public void toJson(JsonWriter w) { //{ catalog : '', name : '' w.startObject() .propertyOptional("catalog", catalog) .property("name", name); //tables : [ {},{} ] w.propertyJsonable("tables",tables); if(sequences.length > 0){ w.propertyJsonable("sequences",sequences); } w.endObject(); } }
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(); } }
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(); }
protected void writeError(Request request, Response response, int status, String code, String desc) { response.setStatus(status); response.setContentType(ContentTypes.APPLICATION_JSON_UTF8); JsonWriter json = JSON.createWriter(response.getWriter()); json.startObject() .property("error", code) .propertyOptional("error_description", desc) .endObject(); }
protected void writeTags(WriteContext context, ApiMetadata m, JsonWriter w) { w.array(m.getTags(), (tag) -> { w.startObject(); w.property(NAME, tag.getName()); w.propertyOptional(DESCRIPTION, tag.descOrSummaryOrTitle()); w.endObject(); }); }
protected void writeError(Request request, Response response, int status, String code, String desc) { response.setStatus(status); response.setContentType(ContentTypes.APPLICATION_JSON_UTF8); JsonWriter json = JSON.createWriter(response.getWriter()); json.startObject() .property("error", code) .propertyOptional("error_description", desc) .endObject(); }
w.startObject(); w.propertyOptional(TITLE, p.getTitle()); w.property(DESCRIPTION, Strings.nullToEmpty(Strings.firstNotEmpty(p.getDescription(),p.getSummary()))); writeParameterType(context, m, w, p); w.propertyOptional(X_SELECTABLE, p.getSelectable()); w.propertyOptional(X_AGGREGATABLE, p.getAggregatable()); w.propertyOptional(X_GROUPABLE, p.getGroupable()); w.propertyOptional(X_CREATABLE, p.getCreatable()); w.propertyOptional(X_UPDATABLE, p.getUpdatable()); w.propertyOptional(X_SORTABLE, p.getSortable()); w.propertyOptional(X_FILTERABLE, p.getFilterable()); w.propertyOptional(X_EXPANDABLE, p.getExpandable());
writer.propertyOptional("defaultValue", defaultValue) .propertyOptional("comment",comment);
@Override public void writeTokenInfo(Request request, Response response, AuthzAccessToken at) { response.setContentType(ContentTypes.APPLICATION_JSON_UTF8); JsonWriter w = response.getJsonWriter(); w.startObject() .property("user_id", at.getUserId()) .property("username", at.getUsername()) .property("expires_in", at.getExpiresInFormNow()) .propertyOptional("scope", at.getScope()); if(at.isAuthenticated()){ w.property("client_id", at.getClientId()); } if(at.hasExtendedParameters()) { for(Map.Entry<String, Object> entry : at.getExtendedParameters().entrySet()) { w.property(entry.getKey(), entry.getValue()); } } w.endObject(); } }
w.propertyOptional(SUMMARY, m.getSummary()) .property(DESCRIPTION, nullToEmpty(m.getDescription())) .propertyOptional(TERMS_OF_SERVICE, m.getTermsOfService()) .propertyOptional(CONTACT, m.getConcat()); w.propertyOptional(VERSION, m.getVersion()); w.endObject(); }); w.propertyOptional(HOST, getHost(sc, m)) .propertyOptional(BASE_PATH, sc.getContextPath() + Strings.nullToEmpty(m.getBasePath())) .propertyOptional(SCHEMES, m.getProtocols()) .propertyOptional(CONSUMES, m.getConsumes()) .propertyOptional(PRODUCES, m.getProduces());
@Override public void writeTokenInfo(Request request, Response response, AuthzAccessToken at) { response.setContentType(ContentTypes.APPLICATION_JSON_UTF8); JsonWriter w = response.getJsonWriter(); w.startObject() .property("user_id", at.getUserId()) .property("username", at.getUsername()) .property("expires_in", at.getExpiresInFormNow()) .propertyOptional("scope", at.getScope()); if(at.isAuthenticated()){ w.property("client_id", at.getClientId()); } if(at.hasExtendedParameters()) { for(Map.Entry<String, Object> entry : at.getExtendedParameters().entrySet()) { w.property(entry.getKey(), entry.getValue()); } } w.endObject(); } }
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()) .propertyOptional("error_description", error.getErrorDescription()) .endObject(); }
protected void writeModelWithinObject(WriteContext context, ApiMetadata m, JsonWriter w, MApiModel model) { if(!model.hasBaseModel()) { w.property(TYPE, OBJECT); } if(model.isEntity()) { w.property(X_ENTITY, true); } writeExtension(w, model.getExtension()); w.propertyOptional(TITLE, model.getTitle()); w.propertyOptional(SUMMARY, model.getSummary()); w.propertyOptional(DESCRIPTION, model.getDescription()); if(!model.hasBaseModel()) { writeModelProperties(context, m, w, model); }else{ w.property(ALL_OF, () -> { w.startArray(); //item1 : the base model. w.startObject() .property(REF, ref(model.getBaseName())) .endObject(); w.separator(); //item2 : self w.startObject() .property(TYPE, OBJECT); writeModelProperties(context, m, w, model); w.endObject(); w.endArray(); }); } }
protected void writeParameter(WriteContext context, ApiMetadata m, JsonWriter w, MApiParameter p) { w.startObject(); w.property(NAME, p.getName()) .propertyOptional(SUMMARY, p.getSummary()) .property(DESCRIPTION, nullToEmpty(Strings.firstNotEmpty(p.getDescription(),p.getSummary(), p.getTitle()))) .property(IN, SwaggerMappings.in(p.getLocation())); w.propertyOptional(REQUIRED, p.getRequired()); writeExtension(w, p.getExtension()); try{ if(Location.BODY == p.getLocation()) { w.property(SCHEMA, () -> { w.startObject(); writeParameterType(context, m, w, p); w.endObject(); }); }else{ writeParameterType(context, m, w, p); } }catch(RuntimeException e) { throw e; } w.endObject(); }
w.propertyOptional(TAGS, o.getTags()); w.propertyOptional(SUMMARY, o.getSummary()); w.property(DESCRIPTION, nullToEmpty(o.getDescription())); w.propertyOptional(OPERATION_ID, o.getId());