<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../xslt/schema.xsl"?>

<!-- (C) 2011 OpenStack Foundation., All Rights Reserved -->

<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
           targetNamespace="http://docs.openstack.org/common/api/v1.0"
           xmlns:limits="http://docs.openstack.org/common/api/v1.0"
           xmlns:xsdxt="http://docs.rackspacecloud.com/xsd-ext/v1.0"
           xmlns:html="http://www.w3.org/1999/xhtml"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:annotation>
        <xs:appinfo
            xml:lang="EN"
            xmlns="http://www.w3.org/1999/xhtml">
            <xsdxt:title>Limits</xsdxt:title>
            <xsdxt:link rel="index" href="api-common.xsd" />
        </xs:appinfo>
        <xs:documentation
            xml:lang="EN"
            xmlns="http://www.w3.org/1999/xhtml">
            <p>
                This schema file defines types related to
                preconfigured limits.  Limits are used to manage the
                capacity of the API and to prevent abuse.  The API
                defines two kinds of limits <a href="#type_RateLimit"
                title="See definition of a RateLimit">RateLimits</a>
                and <a href="#type_AbsoluteLimit" title="See
                definition of an
                AbsoluteLimit">AbsoluteLimits</a>. RateLimits are
                thresholds that are reset after a certain amount of
                time passes.  Absolute limits are fixed.
            </p>
        </xs:documentation>
    </xs:annotation>

    <!-- Live limit definitions -->
    <xs:element name="limits" type="limits:Limits">
        <xs:annotation>
            <xs:documentation
                xml:lang="EN"
                xmlns="http://www.w3.org/1999/xhtml">
                <p>
                    The limits element contains information on both rate and
                    absolute limits.
                </p>
            </xs:documentation>
            <xs:appinfo>
                <xsdxt:samples>
                    <xsdxt:sample>
                        <xsdxt:code type="application/xml" href="../samples/limits.xml" />
                    </xsdxt:sample>
                    <xsdxt:sample>
                        <xsdxt:code type="application/json" href="../samples/limits.json" />
                    </xsdxt:sample>
                </xsdxt:samples>
            </xs:appinfo>
        </xs:annotation>
    </xs:element>

    <!-- Enumeration and SimpleType definitions -->
    <xs:simpleType name="HttpMethod">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                    The HttpMethod simple type defines a string
                    enumeration of HTTP method verbs as outlined in <a
                    href="http://www.ietf.org/rfc/rfc2616.txt">RFC2616</a>
                    section 9.
                </html:p>
            </xs:documentation>
        </xs:annotation>
        
        <xs:restriction base="xs:string">
            <xs:enumeration value="GET" />
            <xs:enumeration value="DELETE" />
            <xs:enumeration value="POST" />
            <xs:enumeration value="PUT" />
            <xs:enumeration value="HEAD" />
            <xs:enumeration value="OPTIONS" />
            <xs:enumeration value="CONNECT" />
            <xs:enumeration value="TRACE" />
            
            <xs:enumeration value="ALL" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="TimeUnit">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                    The TimeUnit simple type defines a string
                    enumeration of coarse time units that are be used
                    to define the duration of time that a limited
                    request will be unavailable for.
                </html:p>
            </xs:documentation>
        </xs:annotation>
        
        <xs:restriction base="xs:string">
            <xs:enumeration value="SECOND" />
            <xs:enumeration value="MINUTE" />
            <xs:enumeration value="HOUR" />
            <xs:enumeration value="DAY" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="Limits">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                    A Limits type defines a collection of limits
                </html:p>
            </xs:documentation>
        </xs:annotation>
        
        <xs:sequence>
            <xs:element name="rates" type="limits:RateLimitList" minOccurs="0" maxOccurs="1" />
            <xs:element name="absolute" type="limits:AbsoluteLimitList" minOccurs="0" maxOccurs="1"  />
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>

    <xs:complexType name="AbsoluteLimitList">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                  An AbsoluteLimitList type defines a list of absolute limits
                </html:p>
            </xs:documentation>
        </xs:annotation>

        <xs:sequence>
            <xs:element name="limit" type="limits:AbsoluteLimit" minOccurs="1" maxOccurs="unbounded" />
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>

    <xs:complexType name="RateLimitList">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                  A RateLimitList type defines a list of resource
                  scoped limit collections.
                </html:p>
            </xs:documentation>
        </xs:annotation>
        
        <xs:sequence>
            <xs:element name="rate" type="limits:ResourceRateLimits" minOccurs="1" maxOccurs="unbounded" />
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>

    <xs:complexType name="ResourceRateLimits">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                  A ResourceLimitCollection type represents a
                  collection of limits that are scoped to a single
                  resource variant.
                </html:p>
            </xs:documentation>
        </xs:annotation>
        
        <xs:sequence>
            <xs:element name="limit" type="limits:RateLimit" minOccurs="1" maxOccurs="unbounded" />
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
    
        <xs:attribute name="uri" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The uri of a limit collection is a human
                        readable string version of the regular
                        expression matcher that is used to define the
                        limit collection resource scope.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>

        <xs:attribute name="regex" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        A collection of limits are scoped to a
                        resource by a regular expression.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>

    <xs:complexType name="AbsoluteLimit">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                    Absolute limits are predefined fixed limits. We
                    define each of these limits as a key/value
                    pair. Please consult the API Specification for a
                    list of absolute limits used by the system.
                </html:p>
            </xs:documentation>
        </xs:annotation>

        <xs:sequence>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The name (or key) of the absolute limit.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>

        <xs:attribute name="value" type="xs:int" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        A value specifying the absolute limit.The name
                        of the absolute limit determines the unit
                        type. For example, the key maxIPGroups implies
                        that the value is in terms of IPGroups.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>

    <xs:complexType name="RateLimit">
        <xs:annotation>
            <xs:documentation>
                <html:p>
                    A Rate Limit type defines the maximum number of
                    requests that can be performed, the time interval
                    that each limited request will be unavailable for,
                    and, for convience, the remaining number of
                    requests remaining. This is done for every
                    HttpMethod that is rate limited.
                </html:p>
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="verb" type="limits:HttpMethod" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The verb of a Limit represents the HttpMethod
                        that the Limit is scoped to.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>

        <xs:attribute name="value" type="xs:int" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The value of a Limit represents maximum Number
                        of requests that the rate limit will allow.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>

        <xs:attribute name="remaining" type="xs:int" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The remaining number of requests that a user
                        can make against the limited resource before
                        being denied access.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>

        <xs:attribute name="unit" type="limits:TimeUnit" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The unit of a Limit defines the duration of a
                        limited request's unavailability.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>

        <xs:attribute name="next-available" type="xs:dateTime" use="required">
            <xs:annotation>
                <xs:documentation>
                    <html:p>
                        The next-available attribute of a Limit tells
                        the user when a limited request will become
                        available for consumption.
                    </html:p>
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:complexType>
</xs:schema>
