Skip to content

Fix "attributes" typing for Node and Web SDKs #1037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 20, 2025
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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ sdk-generator/blob/master/example.php:
Run the following command (make sure you have an updated docker version on your machine):

```bash
docker run --rm -v $(pwd):/app -w /app php:8.1-cli php example.php
docker run --rm -v $(pwd):/app -w /app php:8.3-cli php example.php
```

>Note: You can just add the new language next to the other languages in the `example.php` file. You don't need to rewrite the file completely.
Expand Down Expand Up @@ -252,7 +252,7 @@ Also in `.travis.yml` add new env `SDK=[Language]` so that travis will run a tes

Finally, you can run tests using:
```sh
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock php:8.1-cli-alpine sh -c "apk add docker-cli && vendor/bin/phpunit"
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock php:8.3-cli-alpine sh -c "apk add docker-cli && vendor/bin/phpunit"
```

## SDK Generator Interface
Expand Down
13 changes: 13 additions & 0 deletions src/SDK/Language/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public function getTypeName(array $parameter, array $method = []): string
case self::TYPE_NUMBER:
return 'number';
case self::TYPE_ARRAY:
if (!empty($parameter['array']['x-anyOf'] ?? [])) {
$unionTypes = [];
foreach ($parameter['array']['x-anyOf'] as $refType) {
if (isset($refType['$ref'])) {
$refParts = explode('/', $refType['$ref']);
$modelName = end($refParts);
$unionTypes[] = 'Models.' . $this->toPascalCase($modelName);
}
}
if (!empty($unionTypes)) {
return '(' . implode(' | ', $unionTypes) . ')[]';
}
}
if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) {
return $this->getTypeName($parameter['array']) . '[]';
}
Expand Down
13 changes: 13 additions & 0 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ public function getTypeName(array $parameter, array $method = []): string
case self::TYPE_NUMBER:
return 'number';
case self::TYPE_ARRAY:
if (!empty($parameter['array']['x-anyOf'] ?? [])) {
$unionTypes = [];
foreach ($parameter['array']['x-anyOf'] as $refType) {
if (isset($refType['$ref'])) {
$refParts = explode('/', $refType['$ref']);
$modelName = end($refParts);
$unionTypes[] = 'Models.' . $this->toPascalCase($modelName);
}
}
if (!empty($unionTypes)) {
return '(' . implode(' | ', $unionTypes) . ')[]';
}
}
if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) {
return $this->getTypeName($parameter['array']) . '[]';
}
Expand Down