Example #1
0
  void appendCollectionTo(
      final ObjectSpecification objectSpec, final OneToManyAssociation collection) {

    final String objectType = objectTypeFor(objectSpec);
    final String collectionId = collection.getId();

    final Path path = new Path();
    swagger.path(
        String.format("/objects/%s/{objectId}/collections/%s", objectType, collectionId), path);

    final String tag = tagFor(objectType, null);
    final Operation collectionOperation =
        new Operation()
            .tag(tag)
            .description(Util.roSpec("17.1") + ": resource of " + objectType + "#" + collectionId)
            .parameter(new PathParameter().name("objectId").type("string"))
            .produces("application/json;profile=urn:org.apache.isis/v1")
            .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
            .produces(
                "application/json;profile=urn:org.restfulobjects:repr-types/object-collection");

    path.get(collectionOperation);
    collectionOperation.response(
        200,
        new Response()
            .description(
                objectType
                    + "#"
                    + collectionId
                    + " , if Accept: application/json;profile=urn:org.apache.isis/v1")
            .schema(modelFor(collection)));
  }
Example #2
0
  void appendServicePath(final ObjectSpecification objectSpec) {

    final String serviceId = serviceIdFor(objectSpec);

    final Path path = new Path();
    swagger.path(String.format("/services/%s", serviceId), path);

    final String serviceModelDefinition = serviceId + "Repr";

    final String tag = tagFor(serviceId, "> services");
    path.get(
        new Operation()
            .tag(tag)
            .description(Util.roSpec("15.1"))
            .produces("application/json")
            .produces("application/json;profile=urn:org.restfulobjects:repr-types/object")
            .response(
                200,
                newResponse(Caching.TRANSACTIONAL)
                    .description("OK")
                    .schema(newRefProperty(serviceModelDefinition))));

    final ModelImpl model =
        newModel(Util.roSpec("15.1.2") + ": representation of " + serviceId)
            .property("title", stringProperty())
            .property("serviceId", stringProperty()._default(serviceId))
            .property("members", new ObjectProperty());

    addDefinition(serviceModelDefinition, model);
  }
Example #3
0
  ModelImpl appendObjectPathAndModelDefinitions(final ObjectSpecification objectSpec) {

    final String objectType = objectTypeFor(objectSpec);

    final Path path = new Path();
    swagger.path(String.format("/objects/%s/{objectId}", objectType), path);

    final String tag = tagFor(objectType, null);
    final Operation operation = new Operation();
    path.get(operation);
    operation
        .tag(tag)
        .description(Util.roSpec("14.1"))
        .parameter(new PathParameter().name("objectId").type("string"))
        .produces("application/json;profile=urn:org.apache.isis/v1")
        .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
        .produces("application/json;profile=urn:org.restfulobjects:repr-types/object");

    // per https://github.com/swagger-api/swagger-spec/issues/146, swagger 2.0 doesn't support
    // multiple
    // modelled representations per path and response code;
    // in particular cannot associate representation/model with Accept header ('produces(...)
    // method)
    final String restfulObjectsModelDefinition = objectType + "RestfulObjectsRepr";
    if (false) {
      operation.response(
          200,
          newResponse(Caching.TRANSACTIONAL)
              .description(
                  "if Accept: application/json;profile=urn:org.restfulobjects:repr-types/object")
              .schema(newRefProperty(restfulObjectsModelDefinition)));

      final ModelImpl roSpecModel =
          newModel(Util.roSpec("14.4") + ": representation of " + objectType)
              .property("title", stringProperty())
              .property("domainType", stringProperty()._default(objectType))
              .property("instanceId", stringProperty())
              .property("members", new ObjectProperty());
      swagger.addDefinition(restfulObjectsModelDefinition, roSpecModel);
    }

    final String isisModelDefinition = objectType + "Repr";
    operation.response(
        200,
        newResponse(Caching.TRANSACTIONAL)
            .description(
                objectType + " , if Accept: application/json;profile=urn:org.apache.isis/v1")
            .schema(newRefProperty(isisModelDefinition)));

    final ModelImpl isisModel = new ModelImpl();
    addDefinition(isisModelDefinition, isisModel);

    // return so can be appended to
    return isisModel;
  }
Example #4
0
  void appendObjectActionInvokePath(
      final ObjectSpecification objectSpec, final ObjectAction objectAction) {

    final String objectType = objectTypeFor(objectSpec);
    final String actionId = objectAction.getId();

    final List<ObjectActionParameter> parameters = objectAction.getParameters();
    final Path path = new Path();
    swagger.path(
        String.format("/objects/%s/{objectId}/actions/%s/invoke", objectType, actionId), path);

    final String tag = tagFor(objectType, null);
    final Operation invokeOperation =
        new Operation()
            .tag(tag)
            .description(
                Util.roSpec("19.1") + ": (invoke) resource of " + objectType + "#" + actionId)
            .parameter(new PathParameter().name("objectId").type("string"))
            .produces("application/json;profile=urn:org.apache.isis/v1")
            .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
            .produces("application/json;profile=urn:org.restfulobjects:repr-types/action-result");

    final ActionSemantics.Of semantics = objectAction.getSemantics();
    if (semantics.isSafeInNature()) {
      path.get(invokeOperation);

      for (final ObjectActionParameter parameter : parameters) {
        invokeOperation.parameter(
            new QueryParameter()
                .name(parameter.getId())
                .description(
                    Util.roSpec("2.9.1")
                        + (!Strings.isNullOrEmpty(parameter.getDescription())
                            ? (": " + parameter.getDescription())
                            : ""))
                .required(false)
                .type("string"));
      }
      if (!parameters.isEmpty()) {
        invokeOperation.parameter(
            new QueryParameter()
                .name("x-isis-querystring")
                .description(
                    Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string")
                .required(false)
                .type("string"));
      }

    } else {
      if (semantics.isIdempotentInNature()) {
        path.put(invokeOperation);
      } else {
        path.post(invokeOperation);
      }

      final ModelImpl bodyParam = new ModelImpl().type("object");
      for (final ObjectActionParameter parameter : parameters) {

        final ObjectSpecification specification = parameter.getSpecification();
        final Property valueProperty =
            specification.isValue() ? modelFor(specification) : refToLinkModel();
        bodyParam.property(
            parameter.getId(), new ObjectProperty().property("value", valueProperty));
      }

      invokeOperation
          .consumes("application/json")
          .parameter(new BodyParameter().name("body").schema(bodyParam));
    }

    invokeOperation.response(
        200,
        new Response()
            .description(objectType + "#" + actionId)
            .schema(actionReturnTypeFor(objectAction)));
  }
Example #5
0
  void appendServiceActionInvokePath(
      final ObjectSpecification serviceSpec, final ObjectAction serviceAction) {

    final String serviceId = serviceIdFor(serviceSpec);
    final String actionId = serviceAction.getId();

    final List<ObjectActionParameter> parameters = serviceAction.getParameters();
    final Path path = new Path();
    swagger.path(String.format("/services/%s/actions/%s/invoke", serviceId, actionId), path);

    final String tag = tagFor(serviceId, "> services");
    final Operation invokeOperation =
        new Operation()
            .tag(tag)
            .description(
                Util.roSpec("19.1") + ": (invoke) resource of " + serviceId + "#" + actionId)
            .produces("application/json;profile=urn:org.apache.isis/v1")
            .produces("application/json;profile=urn:org.apache.isis/v1;suppress=true")
            .produces("application/json;profile=urn:org.restfulobjects:repr-types/action-result");

    final ActionSemantics.Of semantics = serviceAction.getSemantics();
    if (semantics.isSafeInNature()) {
      path.get(invokeOperation);

      for (final ObjectActionParameter parameter : parameters) {
        invokeOperation.parameter(
            new QueryParameter()
                .name(parameter.getId())
                .description(
                    Util.roSpec("2.9.1")
                        + (!Strings.isNullOrEmpty(parameter.getDescription())
                            ? (": " + parameter.getDescription())
                            : ""))
                .required(false)
                .type("string"));
      }
      if (!parameters.isEmpty()) {
        invokeOperation.parameter(
            new QueryParameter()
                .name("x-isis-querystring")
                .description(
                    Util.roSpec("2.10") + ": all (formal) arguments as base64 encoded string")
                .required(false)
                .type("string"));
      }

    } else {
      if (semantics.isIdempotentInNature()) {
        path.put(invokeOperation);
      } else {
        path.post(invokeOperation);
      }

      final ModelImpl bodyParam = new ModelImpl().type("object");
      for (final ObjectActionParameter parameter : parameters) {

        final Property valueProperty;
        // TODO: need to switch on parameter's type and create appropriate impl of valueProperty
        // if(parameter.getSpecification().isValue()) ...
        valueProperty = stringProperty();

        bodyParam.property(
            parameter.getId(), new ObjectProperty().property("value", valueProperty));
      }

      invokeOperation
          .consumes("application/json")
          .parameter(new BodyParameter().name("body").schema(bodyParam));
    }

    invokeOperation.response(
        200,
        new Response()
            .description(
                serviceId
                    + "#"
                    + actionId
                    + " , if Accept: application/json;profile=urn:org.apache.isis/v1")
            .schema(actionReturnTypeFor(serviceAction)));
  }