zweidenker / jsonschema Goto Github PK
View Code? Open in Web Editor NEWImplementation of JSON schema for pharo
License: MIT License
Implementation of JSON schema for pharo
License: MIT License
In large specs where schemas are reused within the spec schemas are stored at a central place. In JSON schema this is in defintions. At the moment schemas are resolved to objects. That opens the problem that schema with definitions can be parsed but on writing the definitions are gone and the schemas are written everywhere again where they are used
The maxLength
exceeded message in JSONSchemaLengthConstraint>>#validate:
references minLength
which might be nil:
Also maxLength
has to be used here anyway.
At the moment a schema can hold an array for required fields but the writing does not treat it that way
The JSONSchema>>#enum:
helper method creates a string schema although enum
can be defined on all types. As this is maybe used in existing code it might make sense to add a deprecation notice once the "fix" path is clear.
If the schema does not provide a type
property an invalid schema JSONSchemaAnyObject
might be produced. I.e. the following code does not raise an exception as required:
|schema|
schema := JSONSchema fromString: '{"exclusiveMaximum":10}'.
schema validate: 11.
Adding a type
property leads to the right schema being produced (JSONSchemaNumber
) incl. matching constraints:
|schema|
schema := JSONSchema fromString: '{"type":"number","exclusiveMaximum":10}'.
schema validate: 11.
I'm not 100% sure if type
is a required property and thus schemas not specifing it might be invalid. However from reading the spec (and the test cases) I strongly assume that a schema without a type
property is indeed valid. If this is the case the complete framework might have to be reorganized because it's (type
) existence seems to be a very basic low-level assumption the framwork relies on.
The following is the list of formats specified in the JSON Schema specification.
"date-time": Date representation, as defined by RFC 3339, section 5.6.
"email": Internet email address, see RFC 5322, section 3.4.1.
"hostname": Internet host name, see RFC 1034, section 3.1.
"ipv4": IPv4 address, according to dotted-quad ABNF syntax as defined in RFC 2673, section 3.2.
"ipv6": IPv6 address, as defined in RFC 2373, section 2.2.
"uri": A universal resource identifier (URI), according to RFC3986.
"uri-reference": New in draft 6 A URI Reference (either a URI or a relative-reference), according to RFC3986, section 4.1.
"json-pointer": New in draft 6 A JSON Pointer, according to RFC6901. There is more discussion on the use of JSON Pointer within JSON Schema in Structuring a complex schema. Note that this should be used only when the entire string contains only JSON Pointer content, e.g. /foo/bar. JSON Pointer URI fragments, e.g. #/foo/bar/ should use "uri" or "uri-reference".
"uri-template": New in draft 6 A URI Template (of any level) according to RFC6570. If you don’t already know what a URI Template is, you probably don’t need this value.
Reading behaviour in schema objects is incoherent and misleading. Needs separation to read from string or from dictionary. Interface should be same for primitive, objects and lists
{
#name -> nil.
#dateAndTime -> (JSONSchema stringWithFormat: 'date-time').
#numberOfPets -> JSONSchema number } asJSONSchema
#asJSONSchema was sent to nil on ( #name -> nil) association
This package is throwing an error when being loaded in pharo 9 Win 64 (windows 10) as part of pharo-nosql/voyage baseline
failed to stat "C:/Users/xxxx/xxxxxxxx/Pharo/images/p9-xxxxx/pharo-local/iceberg/zweidenker/JSONSchema/source/JSONSchema-Testsuite-Tests.package/JSONSchemaAdditionalPropertiesBeingFalseDoesNotAllowOtherPropertiesTests.class/instance/testPatternPropertiesAreNotAdditionalProperties.st': The filename or extension is too long.
"
but strangely this seems to work in Pharo 8 Win 64 (Windows 10)
Currently array validation fails if items
is not set:
|schema|
schema := JSONSchema fromString: '{
"type": "array"
}'.
schema validate: #(1 2)
The code works if you have items
set however:
|schema|
schema := JSONSchema fromString: '{
"type": "array",
"items": { "type":"number" }
}'.
schema validate: #(1 2).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.