Moved JSON response schemas into separate files
This commit is contained in:
@@ -2,6 +2,7 @@ package responseschema
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"embed"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -20,6 +21,9 @@ const (
|
||||
schemaVersionV1 = "v1"
|
||||
)
|
||||
|
||||
//go:embed assets/*.json
|
||||
var schemaAssets embed.FS
|
||||
|
||||
// Schema describes one registered structured response schema.
|
||||
type Schema struct {
|
||||
ID string `json:"id"`
|
||||
@@ -39,17 +43,17 @@ func (s Schema) DiagnosticsMap() map[string]any {
|
||||
}
|
||||
|
||||
var registry = map[Key]Schema{
|
||||
CorrectionSetKey: mustBuildSchema(
|
||||
CorrectionSetKey: mustBuildSchemaFromAsset(
|
||||
correctionSetSchemaID,
|
||||
schemaVersionV1,
|
||||
"audita_correction_set_v1",
|
||||
[]byte(`{"type":"object","additionalProperties":false,"required":["corrections"],"properties":{"corrections":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["id","original_text","corrected_text","confidence"],"properties":{"id":{"type":"integer","minimum":1},"original_text":{"type":"string","minLength":1},"corrected_text":{"type":"string","minLength":1},"confidence":{"type":"number","minimum":0,"maximum":1}}}}}}`),
|
||||
"assets/correction_set.v1.json",
|
||||
),
|
||||
ValidatorDecisionSetKey: mustBuildSchema(
|
||||
ValidatorDecisionSetKey: mustBuildSchemaFromAsset(
|
||||
validatorDecisionSchemaID,
|
||||
schemaVersionV1,
|
||||
"audita_validator_decision_set_v1",
|
||||
[]byte(`{"type":"object","additionalProperties":false,"required":["validations"],"properties":{"validations":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["correction_index","approved","confidence","reason"],"properties":{"correction_index":{"type":"integer","minimum":0},"approved":{"type":"boolean"},"confidence":{"type":"number","minimum":0,"maximum":1},"reason":{"type":"string"}}}}}}`),
|
||||
"assets/validator_decision_set.v1.json",
|
||||
),
|
||||
}
|
||||
|
||||
@@ -93,6 +97,14 @@ func cloneSchema(in Schema) Schema {
|
||||
return out
|
||||
}
|
||||
|
||||
func mustBuildSchemaFromAsset(id string, version string, name string, assetPath string) Schema {
|
||||
rawSchema, err := schemaAssets.ReadFile(assetPath)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("read response schema asset %q: %v", assetPath, err))
|
||||
}
|
||||
return mustBuildSchema(id, version, name, rawSchema)
|
||||
}
|
||||
|
||||
func mustBuildSchema(id string, version string, name string, rawSchema []byte) Schema {
|
||||
id = strings.TrimSpace(id)
|
||||
version = strings.TrimSpace(version)
|
||||
|
||||
Reference in New Issue
Block a user