Skip to content
Draft
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
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,57 @@ jobs:
run: |
./vendor/bin/phpstan analyse --no-interaction --no-progress --ansi

redocly-lint:
name: Lint OpenAPI with Redocly
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.4'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: intl, bcmath, curl, openssl, mbstring
ini-values: memory_limit=-1
tools: composer
coverage: none
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v5
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: |
composer global require soyuka/pmu
composer global config allow-plugins.soyuka/pmu true --no-interaction
composer global link .
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Redocly CLI
run: npm install -g @redocly/cli@latest
- name: Clear test app cache
run: |
rm -Rf tests/Fixtures/app/var/cache/*
tests/Fixtures/app/console cache:warmup
- name: Generate OpenAPI spec
run: |
mkdir -p /tmp/openapi
tests/Fixtures/app/console api:openapi:export --output=/tmp/openapi/openapi.json --no-ansi
- name: Lint OpenAPI spec with Redocly
run: redocly lint /tmp/openapi/openapi.json

phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion src/Hydra/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string
],
'example' => [
'@id' => 'string',
'type' => 'string',
'@type' => 'string',
$hydraPrefix.'first' => 'string',
$hydraPrefix.'last' => 'string',
$hydraPrefix.'previous' => 'string',
Expand Down
20 changes: 20 additions & 0 deletions tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ public function testSchemaJsonLdCollection(): void
$this->assertEquals(['$ref' => '#/definitions/BagOfTests.jsonld-read'], $schema['allOf'][1]['properties']['hydra:member']['items']);
}

public function testHydraCollectionBaseSchemaExample(): void
{
$schema = $this->schemaFactory->buildSchema(BagOfTests::class, 'jsonld', forceCollection: true);

$this->assertArrayHasKey('HydraCollectionBaseSchema', $schema['definitions']);
$hydraCollectionSchema = $schema['definitions']['HydraCollectionBaseSchema'];

// Navigate to the hydra:view property example
$this->assertArrayHasKey('allOf', $hydraCollectionSchema);
$viewProperty = $hydraCollectionSchema['allOf'][1]['properties']['hydra:view'] ?? null;
$this->assertNotNull($viewProperty, 'hydra:view property should exist');

// Check that the example uses @type instead of type
$this->assertArrayHasKey('example', $viewProperty);
$example = $viewProperty['example'];
$this->assertArrayHasKey('@type', $example, 'Example should use @type with @ prefix');
$this->assertArrayNotHasKey('type', $example, 'Example should not use type without @ prefix');
$this->assertArrayHasKey('@id', $example, 'Example should have @id');
}

public function testArraySchemaWithMultipleUnionTypes(): void
{
$schema = $this->schemaFactory->buildSchema(Nest::class, 'jsonld', 'output');
Expand Down
Loading