openapi: 3.0.0
servers:
    - description: Controller URL
      url: https://localhost:8080/controller/alerting/rest/v1/applications/{application-id}/
info:
    description: |
        Policy apis (Objects/Entities corresponding to EUM applications not supported for now).
        [Details at Appdynamics documentation](https://docs.appdynamics.com/display/PRO45/AppDynamics+APIs)
    version: "1.0.0"
    title: Appdynamics Policy Operations
    termsOfService: 'https://www.appdynamics.com/terms/'
    license:
        name: Apache 2.0
        url: 'http://www.apache.org/licenses/LICENSE-2.0.html'

tags:
    - name: policies
      description: Manage application policies.
      externalDocs:
          description: Find out more
          url: 'https://www.appdynamics.com'

paths:
    '/policies':
        parameters:
            - $ref: '#/components/parameters/applicationId'
        post:
            description: |
                Create a new policy from the provided json payload.
            tags:
                - policies
            operationId: createPolicy
            responses:
                '201':
                    description: Created successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Policy'
                    links:
                        CreatedUserid:
                            operationId: getPolicy
                            parameters:
                                health-rule-id: '$response.body#/id'
                            description:
                                The `id` value returned in the response can be used as `policy-id` parameter in `GET /policies/{policy-id}`
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '409':
                    $ref: '#/components/responses/Conflict'
            requestBody:
                $ref: '#/components/requestBodies/Policy'

        get:
            tags:
                - policies
            description: |
                Returns list of all Policies that belong to the application. Only Policy names, ids and enable flag are returned. For getting complete details for a Policy, see `GET /policies/{policy-id}`
            operationId: getPolicySummaries
            responses:
                '200':
                    description: Fetched successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/PolicySummaryArray'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/NotFound'
    '/policies/{policy-id}':
        parameters:
            - $ref: '#/components/parameters/applicationId'
            - $ref: '#/components/parameters/policyId'
        get:
            tags:
                - policies
            summary: "Returns json representation of policy for the given policy id."
            description: |
                Returns json representation of policy for the given policy id. Valid existing policy id should be provided.
            operationId: getPolicy
            responses:
                '200':
                    description: Fetched successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Policy'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/NotFound'
        put:
            tags:
                - policies
            summary: "Update an existing policy with the given policy id"
            description: |
                Complete json payload for the policy should be provided as input. User can first make  `GET /policies/{policy-id}` to get he json payload and update required fields and send modified payload as part of this `PUT` request.
            operationId: updatePolicy
            responses:
                '200':
                    description: Updated successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Policy'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/NotFound'
            requestBody:
                $ref: '#/components/requestBodies/Policy'
        delete:
            tags:
                - policies
            summary: "Delete an existing policy with the given policy id."
            description: Valid existing policy id should be provided.
            operationId: deletePolicy
            responses:
                '204':
                    description: Deleted successfully
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/NotFound'
    '/policies/{policy-id}/configuration':
        parameters:
            - $ref: '#/components/parameters/applicationId'
            - $ref: '#/components/parameters/policyId'
        put:
            tags:
                - policies
            summary: "Update one or more specific configuration / property of a policy."
            description: |
                The below configuration can be provided:<br>
                  Enable / Disable a policy.</pre>
                Valid existing policy id should be provided.
            operationId: updatePolicyConfiguration
            responses:
                '200':
                    description: Updated successfully
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Policy'
                '400':
                    $ref: '#/components/responses/BadRequest'
                '401':
                    $ref: '#/components/responses/Unauthorized'
                '403':
                    $ref: '#/components/responses/Forbidden'
                '404':
                    $ref: '#/components/responses/NotFound'
            requestBody:
                $ref: '#/components/requestBodies/PolicyConfiguration'
externalDocs:
    description: Find out more about Swagger
    url: 'http://swagger.io'
components:
    schemas:
        Policy:
            description: 'Policy definition'
            type: object
            properties:
                id:
                    description: 'User does not need to provide this while creating a new policy. Will be generated by system and returned in response.'
                    type: integer
                    format: int64
                    readOnly: true
                name:
                    description: Name of the policy.
                    type: string
                    minLength: 1
                    example: "My new policy"
                enabled:
                    type: boolean
                    default: true
                    example: true
                executeActionsInBatch:
                    type: boolean
                    default: true
                    example: true
                actions:
                    type: array
                    items:
                        $ref: '#/components/schemas/Action'
                    minItems: 1
                events:
                    $ref: '#/components/schemas/Events'
                selectedEntities:
                    $ref: '#/components/schemas/SelectedEntities'

            required:
                - name
                - executeActionsInBatch
                - actions
                - events

        SelectedEntities:
            description: 'Selected Entity definition (Entities corresponding to EUM applications not supported for now)'
            type: object
            properties:
                selectedEntityType:
                    $ref: '#/components/schemas/SelectedEntityType'
            discriminator:
                propertyName: selectedEntityType
                mapping:
                    ANY_ENTITY: '#/components/schemas/AnyEntity'
                    SPECIFIC_ENTITIES: '#/components/schemas/SpecificEntities'
            required:
                - selectedEntityType

        SpecificEntities:
            description: 'selectedEntityType: SPECIFIC_ENTITIES'
            allOf:
                - $ref: '#/components/schemas/SelectedEntities'
                - type: object
                  properties:
                      entities:
                          type: array
                          items:
                              $ref: '#/components/schemas/Entity'
                          minItems: 1
        Entity:
            type: object
            properties:
                entityType:
                    $ref: '#/components/schemas/EntityType'
            discriminator:
                propertyName: entityType
                mapping:
                    BUSINESS_TRANSACTION: '#/components/schemas/BusinessTransaction'
                    TIER_NODE: '#/components/schemas/SelectedTierOrNodeEntities'
                    ERRORS: '#/components/schemas/Errors'
                    SERVICE_ENDPOINTS: '#/components/schemas/ServiceEndpoints'
                    INFORMATION_POINTS: '#/components/schemas/InformationPoints'
                    DATABASES_IN_APPLICATION: '#/components/schemas/DatabasesInApplication'
                    SERVERS_IN_APPLICATION: '#/components/schemas/ServersInApplication'
            required:
                - entityType


        AnyEntity:
            description: 'selectedEntityType: ANY_ENTITY'
            allOf:
                - $ref: '#/components/schemas/SelectedEntities'

        BusinessTransaction:
            description: "selectedEntityType: BUSINESS_TRANSACTION"
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      selectedBusinessTransactions:
                          $ref: '#/components/schemas/SelectedBusinessTransactions'
                  required:
                      - selectedBusinessTransactions

        SelectedBusinessTransactions:
            type: object
            properties:
                businessTransactionScope:
                    $ref: '#/components/schemas/BusinessTransactionScopeEnum'
            required:
                - businessTransactionScope
            discriminator:
                propertyName: businessTransactionScope
                mapping:
                    ALL_BUSINESS_TRANSACTIONS: '#/components/schemas/AllBusinessTransactions'
                    SPECIFIC_BUSINESS_TRANSACTIONS: '#/components/schemas/SpecificBusinessTransactions'
                    BUSINESS_TRANSACTIONS_IN_SPECIFIC_TIERS: '#/components/schemas/BusinessTransactionsInSpecificTiers'
                    BUSINESS_TRANSACTIONS_MATCHING_PATTERN: '#/components/schemas/BusinessTransactionsMatchingPattern'

        AllBusinessTransactions:
            description: "businessTransactionScope: ALL_BUSINESS_TRANSACTIONS"
            allOf:
                - $ref: '#/components/schemas/SelectedBusinessTransactions'
                - type: object

        SpecificBusinessTransactions:
            description: "businessTransactionScope: SPECIFIC_BUSINESS_TRANSACTIONS"
            allOf:
                - $ref: '#/components/schemas/SelectedBusinessTransactions'
                - type: object
                  properties:
                      businessTransactions:
                          type: array
                          items:
                              type: string
                              example: "CheckOutBT"
                          minItems: 1
                          example: ["LoginBT", "reportsBT"]
                  required:
                      - businessTransactions

        BusinessTransactionsInSpecificTiers:
            description: "businessTransactionScope: BUSINESS_TRANSACTIONS_IN_SPECIFIC_TIERS"
            allOf:
                - $ref: '#/components/schemas/SelectedBusinessTransactions'
                - type: object
                  properties:
                      specificTiers:
                          type: array
                          items:
                              type: string
                          minItems: 1
                  required:
                      - specificTiers

        BusinessTransactionsMatchingPattern:
            description: "businessTransactionScope: BUSINESS_TRANSACTIONS_MATCHING_PATTERN"
            allOf:
                - $ref: '#/components/schemas/SelectedBusinessTransactions'
                - type: object
                  properties:
                      patternMatcher:
                          $ref: '#/components/schemas/EntityMatchingPattern'
                  required:
                      - patternMatcher

        SelectedTierOrNodeEntities:
            description: 'selectedEntityType: TIER_NODE'
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      tierOrNode:
                          $ref: '#/components/schemas/TierOrNode'
                  required:
                      - tierOrNode

        TierOrNode:
            type: object
            properties:
                tierOrNodeScope:
                    $ref: '#/components/schemas/TierOrNodeScopeEnum'
            required:
                - tierOrNodeScope
            discriminator:
                propertyName: tierOrNodeScope
                mapping:
                    TIER_SELECTED_ENTITIES: '#/components/schemas/TierSelectedEntities'
                    NODE_SELECTED_ENTITIES: '#/components/schemas/NodeSelectedEntities'

        TierSelectedEntities:
            description: "tierOrNode: TIER_SELECTED_ENTITIES"
            allOf:
                - $ref: '#/components/schemas/TierOrNode'
                - type: object
                  properties:
                      selectedTiers:
                          $ref: '#/components/schemas/SelectedTiers'
                  required:
                      - selectedTiers

        SelectedTiers:
            type: object
            properties:
                selectedTierScope:
                    $ref: '#/components/schemas/SelectedTierScopeEnum'
            required:
                - selectedTierScope
            discriminator:
                propertyName: selectedTierScope
                mapping:
                    ALL_TIERS: '#/components/schemas/AllTiers'
                    SPECIFIC_TIERS: '#/components/schemas/SpecificTiers'

        AllTiers:
            description: "selectedTierScope: ALL_TIERS"
            allOf:
                - $ref: '#/components/schemas/SelectedTiers'
                - type: object

        SpecificTiers:
            description: "selectedTierScope: SPECIFIC_TIERS"
            allOf:
                - $ref: '#/components/schemas/SelectedTiers'
                - type: object
                  properties:
                      tiers:
                          type: array
                          items:
                              type: string
                              example: "AuthTier"
                          minItems: 1
                          example: ["AuthTier", "AggregatorTier"]
                  required:
                      - tiers

        NodeSelectedEntities:
            description: "tierOrNode: NODE_SELECTED_ENTITIES"
            allOf:
                - $ref: '#/components/schemas/TierOrNode'
                - type: object
                  properties:
                      typeofNode:
                          $ref: '#/components/schemas/TypeOfNodeEnum'
                      selectedNodes:
                          $ref: '#/components/schemas/SelectedNodes'
                  required:
                      - typeofNode
                      - selectedNodes

        SelectedNodes:
            type: object
            properties:
                selectedNodeScope:
                    $ref: '#/components/schemas/SelectedNodeScopeEnum'
            required:
                - selectedNodeScope
            discriminator:
                propertyName: selectedNodeScope
                mapping:
                    ALL_NODES: '#/components/schemas/AllNodes'
                    SPECIFIC_NODES: '#/components/schemas/SpecificNodes'
                    NODES_OF_SPECIFIC_TIERS: '#/components/schemas/NodesOfSpecificTiers'
                    NODES_MATCHING_PATTERN: '#/components/schemas/NodesMatchingPattern'
                    NODE_PROPERTY_VARIABLE_MATCHER: '#/components/schemas/NodePropertyVariableMatcher'

        AllNodes:
            description: "selectedNodeScope: ALL_NODES"
            allOf:
                - $ref: '#/components/schemas/SelectedNodes'
                - type: object

        SpecificNodes:
            description: "selectedNodeScope: SPECIFIC_NODES"
            allOf:
                - $ref: '#/components/schemas/SelectedNodes'
                - type: object
                  properties:
                      nodes:
                          type: array
                          items:
                              type: string
                              example: "node1"
                          minItems: 1
                          example: ["node1", "node2"]
                  required:
                      - nodes

        NodesOfSpecificTiers:
            description: "selectedNodeScope: NODES_OF_SPECIFIC_TIERS"
            allOf:
                - $ref: '#/components/schemas/SelectedNodes'
                - type: object
                  properties:
                      specificTiers:
                          type: array
                          items:
                              type: string
                          minItems: 1
                  required:
                      - specificTiers

        NodesMatchingPattern:
            description: "selectedNodeScope: NODES_MATCHING_PATTERN"
            allOf:
                - $ref: '#/components/schemas/SelectedNodes'
                - type: object
                  properties:
                      patternMatcher:
                          $ref: '#/components/schemas/EntityMatchingPattern'
                  required:
                      - patternMatcher

        NodePropertyVariableMatcher:
            description: "selectedNodeScope: NODE_PROPERTY_VARIABLE_MATCHER"
            allOf:
                - $ref: '#/components/schemas/SelectedNodes'
                - type: object
                  properties:
                      propVarPairs:
                          type: array
                          items:
                              type: object
                              properties:
                                  propertyType:
                                      $ref: '#/components/schemas/NodePropertyTypeEnum'
                                      example: JVM
                                  name:
                                      type: string
                                      minLength: 1
                                      example: "XmX"
                                  value:
                                      type: string
                                      minLength: 1
                                      example: "5g"
                              required:
                                  - propertyType
                                  - name
                                  - value
                          minItems: 1
                  required:
                      - propVarPairs
        Errors:
            description: "entityType: ERRORS"
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      selectedErrors:
                          $ref: '#/components/schemas/SelectedErrors'
                  required:
                      - selectedErrors
        SelectedErrors:
            type: object
            properties:
                errorScope:
                    $ref: '#/components/schemas/ErrorScopeEnum'
            required:
                - errorScope
            discriminator:
                propertyName: errorScope
                mapping:
                    ALL_ERRORS: '#/components/schemas/AllErrors'
                    SPECIFIC_ERRORS: '#/components/schemas/SpecificErrors'
                    ERRORS_OF_SPECIFIC_TIERS: '#/components/schemas/ErrorsOfSpecificTiers'
                    ERRORS_MATCHING_PATTERN: '#/components/schemas/ErrorsMatchingPattern'
        AllErrors:
            description: "errorScope: ALL_ERRORS"
            allOf:
                - $ref: '#/components/schemas/SelectedErrors'
                - type: object
        SpecificErrors:
            description: "errorScope: SPECIFIC_ERRORS"
            allOf:
                - $ref: '#/components/schemas/SelectedErrors'
                - type: object
                  properties:
                      errors:
                          type: array
                          items:
                              type: string
                              example: "NullPointerException"
                          minItems: 1
                          example: ["NullPointerException", "NumberFormatException"]
                  required:
                      - errors
        ErrorsOfSpecificTiers:
            description: "errorScope: ERRORS_OF_SPECIFIC_TIERS"
            allOf:
                - $ref: '#/components/schemas/SelectedErrors'
                - type: object
                  properties:
                      specificTiers:
                          type: array
                          items:
                              type: string
                          minItems: 1
                  required:
                      - specificTiers
        ErrorsMatchingPattern:
            description: "errorScope: ERRORS_MATCHING_PATTERN"
            allOf:
                - $ref: '#/components/schemas/SelectedErrors'
                - type: object
                  properties:
                      patternMatcher:
                          $ref: '#/components/schemas/EntityMatchingPattern'
                  required:
                      - patternMatcher
        ServiceEndpoints:
            description: "entityType: SERVICE_ENDPOINTS"
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      selectedServiceEndpoints:
                          $ref: '#/components/schemas/SelectedServiceEndpoints'
                  required:
                      - selectedServiceEndpoints
        SelectedServiceEndpoints:
            type: object
            properties:
                serviceEndpointScope:
                    $ref: '#/components/schemas/ServiceEndpointScopeEnum'
            required:
                - serviceEndpointScope
            discriminator:
                propertyName: serviceEndpointScope
                mapping:
                    ALL_SERVICE_ENDPOINTS: '#/components/schemas/AllServiceEndpoints'
                    SPECIFIC_SERVICE_ENDPOINTS: '#/components/schemas/SpecificServiceEndpoints'
                    SERVICE_ENDPOINTS_IN_SPECIFIC_TIERS: '#/components/schemas/ServiceEndpointsInSpecificTiers'
                    SERVICE_ENDPOINTS_MATCHING_PATTERN: '#/components/schemas/ServiceEndpointsMatchingPattern'

        AllServiceEndpoints:
            description: "serviceEndpointScope: ALL_SERVICE_ENDPOINTS"
            allOf:
                - $ref: '#/components/schemas/SelectedServiceEndpoints'
                - type: object
        SpecificServiceEndpoints:
            description: "serviceEndpointScope: SPECIFIC_SERVICE_ENDPOINTS"
            allOf:
                - $ref: '#/components/schemas/SelectedServiceEndpoints'
                - type: object
                  properties:
                      serviceEndpoints:
                          type: array
                          items:
                              type: string
                              example: "SE1"
                          minItems: 1
                          example: ["SE1", "SE2"]
                  required:
                      - serviceEndpoints
        ServiceEndpointsInSpecificTiers:
            description: "serviceEndpointScope: SERVICE_ENDPOINTS_IN_SPECIFIC_TIERS"
            allOf:
                - $ref: '#/components/schemas/SelectedServiceEndpoints'
                - type: object
                  properties:
                      specificTiers:
                          type: array
                          items:
                              type: string
                          minItems: 1
                  required:
                      - specificTiers
        ServiceEndpointsMatchingPattern:
            description: "serviceEndpointScope: SERVICE_ENDPOINTS_MATCHING_PATTERN"
            allOf:
                - $ref: '#/components/schemas/SelectedServiceEndpoints'
                - type: object
                  properties:
                      patternMatcher:
                          $ref: '#/components/schemas/EntityMatchingPattern'
                  required:
                      - patternMatcher
        InformationPoints:
            description: "entityType: INFORMATION_POINTS"
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      selectedInformationPoints:
                          $ref: '#/components/schemas/SelectedInformationPoints'
                  required:
                      - selectedInformationPoints
        SelectedInformationPoints:
            type: object
            properties:
                informationPointScope:
                    $ref: '#/components/schemas/InformationPointScopeEnum'
            required:
                - informationPointScope
            discriminator:
                propertyName: informationPointScope
                mapping:
                    ALL_INFORMATION_POINTS: '#/components/schemas/AllInformationPoints'
                    SPECIFIC_INFORMATION_POINTS: '#/components/schemas/SpecificInformationPoints'
                    INFORMATION_POINTS_MATCHING_PATTERN: '#/components/schemas/InformationPointsMatchingPattern'
        AllInformationPoints:
            description: "informationPointScope: ALL_INFORMATION_POINTS"
            allOf:
                - $ref: '#/components/schemas/SelectedInformationPoints'
                - type: object
        SpecificInformationPoints:
            description: "informationPointScope: SPECIFIC_INFORMATION_POINTS"
            allOf:
                - $ref: '#/components/schemas/SelectedInformationPoints'
                - type: object
                  properties:
                      informationPoints:
                          type: array
                          items:
                              type: string
                              example: "infoPoint1"
                          minItems: 1
                          example: ["infoPoint1", "infoPoint2"]
                  required:
                      - informationPoints
        InformationPointsMatchingPattern:
            description: "informationPointScope: INFORMATION_POINTS_MATCHING_PATTERN"
            allOf:
                - $ref: '#/components/schemas/SelectedInformationPoints'
                - type: object
                  properties:
                      patternMatcher:
                          $ref: '#/components/schemas/EntityMatchingPattern'
                  required:
                      - patternMatcher

        DatabasesInApplication:
            description: "entityType: DATABASES_IN_APPLICATION"
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      selectedApplicationDatabases:
                          $ref: '#/components/schemas/SelectedApplicationDatabases'
                  required:
                      - selectedApplicationDatabases
        SelectedApplicationDatabases:
            type: object
            properties:
                applicationDatabaseScope:
                    $ref: '#/components/schemas/ApplicationDatabaseScopeEnum'
            required:
                - applicationDatabaseScope
            discriminator:
                propertyName: applicationDatabaseScope
                mapping:
                    ALL_APPLICATION_DATABASES: '#/components/schemas/AllApplicationDatabases'
                    SPECIFIC_APPLICATION_DATABASES: '#/components/schemas/SpecificApplicationDatabases'
                    APPLICATION_DATABASES_MATCHING_PATTERN: '#/components/schemas/ApplicationDatabasesMatchingPattern'
        AllApplicationDatabases:
            description: "applicationDatabaseScope: ALL_APPLICATION_DATABASES"
            allOf:
                - $ref: '#/components/schemas/SelectedApplicationDatabases'
                - type: object
        SpecificApplicationDatabases:
            description: "applicationDatabaseScope: SPECIFIC_APPLICATION_DATABASES"
            allOf:
                - $ref: '#/components/schemas/SelectedApplicationDatabases'
                - type: object
                  properties:
                      applicationDatabases:
                          type: array
                          items:
                              type: string
                              example: "accountsDB"
                          minItems: 1
                          example: ["accountsDB", "MetaDB"]
                  required:
                      - applicationDatabases
        ApplicationDatabasesMatchingPattern:
            description: 'applicationDatabaseScope: APPLICATION_DATABASES_MATCHING_PATTERN'
            allOf:
                - $ref: '#/components/schemas/SelectedApplicationDatabases'
                - type: object
                  properties:
                      patternMatcher:
                          $ref: '#/components/schemas/EntityMatchingPattern'
                  required:
                      - patternMatcher
        ServersInApplication:
            description: "entityType: SERVERS_IN_APPLICATION"
            allOf:
                - $ref: '#/components/schemas/Entity'
                - type: object
                  properties:
                      selectedServers:
                          $ref: '#/components/schemas/ApplicationSelectedServers'
                  required:
                      - selectedServers
        ApplicationSelectedServers:
            type: object
            properties:
                serversScope:
                    $ref: '#/components/schemas/ServersScopeEnum'
            required:
                - serversScope
            discriminator:
                propertyName: serversScope
                mapping:
                    ALL_SERVERS_IN_APPLICATION: '#/components/schemas/AllServersInApplication'
                    SPECIFIC_SERVERS_IN_APPLICATION: '#/components/schemas/SpecificServersInApplication'
                    ALL_SERVERS_IN_SPECIFIC_TIERS: '#/components/schemas/AllServersInSpecificTiers'
        AllServersInApplication:
            description: "serversScope: ALL_SERVERS_IN_APPLICATION"
            allOf:
                - $ref: '#/components/schemas/ApplicationSelectedServers'
                - type: object
        SpecificServersInApplication:
            description: "serversScope: SPECIFIC_SERVERS_IN_APPLICATION"
            allOf:
                - $ref: '#/components/schemas/ApplicationSelectedServers'
                - type: object
                  properties:
                      specificServers:
                          type: array
                          items:
                              type: string
                              minLength: 1
                          minItems: 1
                  required:
                      - specificServers
        AllServersInSpecificTiers:
            description: "serversScope: ALL_SERVERS_IN_SPECIFIC_TIERS"
            allOf:
                - $ref: '#/components/schemas/ApplicationSelectedServers'
                - type: object
                  properties:
                      specificTiers:
                          type: array
                          items:
                              type: string
                          minItems: 1
                  required:
                      - specificTiers

        Events:
            description: 'describes the triggers for policy'
            type: object
            properties:
                healthRuleEvents:
                    $ref: '#/components/schemas/HealthRuleEvents'
                otherEvents:
                    $ref: '#/components/schemas/OtherEvents'
                anomalyEvents:
                    $ref: '#/components/schemas/AnomalyEvents'
                customEvents:
                    type: array
                    items:
                        $ref: '#/components/schemas/CustomEvent'
            minProperties: 1

        CustomEvent:
            description: 'describes the custom events'
            type: object
            properties:
                eventName:
                    type: string
                propertyMatchCriteria:
                    $ref: '#/components/schemas/PropertyMatchCriteria'
                keyValuePairArray:
                    type: array
                    items:
                        $ref: '#/components/schemas/KeyValuePair'
            required:
                - eventName

        HealthRuleEvents:
            description: 'describes events related to Health Rules'
            type: object
            required:
                - healthRuleEventTypes
                - healthRuleScope
            properties:
                healthRuleEventTypes:
                    $ref: '#/components/schemas/HealthRuleEventTypes'
                healthRuleScope:
                    $ref: '#/components/schemas/HealthRuleScope'

        HealthRuleScope:
            description: 'describes the scope of the health rule on which event(s) should trigger'
            type: object
            properties:
                healthRuleScopeType:
                    $ref: '#/components/schemas/HealthRuleScopeType'
            required:
                - healthRuleScopeType
            discriminator:
                propertyName: healthRuleScopeType
                mapping:
                    ALL_HEALTH_RULES: '#/components/schemas/AllHealthRules'
                    SPECIFIC_HEALTH_RULES: '#/components/schemas/SpecificHealthRules'

        AllHealthRules:
            description: 'HealthRuleScope: ALL_HEALTH_RULES'
            allOf:
                - $ref: '#/components/schemas/HealthRuleScope'
                - type: object

        SpecificHealthRules:
            description: 'HealthRuleScope: SPECIFIC_HEALTH_RULES'
            allOf:
                - $ref: '#/components/schemas/HealthRuleScope'
                - type: object
                  properties:
                      healthRules:
                          type: array
                          items:
                              type: string
                              example: "My health rule"
                          minItems: 1
                          example: ["My health rule 1", "My health rule 2"]
                  required:
                      - healthRules

        HealthRuleEventTypes:
            description: 'describes the trigger event type related to Health rules'
            type: array
            items:
                $ref: '#/components/schemas/HealthRuleEventTypeEnum'
            minItems: 1
            example: ["HEALTH_RULE_CONTINUES_CRITICAL", "HEALTH_RULE_UPGRADED"]

        OtherEvents:
            type: array
            items:
                $ref: '#/components/schemas/OtherEventType'
            example: ["CLR_CRASH", "DEADLOCK"]

        AnomalyEvents:
            description: 'describes the trigger event type(s) generated by anomaly detection'
            type: array
            items:
                $ref: '#/components/schemas/AnomalyEventType'
            minItems: 1
            example: ["ANOMALY_OPEN_WARNING", "ANOMALY_CLOSE_CRITICAL"]

        Action:
            description: 'describes the action to be taken when the policy is triggered'
            type: object
            properties:
                actionName:
                    type: string
                    example: "My action 1"
                actionType:
                    $ref: '#/components/schemas/ActionTypeEnum'
            required:
                - actionName
                - actionType
            discriminator:
                propertyName: actionType
                mapping:
                    CREATE_UPDATE_JIRA: '#/components/schemas/SimpleActionType'
                    SMS: '#/components/schemas/SimpleActionType'
                    EMAIL: '#/components/schemas/EmailActionType'
                    CUSTOM_EMAIL: '#/components/schemas/SimpleActionType'
                    THREAD_DUMP: '#/components/schemas/ActionOnSpecifiedEntities'
                    HTTP_REQUEST: '#/components/schemas/SimpleActionType'
                    CUSTOM: '#/components/schemas/SimpleActionType'
                    RUN_SCRIPT_ON_NODES: '#/components/schemas/ActionOnSpecifiedEntities'
                    DIAGNOSTIC_BUSINESS_TRANSACTIONS: '#/components/schemas/SimpleActionType'

        SimpleActionType:
            allOf:
                - $ref: '#/components/schemas/Action'


        EmailActionType:
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      notes:
                          type: string
                          example: "Now this is an avengers level threat. Fix this bug immediately."


        ActionOnSpecifiedEntities:
            allOf:
                - $ref: '#/components/schemas/Action'
                - type: object
                  properties:
                      specifiedEntityActionDetails:
                            $ref: '#/components/schemas/SpecifiedEntityActionDetails'
                  required:
                      - specifiedEntityActionDetails

        SpecifiedEntityActionDetails:
            type: object
            properties:
                specifiedEntityActionScope:
                    $ref: '#/components/schemas/SpecifiedEntityActionScopeEnum'
            discriminator:
                propertyName: specifiedEntityActionScope
                mapping:
                    PERCENTAGE: '#/components/schemas/ActionOnPercentageEntities'
                    ABSOLUTE: '#/components/schemas/ActionOnAbsoluteEntities'
                    SPECIFIC_NODES: '#/components/schemas/ActionOnSpecificNodes'

        ActionOnPercentageEntities:
            description: 'specifiedEntityActionScope: PERCENTAGE'
            allOf:
                - $ref: '#/components/schemas/SpecifiedEntityActionDetails'
                - type: object
                  properties:
                      value:
                          type: integer
                          example: 50
                  required:
                      - value

        ActionOnAbsoluteEntities:
            description: 'specifiedEntityActionScope: ABSOLUTE'
            allOf:
                - $ref: '#/components/schemas/SpecifiedEntityActionDetails'
                - type: object
                  properties:
                      value:
                          type: integer
                          example: 10
                  required:
                      - value

        ActionOnSpecificNodes:
            description: 'specifiedEntityActionScope: SPECIFIC_NODES. Describes the list of nodes on which the action should be taken.'
            allOf:
                - $ref: '#/components/schemas/SpecifiedEntityActionDetails'
                - type: object
                  properties:
                      nodes:
                          type: array
                          items:
                              type: string
                              example: "node1"
                          minItems: 1
                          example: ["node1", "AuthNode", "ErrorHandlerNode"]
                  required:
                      - nodes

        PolicySummaryArray:
            type: array
            items:
                $ref: '#/components/schemas/PolicySummary'

        KeyValuePair:
            type: object
            properties:
                key:
                    type: string
                    example: "key1"
                value:
                    type: string
                    example: "value1"
            required:
                - key
                - value

        PolicySummary:
            type: object
            properties:
                id:
                    type: integer
                    format: int64
                    example: 12
                name:
                    type: string
                    minLength: 1
                    example: "some policy name"
                enabled:
                    type: boolean
                    example: true
            required:
                - id
                - name
                - enabled

        PolicyConfiguration:
            description: Contains the configuration of policy that can updated individually without the need to send complete policy payload.
            type: object
            properties:
                enabled:
                    type: boolean
                    example: true
                policyName:
                    type: string
                    example: "test policy"

        EntityMatchingPattern:
            type: object
            properties:
                matchTo:
                    $ref: '#/components/schemas/EntityMatchingPatternEnum'
                    example: STARTS_WITH
                matchValue:
                    type: string
                    minLength: 1
                    example: "production"
                shouldNot:
                    type: boolean
                    default: false
                    example: false
            required:
                - matchTo
                - matchValue

        PropertyMatchCriteria:
            type: string
            enum:
                - ANY
                - ALL
            default: ANY

        EntityMatchingPatternEnum:
            type: string
            enum:
                - STARTS_WITH
                - ENDS_WITH
                - CONTAINS
                - EQUALS
                - MATCH_REG_EX

        BusinessTransactionScopeEnum:
            type: string
            enum:
                - ALL_BUSINESS_TRANSACTIONS
                - SPECIFIC_BUSINESS_TRANSACTIONS
                - BUSINESS_TRANSACTIONS_IN_SPECIFIC_TIERS
                - BUSINESS_TRANSACTIONS_MATCHING_PATTERN

        TierOrNodeScopeEnum:
            type: string
            enum:
                - TIER_SELECTED_ENTITIES
                - NODE_SELECTED_ENTITIES

        SelectedTierScopeEnum:
            type: string
            enum:
                - ALL_TIERS
                - SPECIFIC_TIERS

        TypeOfNodeEnum:
            type: string
            enum:
                - ALL_NODES
                - JAVA_NODES
                - DOT_NET_NODES
                - PHP_NODES

        SelectedNodeScopeEnum:
            type: string
            enum:
                - ALL_NODES
                - SPECIFIC_NODES
                - NODES_OF_SPECIFIC_TIERS
                - NODES_MATCHING_PATTERN
                - NODE_PROPERTY_VARIABLE_MATCHER

        NodePropertyTypeEnum:
            type: string
            enum:
                - META
                - ENV
                - JVM

        ErrorScopeEnum:
            type: string
            enum:
                - ALL_ERRORS
                - SPECIFIC_ERRORS
                - ERRORS_OF_SPECIFIC_TIERS
                - ERRORS_MATCHING_PATTERN
        ServiceEndpointScopeEnum:
            type: string
            enum:
                - ALL_SERVICE_ENDPOINTS
                - SPECIFIC_SERVICE_ENDPOINTS
                - SERVICE_ENDPOINTS_IN_SPECIFIC_TIERS
                - SERVICE_ENDPOINTS_MATCHING_PATTERN

        InformationPointScopeEnum:
            type: string
            enum:
                - ALL_INFORMATION_POINTS
                - SPECIFIC_INFORMATION_POINTS
                - INFORMATION_POINTS_MATCHING_PATTERN

        DatabaseTypeEnum:
            type: string
            enum:
                - ALL_DATABASE_TYPES
                - COUCHBASE
                - DB2
                - MONGO_DB
                - MICROSOFT_SQL_SERVER
                - MYSQL
                - ORACLE
                - POSTGRE_SQL
                - AZURE_SQL
                - SYBASE

        ApplicationDatabaseScopeEnum:
            type: string
            enum:
                - ALL_APPLICATION_DATABASES
                - SPECIFIC_APPLICATION_DATABASES
                - APPLICATION_DATABASES_MATCHING_PATTERN

        ServersScopeEnum:
            type: string
            enum:
                - ALL_SERVERS_IN_APPLICATION
                - SPECIFIC_SERVERS_IN_APPLICATION
                - ALL_SERVERS_IN_SPECIFIC_TIERS

        SpecifiedEntityActionScopeEnum:
            type: string
            enum:
                - PERCENTAGE
                - ABSOLUTE
                - SPECIFIC_NODES

        AnomalyEventType:
            type: string
            enum:
                - ANOMALY_OPEN_WARNING
                - ANOMALY_OPEN_CRITICAL
                - ANOMALY_UPGRADED
                - ANOMALY_DOWNGRADED
                - ANOMALY_CLOSE_WARNING
                - ANOMALY_CLOSE_CRITICAL
                - ANOMALY_CANCELED_WARNING
                - ANOMALY_CANCELED_CRITICAL

        HealthRuleEventTypeEnum:
            type: string
            enum:
                - HEALTH_RULE_CONTINUES_CRITICAL
                - HEALTH_RULE_OPEN_CRITICAL
                - HEALTH_RULE_OPEN_WARNING
                - HEALTH_RULE_UPGRADED
                - HEALTH_RULE_DOWNGRADED
                - HEALTH_RULE_CONTINUES_WARNING
                - HEALTH_RULE_CLOSE_WARNING
                - HEALTH_RULE_CLOSE_CRITICAL
                - HEALTH_RULE_CANCELED_WARNING
                - HEALTH_RULE_CANCELED_CRITICAL

        HealthRuleScopeType:
            type: string
            enum:
                - ALL_HEALTH_RULES
                - SPECIFIC_HEALTH_RULES

        OtherEventType:
            type: string
            enum:
                - CLR_CRASH
                - APPLICATION_CRASH
                - DEADLOCK
                - RESOURCE_POOL_LIMIT
                - APPLICATION_DEPLOYMENT
                - APP_SERVER_RESTART
                - APPLICATION_CONFIG_CHANGE
                - AGENT_CONFIGURATION_ERROR
                - APPLICATION_DISCOVERED
                - TIER_DISCOVERED
                - NODE_DISCOVERED
                - MACHINE_DISCOVERED
                - BT_DISCOVERED
                - SERVICE_ENDPOINT_DISCOVERED
                - BACKEND_DISCOVERED
                - EUM_CLOUD_SYNTHETIC_HEALTHY_EVENT
                - EUM_CLOUD_SYNTHETIC_WARNING_EVENT
                - EUM_CLOUD_SYNTHETIC_CONFIRMED_WARNING_EVENT
                - EUM_CLOUD_SYNTHETIC_ONGOING_WARNING_EVENT
                - EUM_CLOUD_SYNTHETIC_ERROR_EVENT
                - EUM_CLOUD_SYNTHETIC_CONFIRMED_ERROR_EVENT
                - EUM_CLOUD_SYNTHETIC_ONGOING_ERROR_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_HEALTHY_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_WARNING_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_CONFIRMED_WARNING_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_ONGOING_WARNING_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_CRITICAL_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_CONFIRMED_CRITICAL_EVENT
                - EUM_CLOUD_SYNTHETIC_PERF_ONGOING_CRITICAL_EVENT
                - MOBILE_NEW_CRASH_EVENT
                - SLOW
                - VERY_SLOW
                - STALL
                - ERROR

        SelectedEntityType:
            type: string
            enum:
                - ANY_ENTITY
                - SPECIFIC_ENTITIES

        EntityType:
            type: string
            enum:
                - BUSINESS_TRANSACTION
                - TIER_NODE
                - ERRORS
                - SERVICE_ENDPOINTS
                - INFORMATION_POINTS
                - DATABASES_IN_APPLICATION
                - SERVERS_IN_APPLICATION

        ActionTypeEnum:
            type: string
            enum:
                - SMS
                - EMAIL
                - CUSTOM_EMAIL
                - THREAD_DUMP
                - HTTP_REQUEST
                - CUSTOM
                - RUN_SCRIPT_ON_NODES
                - DIAGNOSTIC_BUSINESS_TRANSACTIONS
                - CREATE_UPDATE_JIRA
        ErrorResponse:
            type: object
            properties:
                statusCode:
                    type: integer
                    example: 404
                message:
                    type: string
                    example: "Policy with given Id not found."

    parameters:
        applicationId:
            in: path
            name: application-id
            required: true
            schema:
                type: integer
                format: int64
                example: 10
        policyId:
            in: path
            name: policy-id
            description: Id of the policy for which the operation is to be done
            required: true
            schema:
                type: integer
                format: int64
                example: 24
    requestBodies:
        PolicyConfiguration:
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/PolicyConfiguration'
        Policy:
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/Policy'

    responses:
        NotFound:
            description: The specified resource was not found
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        Unauthorized:
            description: Unauthorized
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        BadRequest:
            description: Bad Request
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        Forbidden:
            description: Forbidden
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
        Conflict:
            description: Already exists
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/ErrorResponse'
