openapi json model, processing & parsing fixes

This commit is contained in:
timurgordon
2025-01-30 04:53:08 +03:00
parent ee8fbbca09
commit 5cb30e6783
5 changed files with 101 additions and 11 deletions

View File

@@ -1,10 +1,11 @@
module jsonschema
import x.json2 { Any }
import json
pub fn decode(data string) !Schema {
schema_map := json2.raw_decode(data)!.as_map()
mut schema := json2.decode[Schema](data)!
mut schema := json.decode(Schema, data)!
for key, value in schema_map {
if key == 'properties' {
schema.properties = decode_schemaref_map(value.as_map())!

View File

@@ -8,7 +8,7 @@ pub type SchemaRef = Reference | Schema
pub struct Reference {
pub:
ref string @[json: 'ref']
ref string @[json: '\$ref']
}
pub type Number = int
@@ -21,10 +21,10 @@ pub mut:
title string @[omitempty]
description string @[omitempty]
typ string @[json: 'type'; omitempty]
properties map[string]SchemaRef @[omitempty]
properties map[string]SchemaRef @[json: '-'; omitempty]
additional_properties SchemaRef @[json: 'additionalProperties'; omitempty]
required []string @[omitempty]
items Items @[omitempty]
items Items @[json: '-'; omitempty]
defs map[string]SchemaRef @[omitempty]
one_of []SchemaRef @[json: 'oneOf'; omitempty]
format string @[omitempty]