### Install spdx Go Library Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use 'go get' to install the spdx library. This command fetches and installs the specified package. ```go go get github.com/git-pkgs/spdx ``` -------------------------------- ### Get License Information Source: https://pkg.go.dev/github.com/git-pkgs/spdx Retrieves detailed information about a license, including its key, SPDX identifier, category, and deprecation status. Returns nil if the license is not found. ```go func GetLicenseInfo(license string) *LicenseInfo ``` -------------------------------- ### Get Licenses from AndExpression Source: https://pkg.go.dev/github.com/git-pkgs/spdx The Licenses method for AndExpression returns a slice of strings representing the licenses involved in the AND combination. ```go func (e *AndExpression) Licenses() []string ``` -------------------------------- ### Get License Categories from Expression Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX expression string and returns all unique license categories found within it. Useful for analyzing the licensing of a project based on its declared licenses. ```go func ExpressionCategories(expression string) ([]Category, error) ``` ```go ExpressionCategories("MIT OR Apache-2.0") // []Category{CategoryPermissive} (both are Permissive) ExpressionCategories("MIT OR GPL-3.0-only") // []Category{CategoryPermissive, CategoryCopyleft} ``` -------------------------------- ### Get license categories Source: https://pkg.go.dev/github.com/git-pkgs/spdx Provides information about license categories and checks license types. ```APIDOC ## Get license categories ### Description Provides functions to retrieve license categories, check if licenses are permissive or copyleft, and get detailed license information. ### Function Signatures `LicenseCategory(license string) Category` `IsPermissive(license string) bool` `IsCopyleft(license string) bool` `ExpressionCategories(expression string) ([]Category, error)` `HasCopyleft(expression string) bool` `IsFullyPermissive(expression string) bool` `GetLicenseInfo(license string) LicenseInfo ### Parameters #### Path Parameters - `license` (string) - Required - The license identifier. - `expression` (string) - Required - The license expression. ### Request Example ```go // Get the category for a license cat := spdx.LicenseCategory("MIT") // Returns spdx.CategoryPermissive cat := spdx.LicenseCategory("GPL-3.0-only") // Returns spdx.CategoryCopyleft cat := spdx.LicenseCategory("MPL-2.0") // Returns spdx.CategoryCopyleftLimited cat := spdx.LicenseCategory("Unlicense") // Returns spdx.CategoryPublicDomain // Check license type spdx.IsPermissive("MIT") // Returns true spdx.IsPermissive("GPL-3.0") // Returns false spdx.IsCopyleft("GPL-3.0-only") // Returns true spdx.IsCopyleft("LGPL-2.1") // Returns true (weak copyleft) // Get categories for an expression cats, err := spdx.ExpressionCategories("MIT OR GPL-3.0-only") // cats: []Category{CategoryPermissive, CategoryCopyleft} // Check expressions for copyleft spdx.HasCopyleft("MIT OR Apache-2.0") // Returns false spdx.HasCopyleft("MIT OR GPL-3.0-only") // Returns true spdx.IsFullyPermissive("MIT OR Apache-2.0") // Returns true spdx.IsFullyPermissive("MIT OR GPL-3.0") // Returns false // Get detailed license info info := spdx.GetLicenseInfo("MIT") // info.Category: CategoryPermissive // info.IsException: false // info.IsDeprecated: false ``` ### Response #### Success Response - `cat` (Category) - The category of the license. - `IsPermissive` returns `true` if the license is permissive. - `IsCopyleft` returns `true` if the license is copyleft. - `cats` ([]Category) - A slice of categories for the expression. - `HasCopyleft` returns `true` if the expression contains copyleft licenses. - `IsFullyPermissive` returns `true` if the expression is fully permissive. - `info` (LicenseInfo) - Detailed information about the license. #### Response Example ```json { "cat": "CategoryPermissive", "IsPermissive": true, "IsCopyleft": false, "ExpressionCategories": { "cats": ["CategoryPermissive", "CategoryCopyleft"], "err": null }, "HasCopyleft": true, "IsFullyPermissive": false, "GetLicenseInfo": { "Category": "CategoryPermissive", "IsException": false, "IsDeprecated": false } } ``` ### Available categories: * `CategoryPermissive` - MIT, Apache-2.0, BSD-* * `CategoryCopyleft` - GPL-_, AGPL-* * `CategoryCopyleftLimited` - LGPL-_, MPL-_ , EPL-* * `CategoryPublicDomain` - Unlicense, CC0-1.0 * `CategoryCommercial` - Commercial licenses * `CategoryProprietaryFree` - Free but proprietary * `CategorySourceAvailable` - Source-available licenses * `CategoryPatentLicense` - Patent grants * `CategoryFreeRestricted` - Free with restrictions * `CategoryCLA` - Contributor agreements * `CategoryUnstated` - No license stated ``` -------------------------------- ### Get Category for a Single License Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns the category for a given license identifier (SPDX or scancode key). Returns CategoryUnknown if the license is not found. ```go func LicenseCategory(license string) Category ``` ```go LicenseCategory("MIT") // CategoryPermissive LicenseCategory("GPL-3.0-only") // CategoryCopyleft LicenseCategory("MPL-2.0") // CategoryCopyleftLimited ``` -------------------------------- ### Get License Categories Source: https://pkg.go.dev/github.com/git-pkgs/spdx Retrieves the category for a given license identifier (e.g., Permissive, Copyleft). Also provides functions to check specific license types and expression categories. ```go // Get the category for a license cat := spdx.LicenseCategory("MIT") // spdx.CategoryPermissive cat := spdx.LicenseCategory("GPL-3.0-only") // spdx.CategoryCopyleft cat := spdx.LicenseCategory("MPL-2.0") // spdx.CategoryCopyleftLimited cat := spdx.LicenseCategory("Unlicense") // spdx.CategoryPublicDomain // Check license type spdx.IsPermissive("MIT") // true spdx.IsPermissive("GPL-3.0") // false spdx.IsCopyleft("GPL-3.0-only") // true spdx.IsCopyleft("LGPL-2.1") // true (weak copyleft) // Get categories for an expression cats, err := spdx.ExpressionCategories("MIT OR GPL-3.0-only") // []Category{CategoryPermissive, CategoryCopyleft} // Check expressions for copyleft spdx.HasCopyleft("MIT OR Apache-2.0") // false spdx.HasCopyleft("MIT OR GPL-3.0-only") // true spdx.IsFullyPermissive("MIT OR Apache-2.0") // true spdx.IsFullyPermissive("MIT OR GPL-3.0") // false // Get detailed license info info := spdx.GetLicenseInfo("MIT") // info.Category: CategoryPermissive // info.IsException: false // info.IsDeprecated: false ``` -------------------------------- ### LicenseRef.String Method Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns a string representation of the LicenseRef. This method is part of the fmt.Stringer interface. ```go func (l *LicenseRef) String() string ``` -------------------------------- ### Normalize Informal License String to SPDX Identifier Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use Normalize to convert common informal license names (e.g., 'Apache 2', 'MIT License') into their official SPDX identifiers. Returns an error if normalization fails. ```go func Normalize(license string) (string, error) Normalize("Apache 2") // returns "Apache-2.0", nil Normalize("MIT License") // returns "MIT", nil Normalize("GPL v3") // returns "GPL-3.0-or-later", nil Normalize("UNKNOWN-LICENSE") // returns "", ErrInvalidLicense ``` -------------------------------- ### Check License Compatibility Source: https://pkg.go.dev/github.com/git-pkgs/spdx Determines if a set of provided licenses satisfies a given SPDX license expression. ```go // Check if allowed licenses satisfy an expression satisfied, err := spdx.Satisfies("MIT OR Apache-2.0", []string{"MIT"}) // true satisfied, err := spdx.Satisfies("MIT AND Apache-2.0", []string{"MIT"}) // false (both required) ``` -------------------------------- ### Normalize Informal License Strings Source: https://pkg.go.dev/github.com/git-pkgs/spdx Converts common, informal license names into their official SPDX identifiers. Useful for standardizing license metadata. ```go import "github.com/git-pkgs/spdx" // Normalize converts informal strings to valid SPDX identifiers id, err := spdx.Normalize("Apache 2") // "Apache-2.0" id, err := spdx.Normalize("MIT License") // "MIT" id, err := spdx.Normalize("GPL v3") // "GPL-3.0-or-later" id, err := spdx.Normalize("GNU General Public License") // "GPL-3.0-or-later" id, err := spdx.Normalize("BSD 3-Clause") // "BSD-3-Clause" id, err := spdx.Normalize("CC BY 4.0") // "CC-BY-4.0" ``` -------------------------------- ### Define License Categories Source: https://pkg.go.dev/github.com/git-pkgs/spdx Defines string constants for various license categories used in scancode-licensedb. ```go type Category string const ( CategoryPermissive Category = "Permissive" CategoryCopyleft Category = "Copyleft" CategoryCopyleftLimited Category = "Copyleft Limited" CategoryCommercial Category = "Commercial" CategoryProprietaryFree Category = "Proprietary Free" CategoryPublicDomain Category = "Public Domain" CategoryPatentLicense Category = "Patent License" CategorySourceAvailable Category = "Source-available" CategoryFreeRestricted Category = "Free Restricted" CategoryCLA Category = "CLA" CategoryUnstated Category = "Unstated License" CategoryUnknown Category = "Unknown" ) ``` -------------------------------- ### Parse Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX license expression string into an Expression tree. ```APIDOC ## Parse ```go func Parse(expression string) (Expression, error) ``` Parse parses an SPDX expression string into an Expression tree. It handles both strict SPDX identifiers and informal license names (like "Apache 2" or "MIT License") by normalizing them automatically. ### Parameters - **expression** (string) - The SPDX license expression string to parse. ### Returns - `Expression` - An interface representing the parsed expression tree. - `error` - An error if the expression parsing fails. ### Example ```go // Example usage: // Parse("MIT") returns *License{ID: "MIT"} // Parse("MIT OR Apache-2.0") returns *OrExpression{...} // Parse("mit OR apache 2") normalizes to "MIT OR Apache-2.0" // Parse("GPL v3 AND BSD") normalizes to "GPL-3.0-or-later AND BSD-2-Clause" ``` **Note**: For strict SPDX-only parsing without fuzzy normalization, use `ParseStrict`. ``` -------------------------------- ### Validate Licenses Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks the validity of license strings against the SPDX standard. Can validate entire expressions or individual licenses. ```go // Check if a string is valid SPDX spdx.Valid("MIT OR Apache-2.0") // true spdx.Valid("FAKEYLICENSE") // false // Check if a single identifier is valid spdx.ValidLicense("MIT") // true spdx.ValidLicense("Apache 2") // false (informal, not valid SPDX) // Validate multiple licenses at once valid, invalid := spdx.ValidateLicenses([]string{"MIT", "Apache-2.0", "FAKE"}) // valid: false, invalid: ["FAKE"] ``` -------------------------------- ### LicenseRef.Licenses Method Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns the licenses associated with a LicenseRef. This method is part of the Expression interface. ```go func (l *LicenseRef) Licenses() []string ``` -------------------------------- ### Validate SPDX License Identifier Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use ValidLicense to check if a given string is a recognized and valid SPDX license identifier. ```go func ValidLicense(license string) bool ``` -------------------------------- ### Parse and Normalize License Expressions Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses license expressions, handling both strict SPDX IDs and informal names. Supports operator precedence for complex expressions. ```go // Parse handles both strict SPDX IDs and informal license names expr, err := spdx.Parse("MIT OR Apache-2.0") fmt.Println(expr.String()) // "MIT OR Apache-2.0" expr, err := spdx.Parse("Apache 2 OR MIT License") fmt.Println(expr.String()) // "Apache-2.0 OR MIT" expr, err := spdx.Parse("GPL v3 AND BSD 3-Clause") fmt.Println(expr.String()) // "GPL-3.0-or-later AND BSD-3-Clause" // Handles operator precedence (AND binds tighter than OR) expr, err := spdx.Parse("MIT OR GPL-2.0-only AND Apache-2.0") fmt.Println(expr.String()) // "MIT OR (GPL-2.0-only AND Apache-2.0)" // ParseStrict requires valid SPDX IDs (no fuzzy normalization) expr, err := spdx.ParseStrict("MIT OR Apache-2.0") // succeeds expr, err := spdx.ParseStrict("Apache 2 OR MIT") // fails ``` -------------------------------- ### OrExpression.Licenses Method Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns the licenses associated with an OrExpression. This method aggregates licenses from its left and right sub-expressions. ```go func (e *OrExpression) Licenses() []string ``` -------------------------------- ### Normalize informal license strings Source: https://pkg.go.dev/github.com/git-pkgs/spdx Converts informal license strings found in package metadata to valid SPDX identifiers. ```APIDOC ## Normalize informal license strings ### Description Converts informal license strings to valid SPDX identifiers. ### Function Signature `Normalize(license string) (string, error)` ### Parameters #### Path Parameters - `license` (string) - Required - The informal license string to normalize. ### Request Example ```go id, err := spdx.Normalize("Apache 2") // Returns "Apache-2.0" id, err := spdx.Normalize("MIT License") // Returns "MIT" id, err := spdx.Normalize("GPL v3") // Returns "GPL-3.0-or-later" id, err := spdx.Normalize("GNU General Public License") // Returns "GPL-3.0-or-later" id, err := spdx.Normalize("BSD 3-Clause") // Returns "BSD-3-Clause" id, err := spdx.Normalize("CC BY 4.0") // Returns "CC-BY-4.0" ``` ### Response #### Success Response - `id` (string) - The normalized SPDX identifier. - `err` (error) - An error if normalization fails. #### Response Example ```json { "id": "Apache-2.0", "err": null } ``` ``` -------------------------------- ### Check license compatibility Source: https://pkg.go.dev/github.com/git-pkgs/spdx Determines if a set of allowed licenses satisfies a given SPDX license expression. ```APIDOC ## Check license compatibility ### Description Checks if a list of provided licenses satisfies the requirements of an SPDX license expression. ### Function Signature `Satisfies(expression string, allowedLicenses []string) (bool, error)` ### Parameters #### Path Parameters - `expression` (string) - Required - The SPDX license expression to check against. - `allowedLicenses` ([]string) - Required - A slice of license identifiers that are allowed. ### Request Example ```go satisfied, err := spdx.Satisfies("MIT OR Apache-2.0", []string{"MIT"}) // satisfied: true satisfied, err := spdx.Satisfies("MIT AND Apache-2.0", []string{"MIT"}) // satisfied: false (both required) ``` ### Response #### Success Response - `satisfied` (bool) - `true` if the allowed licenses satisfy the expression, `false` otherwise. - `err` (error) - An error if the check fails. #### Response Example ```json { "satisfied": true, "err": null } ``` ``` -------------------------------- ### Parse Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX license expression string into an Expression object. ```APIDOC ## Parse ### Description Parses an SPDX license expression string into an `Expression` object, which can be used for further analysis or validation. This is the recommended parsing function. ### Function Signature ```go func Parse(expression string) (Expression, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Parse(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **expression** (Expression) - The parsed SPDX expression object. - **error** (error) - An error if the expression is invalid. #### Response Example ```json { "example": ", nil" } ``` ### Error Handling - Returns `ErrEmptyExpression`, `ErrUnexpectedToken`, `ErrUnbalancedParens`, `ErrInvalidLicenseID`, `ErrInvalidException`, `ErrMissingOperand`, or `ErrInvalidSpecialValue` if the expression is invalid. ``` -------------------------------- ### Normalize Source: https://pkg.go.dev/github.com/git-pkgs/spdx Converts an informal license string into a valid SPDX identifier. ```APIDOC ## Normalize ### Description Converts an informal license string to a valid SPDX identifier. It handles common variations like "Apache 2", "MIT License", "GPL v3", etc. Returns the normalized SPDX identifier or an error if normalization fails. ### Function Signature ```go func Normalize(license string) (string, error) ``` ### Parameters #### Path Parameters - **license** (string) - Required - The informal license string to normalize. ### Returns - **string**: The normalized SPDX identifier. - **error**: An error if normalization fails. ### Example ```go Normalize("Apache 2") // returns "Apache-2.0", nil Normalize("MIT License") // returns "MIT", nil Normalize("GPL v3") // returns "GPL-3.0-or-later", nil Normalize("UNKNOWN-LICENSE") // returns "", ErrInvalidLicense ``` ``` -------------------------------- ### License Category Constants Source: https://pkg.go.dev/github.com/git-pkgs/spdx Defines the possible categories for SPDX licenses. ```APIDOC ## Category Type ```go type Category string ``` Category represents a license category from scancode-licensedb. ### Constants - **CategoryPermissive**: Permissive license category. - **CategoryCopyleft**: Copyleft license category. - **CategoryCopyleftLimited**: Limited copyleft license category. - **CategoryCommercial**: Commercial license category. - **CategoryProprietaryFree**: Proprietary but free license category. - **CategoryPublicDomain**: Public domain license category. - **CategoryPatentLicense**: Patent license category. - **CategorySourceAvailable**: Source-available license category. - **CategoryFreeRestricted**: Free but restricted license category. - **CategoryCLA**: Contributor License Agreement category. - **CategoryUnstated**: Unstated license category. - **CategoryUnknown**: Unknown license category. ``` -------------------------------- ### LicenseRef Struct Definition Source: https://pkg.go.dev/github.com/git-pkgs/spdx Defines a custom license reference with optional document and license reference IDs. Use when referring to licenses not in the SPDX list. ```go type LicenseRef struct { DocumentRef string // Optional document reference LicenseRef string // The license reference ID } ``` -------------------------------- ### Extract Licenses from Expressions Source: https://pkg.go.dev/github.com/git-pkgs/spdx Extracts all individual license identifiers present within a complex SPDX license expression. ```go licenses, err := spdx.ExtractLicenses("(MIT AND GPL-2.0-only) OR Apache-2.0") // ["Apache-2.0", "GPL-2.0-only", "MIT"] ``` -------------------------------- ### Check if License is Commercial Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use IsCommercial to identify if a given license string refers to a commercial or proprietary license. ```go func IsCommercial(license string) bool ``` -------------------------------- ### Check if License has Copyleft Requirements Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use IsCopyleft to check if a specific license has copyleft requirements, including full and limited copyleft. ```go func IsCopyleft(license string) bool ``` -------------------------------- ### Valid Source: https://pkg.go.dev/github.com/git-pkgs/spdx Validates an SPDX license expression string. ```APIDOC ## Valid ### Description Validates an SPDX license expression string. Returns true if the expression is a valid SPDX expression, false otherwise. ### Function Signature ```go func Valid(expression string) bool ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Valid(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **isValid** (bool) - True if the expression is valid, false otherwise. #### Response Example ```json { "example": "true" } ``` ### Error Handling None (this function only returns a boolean). ``` -------------------------------- ### Normalize Source: https://pkg.go.dev/github.com/git-pkgs/spdx Normalizes an informal license string to a valid SPDX identifier. ```APIDOC ## Normalize ### Description Normalizes informal license strings (like "Apache 2" or "MIT License") to valid SPDX identifiers (like "Apache-2.0" or "MIT"). ### Function Signature ```go func Normalize(license string) (string, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Normalize(\"Apache 2\")" } ``` ### Response #### Success Response (200) - **normalizedLicense** (string) - The normalized SPDX license identifier. - **error** (error) - An error if normalization fails. #### Response Example ```json { "example": "Apache-2.0, nil" } ``` ### Error Handling - Returns `ErrInvalidLicenseID` if the license string cannot be normalized. ``` -------------------------------- ### Validate Multiple SPDX License Identifiers Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use ValidateLicenses to check if all license identifiers in a slice are valid SPDX identifiers. Returns false and a list of invalid licenses if any are found. ```go func ValidateLicenses(licenses []string) (bool, []string) ``` -------------------------------- ### Parse SPDX Expression (Lax) Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX expression with lax handling of informal license names. Deprecated: Use Parse instead. ```go func ParseLax(expression string) (Expression, error) ``` ```go ParseLax("Apache 2 OR MIT License") // "Apache-2.0 OR MIT" ParseLax("GPL v3 AND BSD 3-Clause") // "GPL-3.0-or-later AND BSD-3-Clause" ``` -------------------------------- ### Check if Allowed Licenses Satisfy SPDX Expression Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use Satisfies to determine if a given set of allowed licenses meets the requirements of an SPDX expression. This is a wrapper for github.com/github/go-spdx/v2/spdxexp.Satisfies. ```go func Satisfies(expression string, allowed []string) (bool, error) ``` -------------------------------- ### Satisfies Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks if a set of allowed licenses satisfies a given SPDX expression. ```APIDOC ## Satisfies ### Description Checks if the allowed licenses satisfy the given SPDX expression. This is a convenience wrapper around github.com/github/go-spdx/v2/spdxexp.Satisfies. ### Function Signature ```go func Satisfies(expression string, allowed []string) (bool, error) ``` ### Parameters #### Path Parameters - **expression** (string) - Required - The SPDX license expression to satisfy. - **allowed** ([]string) - Required - A slice of allowed license identifiers. ### Returns - **bool**: True if the allowed licenses satisfy the expression, false otherwise. - **error**: An error if the check fails. ``` -------------------------------- ### Parse SPDX Expression Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX expression string into an Expression tree, automatically normalizing informal license names. Use this for general-purpose parsing. ```go func Parse(expression string) (Expression, error) ``` ```go Parse("MIT") // *License{ID: "MIT"} Parse("MIT OR Apache-2.0") // *OrExpression{...} Parse("mit OR apache 2") // normalizes to "MIT OR Apache-2.0" Parse("GPL v3 AND BSD") // normalizes to "GPL-3.0-or-later AND BSD-2-Clause" ``` -------------------------------- ### GetLicenseInfo Source: https://pkg.go.dev/github.com/git-pkgs/spdx Retrieves detailed information about a specific license. ```APIDOC ## GetLicenseInfo ```go func GetLicenseInfo(license string) *LicenseInfo ``` GetLicenseInfo returns detailed information about a license. It accepts SPDX identifiers or scancode keys. Returns nil if the license is not found. ### Parameters - **license** (string) - The license identifier (SPDX or scancode key). ### Returns - `*LicenseInfo` - A pointer to a `LicenseInfo` struct containing details about the license, or nil if not found. ### LicenseInfo Struct ```go type LicenseInfo struct { Key string // scancode license key SPDXKey string // primary SPDX identifier Category Category // license category IsException bool // true if this is a license exception IsDeprecated bool // true if deprecated } ``` ``` -------------------------------- ### ValidLicense Source: https://pkg.go.dev/github.com/git-pkgs/spdx Validates if a string is a valid SPDX license identifier. ```APIDOC ## ValidLicense ### Description Checks if the given string is a valid SPDX license identifier. Returns true if valid, false otherwise. ### Function Signature ```go func ValidLicense(license string) bool ``` ### Parameters #### Path Parameters - **license** (string) - Required - The string to validate as an SPDX license identifier. ``` -------------------------------- ### ExpressionCategories Source: https://pkg.go.dev/github.com/git-pkgs/spdx Determines the categories associated with an SPDX license expression. ```APIDOC ## ExpressionCategories ### Description Determines the categories associated with an SPDX license expression. Returns a slice of `Category` structs or an error if parsing fails. ### Function Signature ```go func ExpressionCategories(expression string) ([]Category, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "ExpressionCategories(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **categories** ([]Category) - A slice of `Category` structs representing the categories of the licenses in the expression. - **error** (error) - An error if the expression is invalid. #### Response Example ```json { "example": "[], nil" } ``` ### Error Handling - Returns an error if the expression is invalid. ``` -------------------------------- ### ExtractLicenses Source: https://pkg.go.dev/github.com/git-pkgs/spdx Extracts all unique license identifiers from an SPDX expression. Returns a slice of license identifiers or an error if parsing fails. ```APIDOC ## ExtractLicenses ### Description ExtractLicenses extracts all unique license identifiers from an SPDX expression. Returns a slice of license identifiers or an error if parsing fails. ### Function Signature ```go func ExtractLicenses(expression string) ([]string, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "ExtractLicenses(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **licenses** ([]string) - A slice of unique license identifiers found in the expression. - **error** (error) - An error if the expression parsing fails. #### Response Example ```json { "example": "[\"MIT\", \"Apache-2.0\"], nil" } ``` ### Error Handling - Returns an error if the provided expression is invalid or cannot be parsed. ``` -------------------------------- ### Extract Licenses from SPDX Expression Source: https://pkg.go.dev/github.com/git-pkgs/spdx Extracts all unique license identifiers from an SPDX expression. Returns a slice of license identifiers or an error if parsing fails. ```go func ExtractLicenses(expression string) ([]string, error) ``` ```go ExtractLicenses("MIT OR Apache-2.0") // returns ["MIT", "Apache-2.0"], nil ``` ```go ExtractLicenses("(MIT AND GPL-2.0) OR Apache-2.0") // returns ["Apache-2.0", "GPL-2.0", "MIT"], nil ``` -------------------------------- ### ParseStrict Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX license expression string with strict validation. ```APIDOC ## ParseStrict ### Description Parses an SPDX license expression string with strict validation. Ensures the expression adheres to the most rigorous SPDX specification. ### Function Signature ```go func ParseStrict(expression string) (Expression, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "ParseStrict(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **expression** (Expression) - The strictly parsed SPDX expression object. - **error** (error) - An error if the expression is invalid. #### Response Example ```json { "example": ", nil" } ``` ### Error Handling - Returns an error if the expression is invalid or does not meet strict SPDX standards. ``` -------------------------------- ### Parse and normalize expressions Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses license expressions, handling both strict SPDX IDs and informal license names, and normalizes them. ```APIDOC ## Parse and normalize expressions ### Description Parses license expressions, supporting both strict SPDX identifiers and informal license names. It also handles operator precedence. ### Function Signature `Parse(expression string) (*Expression, error)` ### Parameters #### Path Parameters - `expression` (string) - Required - The license expression string to parse. ### Request Example ```go // Parse handles both strict SPDX IDs and informal license names expr, err := spdx.Parse("MIT OR Apache-2.0") fmt.Println(expr.String()) // Output: "MIT OR Apache-2.0" expr, err := spdx.Parse("Apache 2 OR MIT License") fmt.Println(expr.String()) // Output: "Apache-2.0 OR MIT" expr, err := spdx.Parse("GPL v3 AND BSD 3-Clause") fmt.Println(expr.String()) // Output: "GPL-3.0-or-later AND BSD-3-Clause" // Handles operator precedence (AND binds tighter than OR) expr, err := spdx.Parse("MIT OR GPL-2.0-only AND Apache-2.0") fmt.Println(expr.String()) // Output: "MIT OR (GPL-2.0-only AND Apache-2.0)" ``` ### Response #### Success Response - `expr` (*Expression) - The parsed and normalized license expression. - `err` (error) - An error if parsing fails. #### Response Example ```json { "expr": { "expression": "MIT OR (GPL-2.0-only AND Apache-2.0)" }, "err": null } ``` ## ParseStrict ### Description Requires valid SPDX IDs for parsing. Does not perform fuzzy normalization. ### Function Signature `ParseStrict(expression string) (*Expression, error)` ### Parameters #### Path Parameters - `expression` (string) - Required - The license expression string to parse strictly. ### Request Example ```go expr, err := spdx.ParseStrict("MIT OR Apache-2.0") // succeeds expr, err := spdx.ParseStrict("Apache 2 OR MIT") // fails ``` ``` -------------------------------- ### Satisfies Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks if an SPDX expression satisfies a given set of allowed licenses. ```APIDOC ## Satisfies ### Description Checks if an SPDX expression satisfies a given set of allowed licenses. Returns true if the expression is compatible with the allowed licenses, false otherwise. ### Function Signature ```go func Satisfies(expression string, allowed []string) (bool, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "Satisfies(\"MIT OR Apache-2.0\", []string{\"MIT\", \"BSD-3-Clause\"})" } ``` ### Response #### Success Response (200) - **satisfies** (bool) - True if the expression satisfies the allowed licenses, false otherwise. - **error** (error) - An error if the expression or allowed licenses are invalid. #### Response Example ```json { "example": "false, nil" } ``` ### Error Handling - Returns an error if the expression or any of the allowed licenses are invalid. ``` -------------------------------- ### Normalize SPDX Expression with Lax Handling of Informal Names Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use NormalizeExpressionLax to normalize an SPDX expression, converting informal license names (like 'Apache 2') into their canonical SPDX forms. This is useful for expressions containing non-canonical license names. ```go func NormalizeExpressionLax(expression string) (string, error) NormalizeExpressionLax("Apache 2 OR MIT License") // returns "Apache-2.0 OR MIT", nil NormalizeExpressionLax("GPL v3 AND BSD 3-Clause") // returns "GPL-3.0-or-later AND BSD-3-Clause", nil ``` -------------------------------- ### ExpressionCategories Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns all unique categories for licenses within a given SPDX expression. ```APIDOC ## ExpressionCategories ```go func ExpressionCategories(expression string) ([]Category, error) ``` ExpressionCategories returns all unique categories for licenses in an expression. It parses the expression and returns the category for each license found. ### Parameters - **expression** (string) - The SPDX license expression string. ### Returns - `[]Category` - A slice of unique license categories found in the expression. - `error` - An error if the expression parsing fails. ### Example ```go // Example usage: // ExpressionCategories("MIT OR Apache-2.0") returns []Category{CategoryPermissive} // ExpressionCategories("MIT OR GPL-3.0-only") returns []Category{CategoryPermissive, CategoryCopyleft} ``` ``` -------------------------------- ### Check if License is Permissive Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use IsPermissive to determine if a license belongs to a permissive open-source category, including public domain. ```go func IsPermissive(license string) bool ``` -------------------------------- ### Check if All Licenses in Expression are Permissive Source: https://pkg.go.dev/github.com/git-pkgs/spdx Use IsFullyPermissive to verify if all licenses within an SPDX expression fall under permissive or public domain categories. ```go func IsFullyPermissive(expression string) bool IsFullyPermissive("MIT OR Apache-2.0") // true IsFullyPermissive("MIT AND BSD-3-Clause") // true IsFullyPermissive("MIT OR GPL-3.0-only") // false ``` -------------------------------- ### ValidLicense Source: https://pkg.go.dev/github.com/git-pkgs/spdx Validates a single license identifier string. ```APIDOC ## ValidLicense ### Description Validates a single license identifier string. Returns true if the license identifier is recognized and valid according to the SPDX specification, false otherwise. ### Function Signature ```go func ValidLicense(license string) bool ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "ValidLicense(\"MIT\")" } ``` ### Response #### Success Response (200) - **isValid** (bool) - True if the license identifier is valid, false otherwise. #### Response Example ```json { "example": "true" } ``` ### Error Handling None (this function only returns a boolean). ``` -------------------------------- ### Valid Source: https://pkg.go.dev/github.com/git-pkgs/spdx Validates if a string is a syntactically correct SPDX expression. ```APIDOC ## Valid ### Description Checks if the given string is a valid SPDX expression. This performs strict validation - informal license names like "Apache 2" are not valid. Returns true if valid, false otherwise. ### Function Signature ```go func Valid(expression string) bool ``` ### Parameters #### Path Parameters - **expression** (string) - Required - The string to validate as an SPDX expression. ``` -------------------------------- ### ValidateLicenses Source: https://pkg.go.dev/github.com/git-pkgs/spdx Validates a list of license identifiers to ensure they are all valid SPDX identifiers. ```APIDOC ## ValidateLicenses ### Description Checks if all given license identifiers are valid SPDX identifiers. Returns true and nil if all are valid, or false and the list of invalid licenses. ### Function Signature ```go func ValidateLicenses(licenses []string) (bool, []string) ``` ### Parameters #### Path Parameters - **licenses** ([]string) - Required - A slice of license identifiers to validate. ### Returns - **bool**: True if all licenses are valid, false otherwise. - **[]string**: A slice containing the invalid license identifiers, or nil if all are valid. ``` -------------------------------- ### OrExpression.String Method Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns a string representation of the OrExpression. This method is part of the fmt.Stringer interface. ```go func (e *OrExpression) String() string ``` -------------------------------- ### GetLicenseInfo Source: https://pkg.go.dev/github.com/git-pkgs/spdx Retrieves detailed information about a specific license identifier. ```APIDOC ## GetLicenseInfo ### Description Retrieves detailed information about a specific license identifier. Returns a `LicenseInfo` struct containing metadata about the license. ### Function Signature ```go func GetLicenseInfo(license string) *LicenseInfo ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "GetLicenseInfo(\"MIT\")" } ``` ### Response #### Success Response (200) - **licenseInfo** (*LicenseInfo) - A pointer to a `LicenseInfo` struct containing details about the license. #### Response Example ```json { "example": "" } ``` ### Error Handling None (this function returns a pointer to `LicenseInfo`). ``` -------------------------------- ### IsFullyPermissive Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks if all licenses within an SPDX expression are permissive. ```APIDOC ## IsFullyPermissive ### Description Returns true if all licenses in the expression are permissive. This includes Permissive and Public Domain categories. ### Function Signature ```go func IsFullyPermissive(expression string) bool ``` ### Parameters #### Path Parameters - **expression** (string) - Required - The SPDX license expression to check. ### Example ```go IsFullyPermissive("MIT OR Apache-2.0") // true IsFullyPermissive("MIT AND BSD-3-Clause") // true IsFullyPermissive("MIT OR GPL-3.0-only") // false ``` ``` -------------------------------- ### ParseLax Source: https://pkg.go.dev/github.com/git-pkgs/spdx Parses an SPDX license expression string with lenient validation. Deprecated. ```APIDOC ## ParseLax ### Description Parses an SPDX license expression string with lenient validation. This function is deprecated and `Parse` should be preferred. ### Function Signature ```go func ParseLax(expression string) (Expression, error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "ParseLax(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **expression** (Expression) - The leniently parsed SPDX expression object. - **error** (error) - An error if the expression is invalid. #### Response Example ```json { "example": ", nil" } ``` ### Error Handling - Returns an error if the expression is invalid. ``` -------------------------------- ### String representation of AndExpression Source: https://pkg.go.dev/github.com/git-pkgs/spdx The String method for AndExpression returns a string representation of the AND expression. ```go func (e *AndExpression) String() string ``` -------------------------------- ### SpecialValue Struct Definition Source: https://pkg.go.dev/github.com/git-pkgs/spdx Represents special SPDX license values like NONE or NOASSERTION. Use this for cases where a license cannot be determined or is explicitly not applicable. ```go type SpecialValue struct { Value string } ``` -------------------------------- ### ValidateLicenses Source: https://pkg.go.dev/github.com/git-pkgs/spdx Validates a slice of license identifier strings. ```APIDOC ## ValidateLicenses ### Description Validates a slice of license identifier strings. Returns a boolean indicating if all licenses are valid, and a slice of any invalid license identifiers found. ### Function Signature ```go func ValidateLicenses(licenses []string) (bool, []string) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "ValidateLicenses([]string{\"MIT\", \"Apache-2.0\", \"InvalidLicense\"})" } ``` ### Response #### Success Response (200) - **allValid** (bool) - True if all license identifiers in the slice are valid, false otherwise. - **invalidLicenses** ([]string) - A slice containing any license identifiers that were found to be invalid. #### Response Example ```json { "example": "false, [\"InvalidLicense\"]" } ``` ### Error Handling None (this function returns a boolean and a slice of strings). ``` -------------------------------- ### IsFullyPermissive Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks if an SPDX license expression is fully permissive. ```APIDOC ## IsFullyPermissive ### Description Checks if an SPDX license expression is fully permissive. Returns true if all licenses within the expression are permissive, false otherwise. ### Function Signature ```go func IsFullyPermissive(expression string) bool ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "IsFullyPermissive(\"MIT OR Apache-2.0\")" } ``` ### Response #### Success Response (200) - **isFullyPermissive** (bool) - True if the expression is fully permissive, false otherwise. #### Response Example ```json { "example": "true" } ``` ### Error Handling None (this function only returns a boolean). ``` -------------------------------- ### Extract licenses from expressions Source: https://pkg.go.dev/github.com/git-pkgs/spdx Extracts all unique license identifiers present within an SPDX license expression. ```APIDOC ## Extract licenses from expressions ### Description Extracts all unique license identifiers found within a given SPDX license expression. ### Function Signature `ExtractLicenses(expression string) ([]string, error)` ### Parameters #### Path Parameters - `expression` (string) - Required - The SPDX license expression from which to extract licenses. ### Request Example ```go licenses, err := spdx.ExtractLicenses("(MIT AND GPL-2.0-only) OR Apache-2.0") // licenses: ["Apache-2.0", "GPL-2.0-only", "MIT"] ``` ### Response #### Success Response - `licenses` ([]string) - A slice of unique license identifiers found in the expression. - `err` (error) - An error if extraction fails. #### Response Example ```json { "licenses": ["Apache-2.0", "GPL-2.0-only", "MIT"], "err": null } ``` ``` -------------------------------- ### SpecialValue.Licenses Method Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns the special value as a single-element string slice. This method is part of the Expression interface. ```go func (s *SpecialValue) Licenses() []string ``` -------------------------------- ### IsCopyleft Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks if a specific license has copyleft requirements. ```APIDOC ## IsCopyleft ### Description Returns true if the license has copyleft requirements. This includes both full Copyleft and Copyleft Limited (weak copyleft). ### Function Signature ```go func IsCopyleft(license string) bool ``` ### Parameters #### Path Parameters - **license** (string) - Required - The license identifier to check. ``` -------------------------------- ### LicenseRef Type Source: https://pkg.go.dev/github.com/git-pkgs/spdx Represents a custom license reference with an optional document reference and a license reference ID. ```APIDOC ## type LicenseRef ```go type LicenseRef struct { DocumentRef string // Optional document reference LicenseRef string // The license reference ID } ``` LicenseRef represents a custom license reference. ### Methods #### Licenses() ```go func (l *LicenseRef) Licenses() []string ``` Returns the licenses associated with this LicenseRef. #### String() ```go func (l *LicenseRef) String() string ``` Returns the string representation of the LicenseRef. ``` -------------------------------- ### Validate licenses Source: https://pkg.go.dev/github.com/git-pkgs/spdx Checks the validity of SPDX license expressions and individual license identifiers. ```APIDOC ## Validate licenses ### Description Provides functions to check if a given string is a valid SPDX license expression or a valid individual SPDX license identifier. ### Function Signatures `Valid(expression string) bool` `ValidLicense(license string) bool` `ValidateLicenses(licenses []string) (bool, []string) ### Parameters #### Path Parameters - `expression` (string) - Required - The license expression to validate. - `license` (string) - Required - The individual license identifier to validate. - `licenses` ([]string) - Required - A slice of license identifiers to validate. ### Request Example ```go // Check if a string is valid SPDX spdx.Valid("MIT OR Apache-2.0") // Returns true spdx.Valid("FAKEYLICENSE") // Returns false // Check if a single identifier is valid spdx.ValidLicense("MIT") // Returns true spdx.ValidLicense("Apache 2") // Returns false (informal, not valid SPDX) // Validate multiple licenses at once valid, invalid := spdx.ValidateLicenses([]string{"MIT", "Apache-2.0", "FAKE"}) // valid: false, invalid: ["FAKE"] ``` ### Response #### Success Response - `Valid` returns `true` if the expression is valid, `false` otherwise. - `ValidLicense` returns `true` if the license identifier is valid, `false` otherwise. - `ValidateLicenses` returns a boolean indicating if all licenses were valid, and a slice of invalid license identifiers. #### Response Example ```json { "Valid": true, "ValidLicense": true, "ValidateLicenses": { "valid": false, "invalid": ["FAKE"] } } ``` ``` -------------------------------- ### SpecialValue.String Method Source: https://pkg.go.dev/github.com/git-pkgs/spdx Returns the string representation of the special value (e.g., "NONE"). This method is part of the fmt.Stringer interface. ```go func (s *SpecialValue) String() string ```