Package com.postman.collection
Class CollectionElement
java.lang.Object
com.postman.collection.CollectionElement
- Direct Known Subclasses:
BodyElement
,Cookie
,Event
,Event.PostmanScript
,Item
,Property
,RequestAuth
,RequestBody
,Response
,Url
Abstract Base Class for all objects which are part of a collection
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionTraverse the chain of parent elements upwards until a Collection is reached, or null if this element is not part of a collection.static String
Return the default schema appearing in theschema
property in exported collections.static String
Return the default schema used to validate schemas.abstract String
getKey()
Get the parent element, or null if it is not set.getUUID()
Get a unique UUID for this element.ArrayList<com.networknt.schema.ValidationMessage>
If an element is invalid, returns an ArrayList<ValidationMessage> containing one or more diff messages describing the differences.com.fasterxml.jackson.databind.JsonNode
isEquivalentTo
(CollectionElement compare) Determine whether 2 seperate instance of a JPostman class render semantically identical JSON.void
setParent
(CollectionElement parent) Set the parent of this element, allowing for traversal up the chain of elementsvoid
Set a new unique UUID for this element.toJson()
Render this element to JSON using the Gson conversion library.toJson
(boolean escape, boolean resolveVariables) Render this element to JSON using the Gson conversion library.boolean
validate()
Validate the gson produced by this element against the PostmanSchema.boolean
Convenience method allowing validation against a user-provided schema
-
Constructor Details
-
CollectionElement
public CollectionElement()
-
-
Method Details
-
getKey
-
validate
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, callinggetValidationMessages()
will return an containing the diffs - Throws:
ValidationException
- If an error is encountered accessing the schema or mapping the underlying JSON.
-
setParent
Set the parent of this element, allowing for traversal up the chain of elements- Parameters:
parent
- The parent element
-
getParent
Get the parent element, or null if it is not set.- Returns:
- CollectionElement The parent of this element
-
validate
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, callinggetValidationMessages()
will return an containing the diffs - Throws:
ValidationException
- If there is an error in the validation process
-
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
Render this element to JSON using the Gson conversion library.- Returns:
- String The JSON rendered by Gson
-
toJson
Render this element to JSON using the Gson conversion library. Theescape
andresolveVariable
arguments are currently not implemented- Parameters:
escape
- NOT IMPLEMENTED: Escaping scheme for JSONresolveVariables
- NOT IMPLEMENTED: Whether to resolve variables to their corresponding values.- Returns:
- String The rendered JSON
-
getUUID
Get a unique UUID for this element. UUIDs are not persisted/serialized- Returns:
- UUID A unique UUID
-
setUUID
Set a new unique UUID for this element.- Parameters:
newID
- A new UUID
-
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
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
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
-