Skip to content

Commit 498d33f

Browse files
authored
Add support for collections in OpenApiResponse (#566)
* Add support for collections in OpenApiResponse
1 parent d8c2792 commit 498d33f

55 files changed

Lines changed: 201 additions & 189 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/attributes.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,16 @@ order of operations is used to build the response:
404404
3. `associations`
405405
4. The schema inferred from CakePHP conventions.
406406

407-
| Property | Type / Default | OA Spec | Description |
408-
|-------------------------------|-------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
409-
| schemaType | string `"object"` | Y | The schema response type, generally `"object"` or `"array"` |
410-
| statusCode | string `"200"` | Y | The HTTP response code |
411-
| ref | ?string `null` | Y | The OpenAPI schema (e.g. `"#/components/schemas/ModelName"` |
412-
| [schema](#Schema) | ?string `null` | Y | An FQN describing a custom response schema. The class must have either one or more `#[OpenApiSchemaProperty]` attribute, implement `CustomSchemaInterface` or both. |
413-
| description | ?string `null` | Y | Description of the response |
414-
| mimeTypes | ?array `null` | Y | An array of mime types the response can, if null settings from swagger_bake config are used. |
415-
| [associations](#Associations) | ?array `null` | N | Adds associated tables to the response sample schema, see examples below. |
416-
| schemaFormat | ?string `null` | Y | The schema format, generally only used for schemaType of string. |
407+
| Property | Type / Default | OA Spec | Description |
408+
|-------------------------------|-------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
409+
| schemaType | string `"object"` | Y | The schema response type: `"object"`, `"array"` or `"collection"` |
410+
| statusCode | string `"200"` | Y | The HTTP response code |
411+
| ref | ?string `null` | Y | The OpenAPI schema (e.g. `"#/components/schemas/ModelName"` |
412+
| [schema](#Schema) | ?string `null` | Y | An FQN describing a custom response schema. The class must have either one or more `#[OpenApiSchemaProperty]` attribute, implement `CustomSchemaInterface` or both. |
413+
| description | ?string `null` | Y | Description of the response |
414+
| mimeTypes | ?array `null` | Y | An array of mime types the response can, if null settings from swagger_bake config are used. |
415+
| [associations](#Associations) | ?array `null` | N | Adds associated tables to the response sample schema, see examples below. |
416+
| schemaFormat | ?string `null` | Y | The schema format, generally only used for schemaType of string. |
417417

418418
Defining a multiple mimeTypes and 400-409 status code range and an expected 200 response:
419419

src/Command/CommandTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function loadConfig(Arguments $args): void
3030
Configure::load($config, 'default');
3131
} catch (CakeException $e) {
3232
throw new SwaggerBakeRunTimeException(
33-
"SwaggerBake config file `$config` is missing or " . get_class($e) . ' ' . $e->getMessage()
33+
"SwaggerBake config file `$config` is missing or " . get_class($e) . ' ' . $e->getMessage(),
3434
);
3535
}
3636

src/Command/InstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function execute(Arguments $args, ConsoleIo $io): void
4242
$continue = $io->ask(
4343
'If your API exists in a plugin or you have some other non-standard setup, please follow ' .
4444
'the manual installation steps. Do you want to continue?',
45-
'Y'
45+
'Y',
4646
);
4747

4848
if (strtoupper($continue) !== 'Y') {

src/Lib/Attribute/AbstractOpenApiParameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function create(): Parameter
8383
(new Schema())
8484
->setType($this->type)
8585
->setEnum($this->enum)
86-
->setFormat($this->format)
86+
->setFormat($this->format),
8787
);
8888

8989
return $parameter;

src/Lib/Attribute/AbstractSchemaProperty.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(
7272
public readonly ?int $minProperties = null,
7373
public readonly ?int $maxProperties = null,
7474
public readonly array $enum = [],
75-
public readonly array $items = []
75+
public readonly array $items = [],
7676
) {
7777
}
7878

src/Lib/Attribute/AttributeFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class AttributeFactory
1414
*/
1515
public function __construct(
1616
private Reflector $reflection,
17-
private string $attributeClass
17+
private string $attributeClass,
1818
) {
1919
}
2020

src/Lib/Attribute/OpenApiHeader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
public readonly bool $explode = false,
4444
public readonly string $style = '',
4545
public readonly string|bool|int $example = '',
46-
public readonly bool $allowEmptyValue = false
46+
public readonly bool $allowEmptyValue = false,
4747
) {
4848
if (empty($ref) && empty($name)) {
4949
throw new SwaggerBakeRunTimeException('One of ref or name must be defined');
@@ -55,8 +55,8 @@ public function __construct(
5555
'Invalid Data Type, given %s for %s but must be one of: %s',
5656
$type,
5757
$name,
58-
implode(',', OpenApiDataType::TYPES)
59-
)
58+
implode(',', OpenApiDataType::TYPES),
59+
),
6060
);
6161
}
6262
}
@@ -81,7 +81,7 @@ public function createParameter(): Parameter
8181
(new Schema())
8282
->setType($this->type)
8383
->setEnum($this->enum)
84-
->setFormat($this->format)
84+
->setFormat($this->format),
8585
);
8686
}
8787
}

src/Lib/Attribute/OpenApiPaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OpenApiPaginator
1616
*/
1717
public function __construct(
1818
public readonly array $sortEnum = [],
19-
public readonly bool $useSortTextInput = false
19+
public readonly bool $useSortTextInput = false,
2020
) {
2121
}
2222
}

src/Lib/Attribute/OpenApiPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
public readonly ?string $ref = null,
2626
public readonly ?string $summary = null,
2727
public readonly ?string $description = null,
28-
public readonly array $tags = []
28+
public readonly array $tags = [],
2929
) {
3030
}
3131
}

src/Lib/Attribute/OpenApiPathParam.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
description: $description,
4444
example: $example,
4545
isRequired: $isRequired,
46-
allowReserved: $allowReserved
46+
allowReserved: $allowReserved,
4747
);
4848
}
4949

@@ -62,7 +62,7 @@ public function createParameter(): Parameter
6262
->setSchema(
6363
(new Schema())
6464
->setType($this->type)
65-
->setFormat($this->format)
65+
->setFormat($this->format),
6666
);
6767
}
6868
}

0 commit comments

Comments
 (0)