Reusing Metadata

It is often desirable to reuse metadata definitions across multiple files, or even within different blocks in the same file. For example, if lets say you want to expose the following endpoints:

GET /Examples/Products
GET /Examples/Products/{productId}

Both of these endpoints would have very similar output. The first one would return a collection of objects while the second would return a single object. But the structure of those objects would likely be the same.  Each object would have a name, description, price, etc.  

Aptify support reference expansion in the metadata files according to the JSON.Schema specification. You can have references to objects within the same file, or to object in other files using relative URIs. Absolute URIs are not supported at this time.  When references are used the expanded definition is merged into the existing definition.  Local properties take precedence over referenced properties.  This provides a way to override properties locally so they are different from the referenced definition.  

 

Below is an example file where the output entity definitions and business logic definitions are reused within the same file, and the security metadata is pulled from a different file.  
Endpoint Metadata File with References
{
  "endpoints": {
    "ExamplesGetSingleProduct": {
      "route": {
        "httpMethod": "GET",
        "segments": {
          "examples": {
            "isLiteral": true,
            "type": "string"
          },
          "products": {
            "isLiteral": true,
            "type": "string"
          },
          "productId": {
            "isLiteral": false,
            "type": "long"
          }
        }
      },
      "outputEntityDefinition": {
        "name": "ExampleSingleProductOutput",
        "$ref": "#/exampleProductOutput"
      },
      "inputEntityDefinition": {
        "name": "ExampleGetSingleProductInput",
        "fields": {
          "productId": {
            "type": "long",
            "input": {
              "httpMethods": [
                "GET"
              ],
              "source": "path"
            }
          }
        }
      },
      "businessLogic": {
        "singleProductRetrieval": {
          "$ref": "#/productRetrievalBusinessLogic"
        }
      },
      "security": {
        "allowAnonymous": {
          "$ref": "../../Common/security.json#/allowAnonymous"
        }
      }
    },
    "ExamplesAllProducts": {
      "route": {
        "httpMethod": "GET",
        "segments": {
          "examples": {
            "isLiteral": true,
            "type": "string"
          },
          "products": {
            "isLiteral": true,
            "type": "string"
          }
        }
      },
      "outputEntityDefinition": {
        "isCollection": true,
        "name": "ExampleAllProductsOutput",
        "$ref": "#/exampleProductOutput"
      },
      "inputEntityDefinition": null,
      "businessLogic": {
        "allProductRetrieval": {
          "$ref": "#/productRetrievalBusinessLogic"
        }
      },
      "security": {
        "allowAnonymous": {
          "$ref": "../../Common/security.json#/allowAnonymous"
        }
      }
    }
  },
  "exampleProductOutput": {
    "fields": {
      "id": {
        "type": "long"
      },
      "name": {
        "type": "string"
      },
      "description": {
        "type": "string",
        "description": "A plain text description of the product."
      },
      "hasComplexPricing": {
        "type": "boolean",
        "description": "If true, this indicates you must add the product to the cart in order to get an accurate price."
      },
      "defaultPrice": {
        "type": "decimal"
      }
    }
  },
  "productRetrievalBusinessLogic": {
    "executionType": "processFlow",
    "processFlowProperties": {
      "processFlowName": "Execute Data Object",
      "processFlowParameters": {
        "DataObjectName": "spGeteBusiness6_0ProductCatalog",
        "authenticatedAttributes": "@AuthenticatedAttributes"
      }
    }
  }
}

 

 

 

 

 

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.