Da sgcOpenAPI 2024.9.0 il parser è stato migliorato con le seguenti nuove funzionalità:
- Bundle Specification: se la specifica è composta da più schemi, il parser può aggregarli in un singolo file di specifica.
- Output Parser Parameters: quando crea l'interfaccia Pascal, i parametri usati per importare le specifiche sono scritti nell'header del file Pascal.
- È stato creato un nuovo evento per il client sgcOpenAPI, OnBeforeRequest, che può essere usato per personalizzare la richiesta HTTP prima che venga inviata al server.
Bundle Specification
Quando i documenti OpenAPI o JSON Schema diventano enormi o ripetitivi, i contenuti possono essere suddivisi tra più documenti (sul filesystem, su URL, in memoria) e uniti tramite $ref. Queste descrizioni API frammentate possono poi essere riunite in un unico documento, con $ref che puntano a una posizione interna invece che esterna. Questo si chiama "bundling".
Ora il parser sgcOpenAPI supporta il bundling delle specifiche openAPI. Avviene automaticamente all'importazione di un file.
Specifica OpenAPI suddivisa
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/things:
get:
responses:
'200':
description: 'OK'
content:
application/json:
schema:
properties:
data:
type: array
items:
$ref: './schemas/thing.yaml'
/things/{id}:
get:
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: 'OK'
content:
application/json:
schema:
$ref: './schemas/thing.yaml'
Specifica aggregata
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/things:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
data:
type: array
items:
$ref: '#/paths/~1things~1%7Bid%7D/get/responses/200/content/application~1json/schema'
'/things/{id}':
get:
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
id:
type: string
format: uuid
name:
type: string
type:
type: string
enum:
- type1
- type2
Output dei parametri del parser
Il file Pascal creato a partire dalla specifica openAPI ora contiene i parametri usati per importare il file openAPI. Questi parametri sono creati come commenti nella parte superiore del file Delphi.
{ ***************************************************************************
sgcOpenAPI component
written by eSeGeCe
copyright © 2024
Email : info@esegece.com
Web : http://www.esegece.com
Source: D:\Downloads\ICAR-ADE-1\url-schemes\registrationURLScheme.json
Parsed At: 2024-10-02 10:12:18
Options: [Generate Classes] [Enable Classes] [Documentation]
Authentication: Token
Method Name: OperationId
Base URL: https://spec.openapi.com
*************************************************************************** }
Evento OnBeforeRequest
Questo evento viene chiamato prima che la richiesta HTTP venga inviata. Permette di personalizzare i nomi dei parametri, gli header, la sicurezza... Qui sotto trovi un esempio di come sostituire il nome di alcuni parametri.
procedure OnBeforeRequestEvent(Sender: TObject; const aRequest: TsgcOpenAPIRequest);
var
i: Integer;
oParameter: TsgcOpenAPIParameter;
begin
for i := 0 to aRequest.Parameters.Count - 1 do
begin
oParameter := aRequest.Parameters[i];
if oParameter._Name = 'meta-modified-from' then
oParameter._name := 'eventDateTime-from';
if oParameter._Name = 'meta-modified-to' then
oParameter._name := 'eventDateTime-to';
end;
end;
