OpenAPI Ayrıştırıcısı Bundle Şemaları

· Özellikler

sgcOpenAPI 2024.9.0 sürümünden itibaren ayrıştırıcı aşağıdaki yeni özelliklerle geliştirildi:

- Bundle Specification: spesifikasyon birden çok şemayla oluşturulmuşsa, ayrıştırıcı bunları tek bir spesifikasyon dosyasında birleştirebilir.

- Output Parser Parameters: pascal arayüzü oluşturulurken, spesifikasyonları içe aktarmak için kullanılan parametreler pascal dosyasının başlığına yazılır.

- sgcOpenAPI İstemcisi için, HTTP isteğini sunucuya gönderilmeden önce özelleştirmek üzere kullanılabilen OnBeforeRequest adında yeni bir olay oluşturuldu.

Bundle Specification

OpenAPI veya JSON Schema belgeleri çok büyük veya tekrar eden hale geldiğinde, içerik birden çok belgeye (dosya sisteminde, URL'lerde, bir yerde bellekte) bölünebilir ve $ref ile birbirine bağlanabilir. Bu bölünmüş API açıklamaları daha sonra, $ref harici bir konum yerine dahili bir konumu işaret edecek şekilde tek bir belge olarak yeniden birleştirilebilir. Buna "bundling" denir.

Artık sgcOpenAPI Ayrıştırıcısı, openAPI spesifikasyonlarının birleştirilmesini destekler. Bu, bir dosya içe aktarılırken otomatik olarak yapılır.

Bölünmüş OpenAPI Spesifikasyonu


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'        

Birleştirilmiş Spesifikasyon

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 Parser Parameters

 openAPI spesifikasyonundan oluşturulan pascal dosyası artık openAPI dosyasını içe aktarmak için kullanılan parametreleri içerir. Bu parametreler, delphi dosyasının en üstünde yorum olarak oluşturulur.

{ ***************************************************************************  
  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
  *************************************************************************** } 

OnBeforeRequest olayı

Bu olay, HTTP isteği çağrılmadan önce çağrılır. Parametre adlarını, Başlıkları, güvenliği... özelleştirmeye olanak tanır. Bazı parametrelerin adının nasıl değiştirileceğine dair bir örneği aşağıda bulabilirsiniz.

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;