From fbc991a35dd6b01807b59ee37cf41a1ee4f72a9d Mon Sep 17 00:00:00 2001 From: Norbert Hartl Date: Thu, 30 Jul 2026 10:50:51 +0200 Subject: [PATCH] Add form-urlencoded body support to OARequestBuilder Stripe's v1 API (the part ApptiveAccount currently uses) sends request bodies as application/x-www-form-urlencoded with bracket-notation for nested objects/arrays (metadata[key], items[0][price]), not JSON. addFormBody: mirrors addJSONBody: for that case, built on a generic flatten helper that walks nested Dictionaries/SequenceableCollections into bracket-notation form keys. --- .../OpenAPI-Client/OARequestBuilder.class.st | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/source/OpenAPI-Client/OARequestBuilder.class.st b/source/OpenAPI-Client/OARequestBuilder.class.st index e5fec9d..758ed29 100644 --- a/source/OpenAPI-Client/OARequestBuilder.class.st +++ b/source/OpenAPI-Client/OARequestBuilder.class.st @@ -12,6 +12,11 @@ Class { #package : 'OpenAPI-Client' } +{ #category : 'building' } +OARequestBuilder >> addFormBody: aDictionary [ + client entity: (ZnApplicationFormUrlEncodedEntity withAll: (self flattenFormParameters: aDictionary)) +] + { #category : 'as yet unclassified' } OARequestBuilder >> addJSONBody: aDictionary [ client @@ -58,6 +63,38 @@ OARequestBuilder >> client: aClient [ client := aClient ] +{ #category : 'forms' } +OARequestBuilder >> flattenFormParameters: aDictionary [ + | result | + result := Dictionary new. + self flattenFormParameters: aDictionary prefix: nil into: result. + ^ result +] + +{ #category : 'forms' } +OARequestBuilder >> flattenFormParameters: anObject prefix: aPrefixString into: aDictionary [ + anObject isString ifTrue: [ + aDictionary at: aPrefixString put: anObject. + ^ self ]. + (anObject isKindOf: Dictionary) ifTrue: [ + anObject keysAndValuesDo: [ :k :v | + self + flattenFormParameters: v + prefix: (aPrefixString + ifNil: [ k asString ] + ifNotNil: [ aPrefixString , (String with: $[) , k asString , (String with: $]) ]) + into: aDictionary ]. + ^ self ]. + (anObject isKindOf: SequenceableCollection) ifTrue: [ + anObject doWithIndex: [ :v :i | + self + flattenFormParameters: v + prefix: (aPrefixString , (String with: $[) , (i - 1) asString , (String with: $])) + into: aDictionary ]. + ^ self ]. + aDictionary at: aPrefixString put: anObject asString +] + { #category : 'initialization' } OARequestBuilder >> initialize [ super initialize.