private Response lookupResponse(Entity entity, Lookup lookup, Locale locale) { if (lookup.isSingleObjectReturn()) { return new ResponseWithSchema( msg(locale, RESPONSE_SINGLE_DESC_KEY, entity.getName()), definitionWithMetadataPath(entity.getClassName())); } else { return new ResponseWithSchema( msg(locale, RESPONSE_LIST_DESC_KEY, entity.getName()), definitionWithMetadataPath(entity.getClassName())); } }
private void addLookupEndpoints(SwaggerModel swaggerModel, Entity entity, Locale locale) { for (Lookup lookup : entity.getLookupsExposedByRest()) { String lookupUrl = ClassName.restLookupUrl( entity.getName(), entity.getModule(), entity.getNamespace(), lookup.getMethodName()); swaggerModel.addPathEntry(lookupUrl, HttpMethod.GET, lookupPathEntry(entity, lookup, locale)); } }
private PathEntry deletePathEntry(Entity entity, Locale locale) { final PathEntry pathEntry = new PathEntry(); final String entityName = entity.getName(); pathEntry.setDescription(msg(locale, DELETE_DESC_KEY, entityName)); pathEntry.setOperationId(msg(locale, DELETE_ID_KEY, entityName)); pathEntry.setProduces(json()); pathEntry.addTag(entity.getClassName()); pathEntry.addParameter(deleteIdPathParameter(locale)); addCommonResponses(pathEntry, locale); pathEntry.addResponse(HttpStatus.OK, deleteResponse(entity, locale)); return pathEntry; }
private PathEntry putPathEntry(Entity entity, Locale locale) { final PathEntry pathEntry = new PathEntry(); final String entityName = entity.getName(); pathEntry.setDescription(msg(locale, UPDATE_DESC_KEY, entityName)); pathEntry.setOperationId(msg(locale, UPDATE_ID_KEY, entityName)); pathEntry.setProduces(json()); pathEntry.addTag(entity.getClassName()); pathEntry.addParameter(updateEntityParameter(entity, locale)); addCommonResponses(pathEntry, locale); pathEntry.addResponse(HttpStatus.OK, updatedItemResponse(entity, locale)); pathEntry.addResponse(HttpStatus.NOT_FOUND, notFoundResponse(entity, locale)); return pathEntry; }
private PathEntry readPathEntry(Entity entity, Locale locale) { final PathEntry pathEntry = new PathEntry(); final String entityName = entity.getName(); pathEntry.setDescription(msg(locale, READ_DESC_KEY, entityName)); pathEntry.setOperationId(msg(locale, READ_ID_KEY, entityName)); pathEntry.setProduces(json()); pathEntry.addTag(entity.getClassName()); pathEntry.setParameters(queryParamsParameters(entity.getFieldsExposedByRest(), locale)); pathEntry.addParameter(idQueryParameter(locale)); pathEntry.addResponse(HttpStatus.OK, readResponse(entity, locale)); addCommonResponses(pathEntry, locale); return pathEntry; }
private void addCrudEndpoints(SwaggerModel swaggerModel, Entity entity, Locale locale) { final String entityPath = ClassName.restUrl(entity.getName(), entity.getModule(), entity.getNamespace()); RestOptions restOptions = restOptionsOrDefault(entity); if (restOptions.isAllowRead()) { // retrieveAll and retrieveById swaggerModel.addPathEntry(entityPath, HttpMethod.GET, readPathEntry(entity, locale)); } if (restOptions.isAllowCreate()) { // post new item swaggerModel.addPathEntry(entityPath, HttpMethod.POST, postPathEntry(entity, locale)); } if (restOptions.isAllowUpdate()) { // update an existing item swaggerModel.addPathEntry(entityPath, HttpMethod.PUT, putPathEntry(entity, locale)); } if (restOptions.isAllowDelete()) { // delete an item swaggerModel.addPathEntry( entityPath + ID_PATHVAR, HttpMethod.DELETE, deletePathEntry(entity, locale)); } }
private Response notFoundResponse(Entity entity, Locale locale) { return new Response(msg(locale, RESPONSE_NOT_FOUND_KEY, entity.getName())); }
private Response deleteResponse(Entity entity, Locale locale) { return new Response(msg(locale, RESPONSE_DELETE_DESC_KEY, entity.getName())); }
private Response updatedItemResponse(Entity entity, Locale locale) { return new ResponseWithSchema( msg(locale, RESPONSE_UPDATED_DESC_KEY, entity.getName()), definitionPath(entity.getClassName())); }
private Response readResponse(Entity entity, Locale locale) { return new ResponseWithSchema( msg(locale, RESPONSE_LIST_DESC_KEY, entity.getName()), definitionWithMetadataPath(entity.getClassName())); }
private Response lookup404Response(Entity entity, Locale locale) { return new Response(msg(locale, RESPONSE_LOOKUP_NOT_FOUND_KEY, entity.getName())); }
private Parameter updateEntityParameter(Entity entity, Locale locale) { return bodyParameter( entity.getName(), msg(locale, UPDATE_BODY_DESC_KEY, entity.getName()), definitionUpdatePath(entity.getClassName())); }
private Parameter newEntityParameter(Entity entity, Locale locale) { return bodyParameter( entity.getName(), msg(locale, CREATE_BODY_DESC_KEY, entity.getName()), definitionNewPath(entity.getClassName())); }