Skip to content

Commit cf0375b

Browse files
committed
fix: better schema generation
1 parent 1eb79bf commit cf0375b

File tree

14 files changed

+712
-308
lines changed

14 files changed

+712
-308
lines changed

codegen/pkg/generator/collect.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ func (g *Generator) assignSchemasToTags(usage map[string]*schemaUsage) (map[stri
8181
targetTag = tagNames[0]
8282
}
8383

84-
result[targetTag] = append(result[targetTag], info.schema)
85-
namespaceBySchema[schemaName] = g.namespaceForTag(targetTag)
84+
if schemaIsObject(info.schema) {
85+
result[targetTag] = append(result[targetTag], info.schema)
86+
namespaceBySchema[schemaName] = g.namespaceForTag(targetTag)
87+
}
8688
}
8789

8890
for tag := range result {

codegen/pkg/generator/operations.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ func (g *Generator) buildResponseType(schema *base.SchemaProxy, currentNamespace
258258
}
259259

260260
if ref := schema.GetReference(); ref != "" {
261+
if !schemaIsObject(schema) {
262+
return g.buildResponseTypeFromSpec(schema.Schema(), currentNamespace)
263+
}
264+
261265
name := schemaClassName(schema)
262266
namespace := g.schemaNamespaces[name]
263267
typeName := name
@@ -271,7 +275,10 @@ func (g *Generator) buildResponseType(schema *base.SchemaProxy, currentNamespace
271275
}
272276
}
273277

274-
spec := schema.Schema()
278+
return g.buildResponseTypeFromSpec(schema.Schema(), currentNamespace)
279+
}
280+
281+
func (g *Generator) buildResponseTypeFromSpec(spec *base.Schema, currentNamespace string) *responseType {
275282
if spec == nil {
276283
return nil
277284
}

codegen/pkg/generator/properties.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func (g *Generator) resolvePHPType(schema *base.SchemaProxy, currentNamespace st
201201
}
202202

203203
if ref := schema.GetReference(); ref != "" {
204+
if !schemaIsObject(schema) {
205+
return g.resolvePHPTypeFromSpec(schema.Schema(), currentNamespace)
206+
}
207+
204208
name := schemaClassName(schema)
205209
namespace := g.schemaNamespaces[name]
206210
if namespace == "" {
@@ -215,7 +219,10 @@ func (g *Generator) resolvePHPType(schema *base.SchemaProxy, currentNamespace st
215219
return typeName, typeName
216220
}
217221

218-
spec := schema.Schema()
222+
return g.resolvePHPTypeFromSpec(schema.Schema(), currentNamespace)
223+
}
224+
225+
func (g *Generator) resolvePHPTypeFromSpec(spec *base.Schema, currentNamespace string) (string, string) {
219226
if spec == nil {
220227
return "mixed", "mixed"
221228
}

codegen/pkg/generator/schemas.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package generator
2+
3+
import "github.com/pb33f/libopenapi/datamodel/high/base"
4+
5+
// schemaIsObject reports whether the provided schema describes an object that
6+
// warrants generating a PHP class. It walks nested compositions (allOf/oneOf/anyOf)
7+
// to account for aggregated object schemas.
8+
func schemaIsObject(schema *base.SchemaProxy) bool {
9+
return schemaIsObjectWithStack(schema, make(map[*base.SchemaProxy]struct{}))
10+
}
11+
12+
func schemaIsObjectWithStack(schema *base.SchemaProxy, stack map[*base.SchemaProxy]struct{}) bool {
13+
if schema == nil {
14+
return false
15+
}
16+
17+
if _, ok := stack[schema]; ok {
18+
return false
19+
}
20+
stack[schema] = struct{}{}
21+
defer delete(stack, schema)
22+
23+
spec := schema.Schema()
24+
if spec == nil {
25+
return false
26+
}
27+
28+
if hasSchemaType(spec, "object") {
29+
return true
30+
}
31+
32+
if spec.Properties != nil && spec.Properties.Len() > 0 {
33+
return true
34+
}
35+
36+
for _, composite := range spec.AllOf {
37+
if schemaIsObjectWithStack(composite, stack) {
38+
return true
39+
}
40+
}
41+
42+
for _, composite := range spec.AnyOf {
43+
if schemaIsObjectWithStack(composite, stack) {
44+
return true
45+
}
46+
}
47+
48+
for _, composite := range spec.OneOf {
49+
if schemaIsObjectWithStack(composite, stack) {
50+
return true
51+
}
52+
}
53+
54+
return false
55+
}

src/SumUp/Checkouts/Checkouts.php

Lines changed: 151 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class Checkout
8989
/**
9090
* Three-letter [ISO4217](https://en.wikipedia.org/wiki/ISO_4217) code of the currency for the amount. Currently supported currency values are enumerated above.
9191
*
92-
* @var \SumUp\Shared\Currency|null
92+
* @var string|null
9393
*/
94-
public ?\SumUp\Shared\Currency $currency = null;
94+
public ?string $currency = null;
9595

9696
/**
9797
* Unique identifying code of the merchant profile.
@@ -201,9 +201,9 @@ class CheckoutCreateRequest
201201
/**
202202
* Three-letter [ISO4217](https://en.wikipedia.org/wiki/ISO_4217) code of the currency for the amount. Currently supported currency values are enumerated above.
203203
*
204-
* @var \SumUp\Shared\Currency
204+
* @var string
205205
*/
206-
public \SumUp\Shared\Currency $currency;
206+
public string $currency;
207207

208208
/**
209209
* Unique identifying code of the merchant profile.
@@ -286,6 +286,132 @@ class CheckoutCreateRequest
286286

287287
class CheckoutSuccess
288288
{
289+
/**
290+
* Unique ID of the payment checkout specified by the client application when creating the checkout resource.
291+
*
292+
* @var string|null
293+
*/
294+
public ?string $checkoutReference = null;
295+
296+
/**
297+
* Amount of the payment.
298+
*
299+
* @var float|null
300+
*/
301+
public ?float $amount = null;
302+
303+
/**
304+
* Three-letter [ISO4217](https://en.wikipedia.org/wiki/ISO_4217) code of the currency for the amount. Currently supported currency values are enumerated above.
305+
*
306+
* @var string|null
307+
*/
308+
public ?string $currency = null;
309+
310+
/**
311+
* Unique identifying code of the merchant profile.
312+
*
313+
* @var string|null
314+
*/
315+
public ?string $merchantCode = null;
316+
317+
/**
318+
* Short description of the checkout visible in the SumUp dashboard. The description can contribute to reporting, allowing easier identification of a checkout.
319+
*
320+
* @var string|null
321+
*/
322+
public ?string $description = null;
323+
324+
/**
325+
* URL to which the SumUp platform sends the processing status of the payment checkout.
326+
*
327+
* @var string|null
328+
*/
329+
public ?string $returnUrl = null;
330+
331+
/**
332+
* Unique ID of the checkout resource.
333+
*
334+
* @var string|null
335+
*/
336+
public ?string $id = null;
337+
338+
/**
339+
* Current status of the checkout.
340+
*
341+
* @var string|null
342+
*/
343+
public ?string $status = null;
344+
345+
/**
346+
* Date and time of the creation of the payment checkout. Response format expressed according to [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) code.
347+
*
348+
* @var string|null
349+
*/
350+
public ?string $date = null;
351+
352+
/**
353+
* Date and time of the checkout expiration before which the client application needs to send a processing request. If no value is present, the checkout does not have an expiration time.
354+
*
355+
* @var string|null
356+
*/
357+
public ?string $validUntil = null;
358+
359+
/**
360+
* Unique identification of a customer. If specified, the checkout session and payment instrument are associated with the referenced customer.
361+
*
362+
* @var string|null
363+
*/
364+
public ?string $customerId = null;
365+
366+
/**
367+
* Created mandate
368+
*
369+
* @var \SumUp\Shared\MandateResponse|null
370+
*/
371+
public ?\SumUp\Shared\MandateResponse $mandate = null;
372+
373+
/**
374+
* List of transactions related to the payment.
375+
*
376+
* @var mixed[]|null
377+
*/
378+
public ?array $transactions = null;
379+
380+
/**
381+
* Transaction code of the successful transaction with which the payment for the checkout is completed.
382+
*
383+
* @var string|null
384+
*/
385+
public ?string $transactionCode = null;
386+
387+
/**
388+
* Transaction ID of the successful transaction with which the payment for the checkout is completed.
389+
*
390+
* @var string|null
391+
*/
392+
public ?string $transactionId = null;
393+
394+
/**
395+
* Name of the merchant
396+
*
397+
* @var string|null
398+
*/
399+
public ?string $merchantName = null;
400+
401+
/**
402+
* Refers to a url where the end user is redirected once the payment processing completes.
403+
*
404+
* @var string|null
405+
*/
406+
public ?string $redirectUrl = null;
407+
408+
/**
409+
* Object containing token information for the specified payment instrument
410+
*
411+
* @var array|null
412+
*/
413+
public ?array $paymentInstrument = null;
414+
289415
}
290416

291417
/**
@@ -324,6 +450,27 @@ class DetailsError
324450

325451
class ErrorExtended
326452
{
453+
/**
454+
* Short description of the error.
455+
*
456+
* @var string|null
457+
*/
458+
public ?string $message = null;
459+
460+
/**
461+
* Platform code for the error.
462+
*
463+
* @var string|null
464+
*/
465+
public ?string $errorCode = null;
466+
467+
/**
468+
* Parameter name (with relative location) to which the error applies. Parameters from embedded resources are displayed using dot notation. For example, `card.name` refers to the `name` parameter embedded in the `card` object.
469+
*
470+
* @var string|null
471+
*/
472+
public ?string $param = null;
473+
327474
}
328475

329476
/**

src/SumUp/Members/Members.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Member
6161
/**
6262
* The status of the membership.
6363
*
64-
* @var \SumUp\Shared\MembershipStatus
64+
* @var string
6565
*/
66-
public \SumUp\Shared\MembershipStatus $status;
66+
public string $status;
6767

6868
/**
6969
* Set of user-defined key-value pairs attached to the object. Partial updates are not supported. When updating, always submit whole metadata.

src/SumUp/Memberships/Memberships.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Membership
2929
* * `merchant` - merchant account(s)
3030
* * `organization` - organization(s)
3131
*
32-
* @var ResourceType
32+
* @var string
3333
*/
34-
public ResourceType $type;
34+
public string $type;
3535

3636
/**
3737
* User's roles.
@@ -71,9 +71,9 @@ class Membership
7171
/**
7272
* The status of the membership.
7373
*
74-
* @var \SumUp\Shared\MembershipStatus
74+
* @var string
7575
*/
76-
public \SumUp\Shared\MembershipStatus $status;
76+
public string $status;
7777

7878
/**
7979
* Set of user-defined key-value pairs attached to the object. Partial updates are not supported. When updating, always submit whole metadata.
@@ -116,9 +116,9 @@ class MembershipResource
116116
* * `merchant` - merchant account(s)
117117
* * `organization` - organization(s)
118118
*
119-
* @var ResourceType
119+
* @var string
120120
*/
121-
public ResourceType $type;
121+
public string $type;
122122

123123
/**
124124
* Display name of the resource.
@@ -156,13 +156,3 @@ class MembershipResource
156156
public ?\SumUp\Shared\Attributes $attributes = null;
157157

158158
}
159-
160-
/**
161-
* The type of the membership resource.
162-
* Possible values are:
163-
* * `merchant` - merchant account(s)
164-
* * `organization` - organization(s)
165-
*/
166-
class ResourceType
167-
{
168-
}

src/SumUp/Merchant/Merchant.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,6 @@ class BankAccount
343343

344344
}
345345

346-
/**
347-
* Business owners information.
348-
*/
349-
class BusinessOwners
350-
{
351-
}
352-
353346
/**
354347
* Country Details
355348
*/
@@ -595,9 +588,9 @@ class MerchantProfileLegacy
595588
/**
596589
* Business owners information.
597590
*
598-
* @var BusinessOwners|null
591+
* @var array[]|null
599592
*/
600-
public ?BusinessOwners $businessOwners = null;
593+
public ?array $businessOwners = null;
601594

602595
/**
603596
* Doing Business As information

0 commit comments

Comments
 (0)