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
7 changes: 3 additions & 4 deletions source/BaselineOfOpenAPI/BaselineOfOpenAPI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ BaselineOfOpenAPI >> baseline: spec [
package: 'OpenAPI-Core-Tests' with: [ spec requires: #('OpenAPI-Core' 'JSONSchema Tests'). ];
package: 'OpenAPI-REST' with: [ spec requires: #('OpenAPI-Core' 'ZincHTTPComponents') ];
package: 'OpenAPI-REST-Tests' with: [ spec requires: #('OpenAPI-REST') ];
package: 'OpenAPI-Client' with: [ spec requires: #('OpenAPI-Core') ].

package: 'OpenAPI-Client' with: [ spec requires: #('OpenAPI-Core') ];
package: 'OpenAPI-Client-Tests' with: [ spec requires: #('OpenAPI-Client') ].
spec
group: 'default' with: #('Core' 'REST' 'Client' 'Tests');
group: 'Core' with: #('OpenAPI-Core');
group: 'REST' with: #('Core' 'OpenAPI-REST');
group: 'Client' with: #('Core' 'OpenAPI-Client');
group: 'Tests' with: #('OpenAPI-Core-Tests' 'OpenAPI-REST-Tests').

group: 'Tests' with: #('OpenAPI-Core-Tests' 'OpenAPI-REST-Tests' 'OpenAPI-Client-Tests').
self
neoJson: spec;
zinHTTPComponents: spec;
Expand Down
78 changes: 78 additions & 0 deletions source/OpenAPI-Client-Tests/OARequestBuilderTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Class {
#name : 'OARequestBuilderTest',
#superclass : 'TestCase',
#category : 'OpenAPI-Client-Tests-Tests',
#package : 'OpenAPI-Client-Tests',
#tag : 'Tests'
}

{ #category : 'tests' }
OARequestBuilderTest >> testAddFormBodyBuildsFormUrlEncodedEntity [
| client builder entity |
client := ZnClient new.
builder := OARequestBuilder new client: client.
builder addFormBody: (Dictionary new at: 'email' put: 'test@example.com'; yourself).
entity := client request entity.
self assert: entity contentType sub equals: 'x-www-form-urlencoded'.
self assert: (entity contents at: 'email') equals: 'test@example.com'
]

{ #category : 'tests' }
OARequestBuilderTest >> testFlattenArrayOfObjects [
| builder result items |
items := OrderedCollection new
add: (Dictionary new at: 'price' put: 'price_abc'; at: 'quantity' put: '1'; yourself);
yourself.
builder := OARequestBuilder new.
result := builder flattenFormParameters: (Dictionary new at: 'items' put: items; yourself).
self assert: (result at: 'items[0][price]') equals: 'price_abc'.
self assert: (result at: 'items[0][quantity]') equals: '1'
]

{ #category : 'tests' }
OARequestBuilderTest >> testFlattenDeeplyNestedObject [
| builder result nested |
nested := Dictionary new
at: 'end_behavior' put: (Dictionary new at: 'missing_payment_method' put: 'cancel'; yourself);
yourself.
builder := OARequestBuilder new.
result := builder flattenFormParameters: (Dictionary new at: 'trial_settings' put: nested; yourself).
self assert: (result at: 'trial_settings[end_behavior][missing_payment_method]') equals: 'cancel'
]

{ #category : 'tests' }
OARequestBuilderTest >> testFlattenNestedDictionary [
| builder result |
builder := OARequestBuilder new.
result := builder flattenFormParameters: (Dictionary new
at: 'metadata' put: (Dictionary new at: 'apptiveid' put: 'acc_42'; yourself);
yourself).
self assert: (result at: 'metadata[apptiveid]') equals: 'acc_42'
]

{ #category : 'tests' }
OARequestBuilderTest >> testFlattenNestedOrderedDictionary [
"NeoJSON-produced objects (NeoJSONObject/OrderedDictionary) must flatten the
same way as plain Dictionary - this is what schema-validated request bodies
actually are, not a hand-built Dictionary."
| builder result neoObject |
neoObject := NeoJSONObject new.
neoObject at: 'apptiveid' put: 'acc_42'.
builder := OARequestBuilder new.
result := builder flattenFormParameters: (Dictionary new
at: 'metadata' put: neoObject;
yourself).
self assert: (result at: 'metadata[apptiveid]') equals: 'acc_42'
]

{ #category : 'tests' }
OARequestBuilderTest >> testFlattenScalarValues [
| builder result |
builder := OARequestBuilder new.
result := builder flattenFormParameters: (Dictionary new
at: 'customer' put: 'cus_123';
at: 'trial_end' put: 'now';
yourself).
self assert: (result at: 'customer') equals: 'cus_123'.
self assert: (result at: 'trial_end') equals: 'now'
]
1 change: 1 addition & 0 deletions source/OpenAPI-Client-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'OpenAPI-Client-Tests' }
2 changes: 1 addition & 1 deletion source/OpenAPI-Client/OARequestBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ OARequestBuilder >> flattenFormParameters: anObject prefix: aPrefixString into:
anObject isString ifTrue: [
aDictionary at: aPrefixString put: anObject.
^ self ].
(anObject isKindOf: Dictionary) ifTrue: [
((anObject isKindOf: Dictionary) or: [ anObject isKindOf: OrderedDictionary ]) ifTrue: [
anObject keysAndValuesDo: [ :k :v |
self
flattenFormParameters: v
Expand Down
5 changes: 5 additions & 0 deletions source/OpenAPI-Client/OpenApiClient.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ OpenApiClient >> call: aString withArguments: aCollection [

]

{ #category : 'requests' }
OpenApiClient >> handleError: anObject request: aRequest response: aResponse [
^ self handleError: anObject response: aResponse
]

{ #category : 'as yet unclassified' }
OpenApiClient >> handleError: anObject response: aResponse [
(OAUnspecifiedError new
Expand Down
6 changes: 6 additions & 0 deletions source/OpenAPI-Core/JSONSchemaAnyObject.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : 'JSONSchemaAnyObject' }

{ #category : '*OpenAPI-Core' }
JSONSchemaAnyObject >> acceptOpenApi: aVisitor [
^ self
]
12 changes: 12 additions & 0 deletions source/OpenAPI-Core/OAMediaTypeObject.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ OAMediaTypeObject >> encoding [
^ encoding
]

{ #category : 'accessing' }
OAMediaTypeObject >> encoding: aDictionary [
encoding := aDictionary
]

{ #category : 'as yet unclassified' }
OAMediaTypeObject >> example [
^ example
Expand Down Expand Up @@ -108,3 +113,10 @@ OAMediaTypeObject >> writeBody: aDictionary builder: builder [
ifFalse: [ schema readObject: aDictionary ])

]

{ #category : 'as yet unclassified' }
OAMediaTypeObject >> writeFormBody: aDictionary builder: builder [
builder addFormBody: (schema isAnyObject
ifTrue: [ aDictionary ]
ifFalse: [ schema readObject: aDictionary ])
]
14 changes: 9 additions & 5 deletions source/OpenAPI-Core/OAOperation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ OAOperation >> api [
]

{ #category : 'as yet unclassified' }
OAOperation >> applyBody: body builder: builder [
self hasBody ifTrue: [ | mediaTypeObject |
body ifNil: [ Error signal: 'cannot use nil for body' ].
mediaTypeObject := self mediaTypeObjectFor: 'application/json'.
mediaTypeObject writeBody: body builder: builder ]
OAOperation >> applyBody: body builder: builder [
| contentType mediaTypeObject |
self hasBody ifFalse: [ ^ self ].
body ifNil: [ Error signal: 'cannot use nil for body' ].
contentType := requestBody preferredContentType.
mediaTypeObject := self mediaTypeObjectFor: contentType.
contentType = 'application/x-www-form-urlencoded'
ifTrue: [ mediaTypeObject writeFormBody: body builder: builder ]
ifFalse: [ mediaTypeObject writeBody: body builder: builder ]
]

{ #category : 'as yet unclassified' }
Expand Down
8 changes: 8 additions & 0 deletions source/OpenAPI-Core/OARequestBody.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ OARequestBody >> initialize [
required := false
]

{ #category : 'accessing' }
OARequestBody >> preferredContentType [
content ifNil: [ ^ nil ].
(content includesKey: 'application/x-www-form-urlencoded') ifTrue: [ ^ 'application/x-www-form-urlencoded' ].
(content includesKey: 'application/json') ifTrue: [ ^ 'application/json' ].
^ content keys anyOne
]

{ #category : 'instance creation' }
OARequestBody >> readFrom: aCall object: object [
| mimeType bodyString |
Expand Down
15 changes: 13 additions & 2 deletions source/OpenAPI-Core/OASchemaDefinition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Class {
#name : 'OASchemaDefinition',
#superclass : 'JSONSchemaDefinition',
#instVars : [
'default'
'default',
'nullable'
],
#category : 'OpenAPI-Core-Model',
#package : 'OpenAPI-Core',
Expand All @@ -13,7 +14,7 @@ Class {
OASchemaDefinition class >> neoJsonMapping: mapper [
super neoJsonMapping: mapper.
mapper for: self do: [ :mapping |
mapping mapInstVars: #( default ) ]
mapping mapInstVars: #( default nullable ) ]
]

{ #category : 'visiting' }
Expand All @@ -30,3 +31,13 @@ OASchemaDefinition >> default [
OASchemaDefinition >> default: anObject [
default := anObject
]

{ #category : 'accessing' }
OASchemaDefinition >> nullable [
^ nullable
]

{ #category : 'accessing' }
OASchemaDefinition >> nullable: aBoolean [
nullable := aBoolean
]
Loading