Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions source/JSONSchema-Core/JSONFormatDate.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ JSONFormatDate class >> basicConvertString: aString [
^ Date fromString: aString
]

{ #category : 'as yet unclassified' }
JSONFormatDate class >> encodeJSON: aDate [
^ aDate yyyymmdd
]

{ #category : 'validation' }
JSONFormatDate class >> daysInMonth: aMonth year: aYear [
| leap |
Expand All @@ -24,6 +19,11 @@ JSONFormatDate class >> daysInMonth: aMonth year: aYear [
^ #(31 28 31 30 31 30 31 31 30 31 30 31) at: aMonth
]

{ #category : 'as yet unclassified' }
JSONFormatDate class >> encodeJSON: aDate [
^ aDate yyyymmdd
]

{ #category : 'formatting' }
JSONFormatDate class >> formatName [
^ #date
Expand All @@ -44,12 +44,6 @@ JSONFormatDate class >> isValidFullDate: aString [
^ (month between: 1 and: 12) and: [ day between: 1 and: (self daysInMonth: month year: year) ]
]

{ #category : 'validation' }
JSONFormatDate class >> validateString: aString [
(self isValidFullDate: aString) ifFalse: [
JSONConstraintError signal: aString printString, ' is not a valid date' ]
]

{ #category : 'services' }
JSONFormatDate class >> validate: aDate [
(aDate isKindOf: Date) ifFalse: [
Expand All @@ -58,6 +52,12 @@ JSONFormatDate class >> validate: aDate [

]

{ #category : 'validation' }
JSONFormatDate class >> validateString: aString [
(self isValidFullDate: aString) ifFalse: [
JSONConstraintError signal: aString printString, ' is not a valid date' ]
]

{ #category : 'writing' }
JSONFormatDate class >> write: aDate [
"convert to DateaAndTime without the sub-second precision"
Expand Down
12 changes: 6 additions & 6 deletions source/JSONSchema-Core/JSONFormatDateTime.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ JSONFormatDateTime class >> isValidDateTime: aString [
^ (JSONFormatDate isValidFullDate: datePart) and: [ JSONFormatTime isValidString: timePart ]
]

{ #category : 'validation' }
JSONFormatDateTime class >> validateString: aString [
(self isValidDateTime: aString) ifFalse: [
JSONConstraintError signal: aString printString, ' is not a valid date-time' ]
]

{ #category : 'services' }
JSONFormatDateTime class >> validate: aDate [
(aDate isKindOf: DateAndTime) ifFalse: [
Expand All @@ -47,6 +41,12 @@ JSONFormatDateTime class >> validate: aDate [

]

{ #category : 'validation' }
JSONFormatDateTime class >> validateString: aString [
(self isValidDateTime: aString) ifFalse: [
JSONConstraintError signal: aString printString, ' is not a valid date-time' ]
]

{ #category : 'writing' }
JSONFormatDateTime class >> write: aDateAndTime [
"convert to DateaAndTime without the sub-second precision"
Expand Down
16 changes: 8 additions & 8 deletions source/JSONSchema-Core/JSONFormatURI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ JSONFormatURI class >> formatName [
^ #uri
]

{ #category : 'services' }
JSONFormatURI class >> validate: aUrl [
(aUrl isKindOf: ZnUrl) ifFalse: [
JSONTypeError
signal: aUrl printString , ' is not a URL' ]

]

{ #category : 'validation' }
JSONFormatURI class >> isValidURIAuthority: anAuthority [
"authority = [ userinfo @ ] host [ : port ]. Necessary check: after stripping any
Expand Down Expand Up @@ -84,6 +76,14 @@ JSONFormatURI class >> legalURICharacters [
^ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~:/?#[]@!$&''()*+,;=%'
]

{ #category : 'services' }
JSONFormatURI class >> validate: aUrl [
(aUrl isKindOf: ZnUrl) ifFalse: [
JSONTypeError
signal: aUrl printString , ' is not a URL' ]

]

{ #category : 'validation' }
JSONFormatURI class >> validateString: aString [
(self isValidURIString: aString allowUnicode: false) ifFalse: [
Expand Down
13 changes: 9 additions & 4 deletions source/JSONSchema-Core/JSONPrimitiveSchema.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ JSONPrimitiveSchema >> initialize [
]

{ #category : 'accessing' }
JSONPrimitiveSchema >> nullable: aBoolean [
nullable := aBoolean
JSONPrimitiveSchema >> nullable [
"Unset (not explicitly declared) defaults to permissive: nested property
schemas are parsed via base JSONSchemaDefinition, which does not carry the
OpenAPI-3.0-only 'nullable' keyword, so most real-world nullable fields
never reach here as true. Erring towards accepting null is the safe
direction for a response reader; explicit false is still honored."
^ nullable ~~ false
]

{ #category : 'reading' }
Expand Down Expand Up @@ -111,7 +116,7 @@ JSONPrimitiveSchema >> readUsing: aReader [
| value |
value := aReader parseValue.
value ifNil: [
nullable
self nullable
ifTrue: [ ^ nil ]
ifFalse: [ JSONTypeError signal: self class typeName, ' cannot be nil' ] ].
^ self read: value
Expand All @@ -138,7 +143,7 @@ JSONPrimitiveSchema >> write: anObject [
{ #category : 'writing' }
JSONPrimitiveSchema >> write: anObject on: aWriter [
anObject ifNil: [
nullable ifTrue: [
self nullable ifTrue: [
^ aWriter writeNull ] ].
self validate: anObject.
aWriter nextPut: anObject
Expand Down
5 changes: 5 additions & 0 deletions source/JSONSchema-Core/JSONSchemaAnyObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ JSONSchemaAnyObject >> acceptJSONSchema: aVisitor [
^ aVisitor visitAnyObject: self
]

{ #category : 'reading-primitive data' }
JSONSchemaAnyObject >> read: anObject [
^ anObject
]

{ #category : 'reading' }
JSONSchemaAnyObject >> read: string object: object [
| json |
Expand Down
6 changes: 4 additions & 2 deletions source/JSONSchema-Core/JSONSchemaArray.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ JSONSchemaArray >> items: aSchema [

{ #category : 'meta-object-protocol' }
JSONSchemaArray >> read: aCollection [
items isCollection
^ items isCollection
ifTrue: [
items withIndexCollect: [ :item :idx |
"tuple validation: items is an array of per-position schemas"
aCollection withIndexCollect: [ :item :idx |
(items at: idx) read: item ] ]
ifFalse: [
"homogeneous array: items is a single schema applied to every element"
aCollection collect: [ :item |
items read: item ] ]
]
Expand Down
Loading
Loading