RFC 9457 Problem Details JSON parser, serializer, validator, registry and audit toolkit for MoonBit.
moon add 6P66006/moon-problem-detailsimport {
"6P66006/moon-problem-details" @problem,
}moon check --target wasm-gc
moon run ./examples/parse --target wasm-gcpython ./scripts/verify_iana_snapshot.pymoon run ./cmd/problem-tool -- parse --input '{"status":404}'
moon run ./cmd/problem-tool -- validate --status 404 --input '{"status":404}'
moon run ./cmd/problem-tool -- registry about:blank
moon run ./cmd/problem-tool -- make --status 404 --title "Not Found"
moon run ./cmd/problem-tool -- batch --input '{"title":"Not Found","status":404}' --input '{"status":500}'moon run ./cmd/problem-tool -- parse --input '{"title":123,"status":404,"request_id":"abc"}'.\scripts\verify_all.ps1pub struct AuditIssue {
kind : AuditIssueKind
severity : AuditSeverity
context : String
} derive(Eq, Debug)pub struct ExtensionFrequency {
name : String
count : Int
}pub struct ProblemBatchPolicy {
max_documents : Int
max_parse_failures : Int
max_semantic_issues : Int
max_audit_issues : Int
max_unregistered_types : Int
require_title : Bool
require_status : Bool
allow_relative_types : Bool
}fn ProblemBatchPolicy::with_allow_relative_types(self : ProblemBatchPolicy, value : Bool) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_max_audit_issues(self : ProblemBatchPolicy, value : Int) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_max_documents(self : ProblemBatchPolicy, value : Int) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_max_parse_failures(self : ProblemBatchPolicy, value : Int) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_max_semantic_issues(self : ProblemBatchPolicy, value : Int) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_max_unregistered_types(self : ProblemBatchPolicy, value : Int) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_require_status(self : ProblemBatchPolicy, value : Bool) -> ProblemBatchPolicyfn ProblemBatchPolicy::with_require_title(self : ProblemBatchPolicy, value : Bool) -> ProblemBatchPolicypub struct ProblemBatchReport {
input_count : Int
parsed_count : Int
parse_failure_count : Int
diagnostic_count : Int
semantic_issue_count : Int
audit_issue_count : Int
about_blank_count : Int
registered_type_count : Int
unregistered_type_count : Int
relative_type_count : Int
missing_title_count : Int
missing_status_count : Int
total_member_count : Int
max_member_count : Int
informational_status_count : Int
successful_status_count : Int
redirection_status_count : Int
client_error_status_count : Int
server_error_status_count : Int
other_status_count : Int
type_frequencies : Array[ProblemTypeFrequency]
status_frequencies : Array[ProblemStatusFrequency]
extension_frequencies : Array[ExtensionFrequency]
findings : Array[BatchFinding]
decision : BatchDecision
quality_score : Int
}fn ProblemBatchReport::extension_frequencies(self : ProblemBatchReport) -> Array[ExtensionFrequency]fn ProblemBatchReport::status_frequencies(self : ProblemBatchReport) -> Array[ProblemStatusFrequency]pub struct ProblemBuilder {
type_raw : String?
title : String?
status : Int?
detail : String?
instance : String?
extensions : Array[ExtensionMember]
error : ProblemError?
}pub struct ProblemDetails {
type_raw : String?
title : String?
status : Int?
detail : String?
instance : String?
extensions : Array[ExtensionMember]
} derive(Eq, Debug)pub struct ProblemDiagnostic {
kind : ProblemDiagnosticKind
member_name : String
expected : String
actual : String
} derive(Eq, Debug)pub struct ProblemParseResult {
problem : ProblemDetails
diagnostics : Array[ProblemDiagnostic]
} derive(Eq, Debug)pub struct ProblemStatusFrequency {
status : Int?
count : Int
}pub struct ProblemTypeFrequency {
type_uri : String
count : Int
}fn analyze_problem_batch(inputs : Array[String], policy? : ProblemBatchPolicy, limits? : Limits) -> ProblemBatchReportfn parse_problem_json_bytes(input : Bytes, limits? : Limits) -> Result[ProblemParseResult, ProblemError]fn parse_problem_json_with_limits(input : String, limits : Limits) -> Result[ProblemParseResult, ProblemError]fn problem_context(actual_status : Int?, content_type : String?, base_uri : String?) -> ProblemContextfn problem_details(type_raw : String?, title : String?, status : Int?, detail : String?, instance : String?, extensions : Array[ExtensionMember]) -> ProblemDetailsfn problem_error(stage : ProblemErrorStage, kind : ProblemErrorKind, context : String, byte_offset? : Int) -> ProblemErrorfn problem_type_record(type_uri : String, title : String, recommended_status : Int?, reference : String) -> ProblemTypeRecordfn status_reason(code : Int) -> String?RFC 9457 Problem Details JSON parser, serializer, validator, registry and audit toolkit for MoonBit.