module ietf-yang-semver {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-yang-semver";
  prefix ysv;

  organization
    "IETF NETMOD (Network Modeling) Working Group";
  contact
    "WG Web:   <http://tools.ietf.org/wg/netmod/>
     WG List:  <mailto:netmod@ietf.org>

     Author:   Joe Clarke
               <mailto:jclarke@cisco.com>
     Author:   Robert Wilton
               <mailto:rwilton@cisco.com>
     Author:   Reshad Rahman
               <mailto:reshad@yahoo.com>
     Author:   Balazs Lengyel
               <mailto:balazs.lengyel@ericsson.com>
     Author:   Jason Sterne
               <mailto:jason.sterne@nokia.com>
     Author:   Benoit Claise
               <mailto:benoit.claise@huawei.com>";
  description
    "This module provides type and grouping definitions for YANG
     packages.

     Copyright (c) 2025 IETF Trust and the persons identified as
     authors of the code.  All rights reserved.

     Redistribution and use in source and binary forms, with or
     without modification, is permitted pursuant to, and subject
     to the license terms contained in, the Revised BSD License
     set forth in Section 4.c of the IETF Trust's Legal Provisions
     Relating to IETF Documents
     (http://trustee.ietf.org/license-info).

     The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL
     NOT', 'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'NOT RECOMMENDED',
     'MAY', and 'OPTIONAL' in this document are to be interpreted as
     described in BCP 14 (RFC 2119) (RFC 8174) when, and only when,
     they appear in all capitals, as shown here.

     This version of this YANG module is part of RFC XXXX; see
     the RFC itself for full legal notices.";

  // RFC Ed.: update the date below with the date of RFC publication
  // and remove this note.
  // RFC Ed.: replace XXXX with actual RFC number and remove this
  // note.
  // RFC Ed. update the ysv:version to "1.0.0".

  revision 2025-01-21 {
    ysv:version "0.20.0";
    description
      "Initial revision";
    reference
      "RFC XXXX: YANG Semantic Versioning.";
  }

  /*
   * Extensions
   */

  extension version {
    argument yang-semantic-version;
    description
      "The version extension can be used to provide an additional
       identifier associated with a module or submodule
       revision.

       The format of the version extension argument MUST conform
       to the 'version' typedef defined in this module.

       The statement MUST only be a substatement of the revision
       statement.  Zero or one version statements per parent
       statement are allowed.  No substatements for this extension
       have been standardized.

       Versions MUST be unique amongst all revisions of a
       module or submodule.

       Adding a version is a backwards-compatible
       change.  Changing or removing an existing version in
       the revision history is a non-backwards-compatible
       change, because it could impact any references to that
       version.";
    reference
      "RFC XXXX: YANG Semantic Versioning;
       Section 4.2, YANG Semantic Version Extension";
  }

  extension recommended-min-version {
    argument yang-semantic-version;
    description
      "Recommends the versions of the module that may be imported to
       one that is greater than or equal to the specified version.

       The format of the recommended-min-version extension argument
       must be the MAJOR.MINOR.PATCH components from the
       'version' typedef defined in this module (i.e., excluding
       the '_compatible' and '_non_compatible' modifiers as
       well as any metadata).

       The statement MUST only be a substatement of the import
       statement.  Zero or one 'recommended-min-version'
       statements per parent statement are allowed.  No
       substatements for this extension have been
       standardized.

       A module to be imported is considered as meeting the
       recommended minimum version criteria if it meets one of
       the following conditions:

       * Has the exact same MAJOR, MINOR, PATCH as in the
          recommend-min-version value.
       * Has the same MAJOR and MINOR version numbers and a
         greater PATCH number.
       * Has the same MAJOR version number and greater MINOR number.
         In this case the PATCH number is ignored.
       * Has a greater MAJOR version number.  In this case MINOR
         and PATCH numbers are ignored.

       Adding, removing or updating a 'recommended-min-version'
       statement to an import is a backwards-compatible change.";
    reference
      "RFC XXXX: YANG Semantic Versioning; Section 5,
       Import Module by Semantic Version";
  }

  /*
   * Typedefs
   */

  typedef version {
    type string {
      length "5..128";
      pattern '[0-9]+[.][0-9]+[.][0-9]+(_(non_)?compatible)?'
            + '(-[A-Za-z0-9.-]+[.-][0-9]+)?([+][A-Za-z0-9.-]+)?';
    }
    description
      "Represents a YANG semantic version.  The rules governing the
       use of this version identifier are defined in the
       reference for this typedef.";
    reference
      "RFC XXXX: YANG Semantic Versioning.";
  }
}
