OpenAPI to/from Flow Schema
One of the things that will help to consume/expose Http-based datasets would be to be able to infer/generate OpenAPI specification for a given dataset.
Here is an example scenario, let's say we want to expose a dataset through the API (instead of granting read-only access to our filesystem/db).
Let say this is our schema:
$schema = schema(
int_schema('id', $nullable = false),
str_schema('name', $nullable = true),
bool_schema('active', $nullable = false, Metadata::empty()->add('key', 'value')),
);
Lets build a OpenAPI specification for that endpoint:
openapi: 3.0.0
info:
title: User API
version: 1.0.0
paths:
/users:
get:
summary: Get list of users
responses:
'200':
description: A list of users
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
type: integer
nullable: false
example: 1
name:
type: string
nullable: true
example: "John Doe"
active:
type: boolean
nullable: false
example: true
components:
schemas:
User:
type: object
properties:
id:
type: integer
nullable: false
name:
type: string
nullable: true
active:
type: boolean
nullable: false
If we take a closer look properties are 1:1 translatable to/from Flow Schema.
We can add it as a new Bridge src/bridge/openapi/flow/ that would provide two converters:
- Flow to OpenAPI
- OpenAPI to Flow
It would be nice to find a way to integrate it also with the API Platform (but through a separate bridge).
Ideally, the openapi schema converter would be put under a flow-php/openapi-bridge and maybe we could create an independent one flow-php/api-platform bridge.