
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
github.com/CrisisTextLine/modular/modules/jsonschema
A Modular module that provides JSON Schema validation capabilities.
The JSON Schema module provides a service for validating JSON data against JSON Schema specifications. It wraps github.com/santhosh-tekuri/jsonschema/v6 to provide a clean, service-oriented interface that integrates with the Modular framework.
go get github.com/CrisisTextLine/modular/modules/jsonschema@v1.0.0
import (
"github.com/CrisisTextLine/modular"
"github.com/CrisisTextLine/modular/modules/jsonschema"
)
func main() {
app := modular.NewStdApplication(
modular.NewStdConfigProvider(nil),
logger,
)
// Register the JSON Schema module
app.RegisterModule(jsonschema.NewModule())
// Register your modules that depend on the schema service
app.RegisterModule(NewYourModule())
// Run the application
if err := app.Run(); err != nil {
logger.Error("Application error", "error", err)
}
}
type YourModule struct {
schemaService jsonschema.JSONSchemaService
}
// Request the JSON Schema service
func (m *YourModule) RequiresServices() []modular.ServiceDependency {
return []modular.ServiceDependency{
{
Name: "jsonschema.service",
Required: true,
SatisfiesInterface: reflect.TypeOf((*jsonschema.JSONSchemaService)(nil)).Elem(),
},
}
}
// Inject the service using constructor injection
func (m *YourModule) Constructor() modular.ModuleConstructor {
return func(app *modular.StdApplication, services map[string]any) (modular.Module, error) {
schemaService, ok := services["jsonschema.service"].(jsonschema.JSONSchemaService)
if !ok {
return nil, fmt.Errorf("service 'jsonschema.service' not found or wrong type")
}
return &YourModule{
schemaService: schemaService,
}, nil
}
}
// Example of using the schema service
func (m *YourModule) ValidateData(schemaPath string, data []byte) error {
// Compile the schema
schema, err := m.schemaService.CompileSchema(schemaPath)
if err != nil {
return fmt.Errorf("failed to compile schema: %w", err)
}
// Validate data against the schema
if err := m.schemaService.ValidateBytes(schema, data); err != nil {
return fmt.Errorf("validation failed: %w", err)
}
return nil
}
type Schema interface {
// Validate validates the given value against the JSON schema
Validate(value interface{}) error
}
type JSONSchemaService interface {
// CompileSchema compiles a JSON schema from a file path or URL
CompileSchema(source string) (Schema, error)
// ValidateBytes validates raw JSON data against a compiled schema
ValidateBytes(schema Schema, data []byte) error
// ValidateReader validates JSON from an io.Reader against a compiled schema
ValidateReader(schema Schema, reader io.Reader) error
// ValidateInterface validates a Go interface{} against a compiled schema
ValidateInterface(schema Schema, data interface{}) error
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.