<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->

<xsd:schema
 targetNamespace="http://netbeans.org/ns/oauth/metadata/1"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:oauth="http://netbeans.org/ns/oauth/metadata/1"
 elementFormDefault="qualified">
     
    <xsd:element name="metadata" type="oauth:metadata"/>

    <xsd:complexType name="metadata">
        <xsd:annotation>
          <xsd:documentation>
            root element: specifies OAuth authentication flow and OAuth parameters;
          </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="flow" type="oauth:flowType"/>
            <xsd:element name="param" type="oauth:paramType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="base-url" type="xsd:anyURI" use="required"/>
        <xsd:attribute name="signature-method" type="oauth:signature-methodType" use="required"/>
        <xsd:attribute name="version" type="xsd:string"/> <!-- default: 1.0 -->
        <xsd:attribute name="nonce" type="xsd:boolean"/> <!-- default: true -->
        <xsd:attribute name="timestamp" type="xsd:boolean"/> <!-- default: true -->
    </xsd:complexType>

    <xsd:complexType name="flowType">
        <xsd:annotation>
          <xsd:documentation>
            specifies 3 phases of OAuth authentication mechanism:
            1. obtaining request-token,
            2. consumer authorization and getting access-token
            3. obtaining access-token
          </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:element name="request-token" type="oauth:methodType" />
            <xsd:element name="authorization" type="oauth:authorizationType" />
            <xsd:element name="access-token" type="oauth:methodType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="methodType">
        <xsd:annotation>
          <xsd:documentation>
            specifies REST method used to obtain (request/access) token.
          </xsd:documentation>
        </xsd:annotation>
        <xsd:attribute name="method-name" type="xsd:string" use="required"/>
        <xsd:attribute name="request-style" use="required">
          <xsd:simpleType>
            <xsd:restriction base="xsd:string">
              <xsd:enumeration value="FORM"/>
              <xsd:enumeration value="PATH"/>
              <xsd:enumeration value="QUERY"/>
              <xsd:enumeration value="HEADER"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:attribute>
        <!-- request parameter. Default: "method" -->
        <xsd:attribute name="request-param" type="xsd:string"/>
        <xsd:attribute name="response-style" use="required">
          <xsd:simpleType>
            <xsd:restriction base="xsd:string">
              <xsd:enumeration value="FORM"/>
              <xsd:enumeration value="XML"/>
              <xsd:enumeration value="JSON"/>
            </xsd:restriction>
          </xsd:simpleType>
        </xsd:attribute>
        <xsd:attribute name="signature-method" type="oauth:signature-methodType"/>
        <xsd:attribute name="version" type="xsd:string"/> <!-- default: 1.0 -->
        <xsd:attribute name="nonce" type="xsd:boolean"/> <!-- default: true -->
        <xsd:attribute name="timestamp" type="xsd:boolean"/> <!-- default: true -->
        <xsd:attribute name="callback" type="xsd:boolean"/> <!-- default: false -->
        <xsd:attribute name="verifier" type="xsd:boolean"/> <!-- default: false -->
    </xsd:complexType>

      <xsd:complexType name="authorizationType">
        <xsd:annotation>
          <xsd:documentation>
            specifies authorization step, that can be either
            1. fixed-url URL with one ore more OAuth parameters
            2. dynamic-url obtained during first step (request-token)
          </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
            <xsd:choice>
                <xsd:element name="fixed-url" type="oauth:fixed-urlType"/>
                <xsd:element name="dynamic-url" type="oauth:dynamic-urlType"/>
            </xsd:choice>
            <xsd:element name="param" type="oauth:paramType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
      </xsd:complexType>

      <xsd:complexType name="dynamic-urlType">
        <xsd:annotation>
          <xsd:documentation>
            specifies dynamic-url of authorization page,
            obtained during request-token step - as auth-param-name
          </xsd:documentation>
        </xsd:annotation>
        <xsd:attribute name="auth-param-name" type="xsd:string" use="required"/>
      </xsd:complexType>

      <xsd:complexType name="fixed-urlType">
        <xsd:annotation>
          <xsd:documentation>
            specifies fixed-url of authorization page
          </xsd:documentation>
        </xsd:annotation>
        <xsd:attribute name="url" type="xsd:anyURI" use="required"/>
      </xsd:complexType>

      <xsd:simpleType name="signature-methodType">
        <xsd:annotation>
          <xsd:documentation>
            signature method
          </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="HMAC_SHA1"/>
          <xsd:enumeration value="PLAINTEXT"/>
        </xsd:restriction>
      </xsd:simpleType>
      
      <xsd:complexType name="paramType">
          <xsd:attribute name="oauth-name" type="xsd:string" use="required"/>
          <xsd:attribute name="param-name" type="xsd:string"/>
          <xsd:attribute name="oauth-prefix" type="xsd:string"/>
          <xsd:attribute name="oauth-postfix" type="xsd:string"/>
          <xsd:attribute name="xpath" type="xsd:string"/>
      </xsd:complexType>

</xsd:schema>
