示例#1
0
 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()));
   }
 }
示例#2
0
 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));
   }
 }
示例#3
0
  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;
  }
示例#4
0
  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;
  }
示例#5
0
  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;
  }
示例#6
0
  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));
    }
  }
示例#7
0
 private Response notFoundResponse(Entity entity, Locale locale) {
   return new Response(msg(locale, RESPONSE_NOT_FOUND_KEY, entity.getName()));
 }
示例#8
0
 private Response deleteResponse(Entity entity, Locale locale) {
   return new Response(msg(locale, RESPONSE_DELETE_DESC_KEY, entity.getName()));
 }
示例#9
0
 private Response updatedItemResponse(Entity entity, Locale locale) {
   return new ResponseWithSchema(
       msg(locale, RESPONSE_UPDATED_DESC_KEY, entity.getName()),
       definitionPath(entity.getClassName()));
 }
示例#10
0
 private Response readResponse(Entity entity, Locale locale) {
   return new ResponseWithSchema(
       msg(locale, RESPONSE_LIST_DESC_KEY, entity.getName()),
       definitionWithMetadataPath(entity.getClassName()));
 }
示例#11
0
 private Response lookup404Response(Entity entity, Locale locale) {
   return new Response(msg(locale, RESPONSE_LOOKUP_NOT_FOUND_KEY, entity.getName()));
 }
示例#12
0
 private Parameter updateEntityParameter(Entity entity, Locale locale) {
   return bodyParameter(
       entity.getName(),
       msg(locale, UPDATE_BODY_DESC_KEY, entity.getName()),
       definitionUpdatePath(entity.getClassName()));
 }
示例#13
0
 private Parameter newEntityParameter(Entity entity, Locale locale) {
   return bodyParameter(
       entity.getName(),
       msg(locale, CREATE_BODY_DESC_KEY, entity.getName()),
       definitionNewPath(entity.getClassName()));
 }