Class CollectionElement

java.lang.Object
com.postman.collection.CollectionElement
Direct Known Subclasses:
BodyElement, Cookie, Event, Event.PostmanScript, Item, Property, RequestAuth, RequestBody, Response, Url

public abstract class CollectionElement extends Object
Abstract Base Class for all objects which are part of a collection
  • Constructor Details

    • CollectionElement

      public CollectionElement()
  • Method Details

    • getKey

      public abstract String getKey()
    • validate

      public boolean validate() throws ValidationException
      Validate the gson produced by this element against the PostmanSchema. Schema version is currently hardcoded to v2.1.0. Validation is provided by the NetworkNT json-schema-validator
      Returns:
      boolean true if valid, false if not. If the schema is invalid, calling getValidationMessages() will return an containing the diffs
      Throws:
      ValidationException - If an error is encountered accessing the schema or mapping the underlying JSON.
    • setParent

      public void setParent(CollectionElement parent)
      Set the parent of this element, allowing for traversal up the chain of elements
      Parameters:
      parent - The parent element
    • getParent

      public CollectionElement getParent()
      Get the parent element, or null if it is not set.
      Returns:
      CollectionElement The parent of this element
    • validate

      public boolean validate(String altSchemaJSON) throws ValidationException
      Convenience method allowing validation against a user-provided schema
      Parameters:
      altSchemaJSON - String containing the alternate schema JSON
      Returns:
      boolean true if valid, false if not. If the schema is invalid, calling getValidationMessages() will return an containing the diffs
      Throws:
      ValidationException - If there is an error in the validation process
    • getValidationMessages

      public ArrayList<com.networknt.schema.ValidationMessage> getValidationMessages()
      If an element is invalid, returns an ArrayList<ValidationMessage> containing one or more diff messages describing the differences. If the element is valid the size of the returned ArrayList will be zero.
      Returns:
      ArrayList<ValidationMessage> An ArrayList containing zero or more validatin messages.
    • toJson

      public String toJson()
      Render this element to JSON using the Gson conversion library.
      Returns:
      String The JSON rendered by Gson
    • toJson

      public String toJson(boolean escape, boolean resolveVariables)
      Render this element to JSON using the Gson conversion library. The escape and resolveVariable arguments are currently not implemented
      Parameters:
      escape - NOT IMPLEMENTED: Escaping scheme for JSON
      resolveVariables - NOT IMPLEMENTED: Whether to resolve variables to their corresponding values.
      Returns:
      String The rendered JSON
    • getUUID

      public UUID getUUID()
      Get a unique UUID for this element. UUIDs are not persisted/serialized
      Returns:
      UUID A unique UUID
    • setUUID

      public void setUUID(UUID newID)
      Set a new unique UUID for this element.
      Parameters:
      newID - A new UUID
    • getCollection

      public Collection getCollection()
      Traverse the chain of parent elements upwards until a Collection is reached, or null if this element is not part of a collection.
      Returns:
      Collection The collection at the top of the parent tree, or null.
    • isEquivalentTo

      public com.fasterxml.jackson.databind.JsonNode isEquivalentTo(CollectionElement compare) throws ValidationException
      Determine whether 2 seperate instance of a JPostman class render semantically identical JSON. If the JSON is identical, the returned JsonNode will be empty (e.g., size() == 0). If the documents are different, the JsonNode returned contains information about the differences.
      Parameters:
      compare - The CollectionElement to compare to this one.
      Returns:
      JsonNode JsonNode containing an array of diff msgs. size() will be zero if there are no validation messages.
      Throws:
      ValidationException - If there is an exception or error during the Validation process
    • getDefaultCollectionSchema

      public static String getDefaultCollectionSchema()

      Return the default schema appearing in the schema property in exported collections.

      Current: https://schema.getpostman.com/json/collection/v2.1.0/collection.json

      Returns:
      The URI for default schema used to validate schemas
    • getDefaultValidationSchema

      public static String getDefaultValidationSchema()

      Return the default schema used to validate schemas. NOTE: AS of version Version 10.8.9 this is not the same appearing in the schema property in exported collections.

      Current: https://schema.postman.com/collection/json/v2.1.0/draft-07/collection.json

      Returns:
      The URI for default schema used to validate schemas