Skip to content

🔍 ValidateSchema

Only validates the JSON schema of composer.json and composer.lock, without checking platform requirements, publishing requirements, or version constraints. Equivalent to running composer validate --no-check-all --no-check-publish --no-check-version.

When to use

Use this when you only care about whether the file structure is valid (whether fields exist, whether types are correct), and not about platform compatibility or Packagist publishing fields. Suitable for lightweight validation in editor plugins or quick pre-check scripts.

Signature

go
func (c *Composer) ValidateSchema() (string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuestringRaw output of the validation command
Second return valueerrorReturned when the schema is invalid or execution fails

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	output, err := comp.ValidateSchema()
	if err != nil {
		log.Fatalf("schema validation failed: %v\noutput: %s", err, output)
	}
	fmt.Println("JSON schema validation passed")
}

Advanced

  • For full strict validation, use ValidateStrict.
  • To only validate composer.lock sync, use ValidateComposerLock.
  • To customize the combination of validation options, use ValidateWithOptions(options).
  • For structured results (distinguishing errors / warnings), use ValidateStructured.

Released under the MIT License