Skip to content
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
2 changes: 1 addition & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ pnpm test:sdk-emitters
pnpm generate:api-docs
```

Review and commit that catalog change independently. The inspections documentation can ship with the existing published PHP catalog; its PHP samples become available when the released inspection-capable SDK catalog is synchronized.
Review and commit that catalog change independently. The current catalog comes from the published PHP SDK [1.4.0 tag](https://github.com/fleetbase/fleetbase-php/releases/tag/1.4.0), commit `f8237cc6bb918061e6aae7ff676393b8b723d6ad`, and includes all six inspection endpoints. Keep future SDK catalog updates separate from the Postman bump.
62 changes: 61 additions & 1 deletion scripts/php-sdk-examples.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schema_version": 1,
"generated_from": {
"repository": "https://github.com/fleetbase/postman",
"ref": "7fe06b7c5e415a9aa292869e9037910896b049ad",
"ref": "d6a7cc530fa27d7cf19a0d3ef8594cf4e51a76bb",
"collections": [
"Fleetbase API",
"Fleetbase Core API"
Expand Down Expand Up @@ -1030,6 +1030,66 @@
"call": "$result = $fleetbase->geofences->listGeofenceEvents(\n [\n 'per_page' => '50',\n 'event_type' => 'entered',\n ]\n);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n\n$result = $fleetbase->geofences->listGeofenceEvents(\n [\n 'per_page' => '50',\n 'event_type' => 'entered',\n ]\n);"
},
"fleetbase-api-inspections-list-inspection-forms": {
"collection": "Fleetbase API",
"group": "Inspections",
"name": "List Inspection Forms",
"implementation": "Fleetbase\\Sdk\\Services\\InspectionFormService::listInspectionForms",
"variables": [],
"call": "$result = $fleetbase->inspectionForms->listInspectionForms(\n [\n 'vehicle' => 'vehicle_id-fixture',\n ]\n);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n\n$result = $fleetbase->inspectionForms->listInspectionForms(\n [\n 'vehicle' => 'vehicle_id-fixture',\n ]\n);"
},
"fleetbase-api-inspections-list-inspections": {
"collection": "Fleetbase API",
"group": "Inspections",
"name": "List Inspections",
"implementation": "Fleetbase\\Sdk\\Services\\InspectionService::listInspections",
"variables": [],
"call": "$result = $fleetbase->inspections->listInspections(\n [\n 'driver' => 'driver_id-fixture',\n ]\n);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n\n$result = $fleetbase->inspections->listInspections(\n [\n 'driver' => 'driver_id-fixture',\n ]\n);"
},
"fleetbase-api-inspections-list-vehicle-inspections": {
"collection": "Fleetbase API",
"group": "Inspections",
"name": "List Vehicle Inspections",
"implementation": "Fleetbase\\Sdk\\Services\\VehicleService::listVehicleInspections",
"variables": {
"vehicleId": "vehicle_id-fixture"
},
"call": "$result = $fleetbase->vehicles->listVehicleInspections($vehicleId);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n$vehicleId = 'vehicle_id-fixture';\n\n$result = $fleetbase->vehicles->listVehicleInspections($vehicleId);"
},
"fleetbase-api-inspections-retrieve-an-inspection": {
"collection": "Fleetbase API",
"group": "Inspections",
"name": "Retrieve an Inspection",
"implementation": "Fleetbase\\Sdk\\Services\\InspectionService::retrieveInspection",
"variables": {
"inspectionId": "inspection_id-fixture"
},
"call": "$result = $fleetbase->inspections->retrieveInspection($inspectionId);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n$inspectionId = 'inspection_id-fixture';\n\n$result = $fleetbase->inspections->retrieveInspection($inspectionId);"
},
"fleetbase-api-inspections-retrieve-an-inspection-form": {
"collection": "Fleetbase API",
"group": "Inspections",
"name": "Retrieve an Inspection Form",
"implementation": "Fleetbase\\Sdk\\Services\\InspectionFormService::retrieveInspectionForm",
"variables": {
"inspectionFormId": "inspection_form_id-fixture"
},
"call": "$result = $fleetbase->inspectionForms->retrieveInspectionForm($inspectionFormId);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n$inspectionFormId = 'inspection_form_id-fixture';\n\n$result = $fleetbase->inspectionForms->retrieveInspectionForm($inspectionFormId);"
},
"fleetbase-api-inspections-submit-an-inspection": {
"collection": "Fleetbase API",
"group": "Inspections",
"name": "Submit an Inspection",
"implementation": "Fleetbase\\Sdk\\Services\\InspectionService::submitInspection",
"variables": [],
"call": "$result = $fleetbase->inspections->submitInspection(\n [\n 'inspection_form' => 'inspection_form_id-fixture',\n 'driver' => 'driver_id-fixture',\n 'vehicle' => 'vehicle_id-fixture',\n 'started_at' => '2026-09-09T07:10:00Z',\n 'odometer' => 120400,\n 'engine_hours' => 3100,\n 'location' => [\n 'latitude' => 1.3521,\n 'longitude' => 103.8198,\n ],\n 'custom_field_values' => [],\n 'item_results' => [\n [\n 'item_key' => 'brakes',\n 'label' => 'Brakes',\n 'category' => 'Safety',\n 'passed' => false,\n 'severity' => 'critical',\n 'comments' => 'Pedal is soft.',\n 'photos' => [\n 'proof_photo_base64-fixture',\n ],\n ],\n [\n 'item_key' => 'lights',\n 'label' => 'Lights',\n 'category' => 'Safety',\n 'passed' => true,\n ],\n ],\n ]\n);",
"code": "<?php\n\n$fleetbase = new \\Fleetbase\\Sdk\\Fleetbase('flb_live_…');\n\n$result = $fleetbase->inspections->submitInspection(\n [\n 'inspection_form' => 'inspection_form_id-fixture',\n 'driver' => 'driver_id-fixture',\n 'vehicle' => 'vehicle_id-fixture',\n 'started_at' => '2026-09-09T07:10:00Z',\n 'odometer' => 120400,\n 'engine_hours' => 3100,\n 'location' => [\n 'latitude' => 1.3521,\n 'longitude' => 103.8198,\n ],\n 'custom_field_values' => [],\n 'item_results' => [\n [\n 'item_key' => 'brakes',\n 'label' => 'Brakes',\n 'category' => 'Safety',\n 'passed' => false,\n 'severity' => 'critical',\n 'comments' => 'Pedal is soft.',\n 'photos' => [\n 'proof_photo_base64-fixture',\n ],\n ],\n [\n 'item_key' => 'lights',\n 'label' => 'Lights',\n 'category' => 'Safety',\n 'passed' => true,\n ],\n ],\n ]\n);"
},
"fleetbase-api-issues-create-an-issue": {
"collection": "Fleetbase API",
"group": "Issues",
Expand Down
10 changes: 7 additions & 3 deletions scripts/sdk-emitters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,19 @@ export function emitPhp({
// Do not invent SDK methods for APIs added ahead of this SDK's catalog.
if (!sdkExample) return null;

const store = php.stores?.[resourceFolder] ?? camelCase(resourceFolder);
const catalogStore = sdkExample.call?.match(/\$fleetbase->([A-Za-z_][A-Za-z0-9_]*)->/)?.[1];

if (
typeof sdkExample?.code === 'string' &&
!isCanonicalPhpCrud({ endpointKind, endpointName, rawUrl })
(!isCanonicalPhpCrud({ endpointKind, endpointName, rawUrl }) ||
(catalogStore && catalogStore !== store))
) {
// A docs folder can contain multiple SDK services (e.g. inspection forms
// and submissions). Only shorten CRUD calls when the service also matches.
return sdkExample.code;
}

const store = php.stores?.[resourceFolder] ?? camelCase(resourceFolder);

switch (endpointKind) {
case 'create':
return [
Expand Down
36 changes: 35 additions & 1 deletion scripts/sdk-emitters.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import test from 'node:test';

import { emitJs, emitPhp } from './sdk-emitters.mjs';
import { classifyEndpoint, emitJs, emitPhp } from './sdk-emitters.mjs';

const catalog = JSON.parse(
await readFile(new URL('./php-sdk-examples.generated.json', import.meta.url)),
Expand Down Expand Up @@ -130,3 +130,37 @@ test('uses first-class PHP SDK methods for Core API custom endpoints', () => {
assert.match(code, /\$fleetbase->organizations->getCurrentOrganization\(/);
assert.doesNotMatch(code, /GuzzleHttp/);
});

test('renders all released inspection examples on their correct SDK services', () => {
const cases = [
['list-inspection-forms', 'GET', '/inspection-forms', /\$fleetbase->inspectionForms->listInspectionForms\(/],
['retrieve-an-inspection-form', 'GET', '/inspection-forms/:id', /\$fleetbase->inspectionForms->retrieveInspectionForm\(\$inspectionFormId\)/],
['submit-an-inspection', 'POST', '/inspections', /\$fleetbase->inspections->submitInspection\(/],
['list-inspections', 'GET', '/inspections', /\$fleetbase->inspections->query\(/],
['retrieve-an-inspection', 'GET', '/inspections/:id', /\$fleetbase->inspections->findRecord\(\$id\)/],
['list-vehicle-inspections', 'GET', '/vehicles/:id/inspections', /\$fleetbase->vehicles->listVehicleInspections\(\$vehicleId\)/],
];
for (const [suffix, method, url, expected] of cases) {
const sdkExample = catalog.examples[`fleetbase-api-inspections-${suffix}`];
assert.ok(sdkExample, `Missing released inspection example: ${suffix}`);
const endpoint = classifyEndpoint({ name: sdkExample.name, method, pathSegments: url.slice(1).split('/') });
const code = emitPhp({
method, fullUrl: `https://api.fleetbase.io/v1${url}`, body: null,
queryParams: suffix === 'list-inspections' ? { driver: 'driver_id-fixture' } : {},
endpointKind: endpoint.kind, endpointAction: endpoint.action,
endpointName: sdkExample.name, rawUrl: `{{base_url}}/{{namespace}}${url}`,
resourceFolder: 'Inspections', sdkConfig, sdkExample,
});
assert.match(code, expected, suffix);
assert.doesNotMatch(code, /GuzzleHttp|'body'\s*=>/, suffix);
if (suffix.includes('inspection-form')) {
assert.doesNotMatch(code, /\$fleetbase->inspections->/, suffix);
}
if (suffix === 'submit-an-inspection') {
assert.match(code, /'item_results'\s*=>/);
}
if (suffix === 'list-inspections') {
assert.match(code, /'driver'\s*=>/);
}
}
});
Loading