#tek2023
"OpenAPI... previously known as... Swagger... is a specification for a machine-readable interface definition language for describing, producing, consuming and visualizing web services." Wikipedia
Creating OpenAPI from HTTP Traffic
Akita is an observability tool, which can sniff HTTP traffic, and build models of your data.
Stores traffic data in HAR files, which it can then convert to an OpenAPI spec.
npm install @stoplight/spectral-cli
echo 'extends: ["spectral:oas"]' > .spectral.yaml
spectral lint spec.json
composer require cebe/php-openapi
vendor/bin/php-openapi validate spec.json
Treat the spec as a shippable asset, meaning...
info.version
spec attribute as the version changes.PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations. "A poor man's API"
by Nicolas Fränkel
PostgREST automatically serves a full OpenAPI description on the root path. This provides a list of all endpoints (tables, foreign tables, views, functions), along with supported HTTP verbs and example payloads. PostgREST documentation
Integrate frontends with an API before it's built.
ybelenko/openapi-data-mocker-server-middleware
- open source PSR-15 middleware to generate data from OpenAPI specleague/openapi-psr7-validator
- validator for OpenAPI 3.0 implemented as PSR-15 middlewareopis/json-schema
- validator for OpenAPI 3.1 implemented as a libraryhkarlstrom/openapi-validation-middleware
- PSR-15 middleware that uses opis/json-schema
"Schemathesis is a specification-centric API testing tool for OpenAPI... applications. It reads the application schema and generates test cases... The application under test could be written in any language; the only thing you need is a valid API schema..."
st run https://example.schemathesis.io/openapi.json
Supports Docker if you prefer to avoid
Python environments
"Portman leverages your static OpenAPI specs, with all its defined API request/response properties, to power your Postman collection and test suite."
npm add --save-dev @apideck/portman@latest
portman \
-u https://specs.apideck.com/crm.yml \
-c portman-config.crm.json \
-o crm.postman.json
use Vural\OpenAPIFaker\OpenAPIFaker;
$faker = OpenAPIFaker::createFromJson($yourSchemaAsJson);
// or
$faker = OpenAPIFaker::createFromYaml($yourSchemaAsYaml);
$fakeData = $faker->mockResponse('/todos', 'GET');
Uses fakerphp/faker
to generate fake data for OpenAPI requests / responses.
Checks for API implementation drift from spec in Laravel test suites.
composer require hotmeteor/spectator --dev
php artisan vendor:publish \
--provider="Spectator\SpectatorServiceProvider"
class ExampleTest extends TestCase {
public function testBasicExample() {
\Spectator\Spectator::using('Api.v1.json');
$response = $this->postJson('/user', ['name' => 'Sally']);
$response
->assertValidRequest()
->assertValidResponse(201);
}
}
composer require --dev jane-php/open-api-3
composer require jane-php/open-api-runtime
php vendor/bin/jane-openapi generate
$apiClient = Vendor\Library\Generated\Client::create();
$foos = $apiClient->listFoo();
Optic (commercial)