2017-09-14 25 views
3

RADサーバで実験を始めました。投資を魅力的にする機能の1つに、自己文書化APIの機能があります。これにより、RESTインターフェイスに接続する外部パートナーをサポートする作業が大幅に削減され、別のインターフェイス仕様書を維持する必要がなくなります開発。EMSドキュメント属性を使用してYAMLドキュメントを作成する方法

私は、テストEMSサーバーへの配備まで、最初のEMSリソースを作成するためのwikiのチュートリアルに従ってきました。これは問題なく、うまく動作します。

しかし、私がcustom API documentationチュートリアルに達すると、それは単に機能しません。

私はSWAGGER/YAML AND SELF DOCUMENTING RESTFUL API’SのStephen Ballの投稿を見てきました。残念ながら、彼は私にとっても完璧に動作するRAD Studio EMSサンプルプロジェクトを使用しています。しかし、私は自分のEMSパッケージに同じ属性を適用しようとすると、うまくいきません。

私はHTTを呼び出すとき:// localhostを:8080/API /サーバが返すapidoc.yaml:

{ 
    "error":"Error", 
    "description":"Error: No Responses defined for: get " 
} 

EMSの開発サーバは、次の対応するログエントリがあります。ここでは

{"Request":{"Resource":"API","Endpoint":"GetAPIYAMLFormat","Method":"GET","User":"(blank)","Time":"2017/08/11 12:59:46 AM","Thread":1732}} 
{"Error":{"Type":"HTTP","Code":"500","Reason":"Error","Error":"","Description":"Error: No Responses defined for: get ","Thread":1732}} 

をチュートリアルのコードのスニペットです:

unit Unit1; 

// EMS Resource Unit 

interface 

uses 
    System.SysUtils, System.Classes, System.JSON, 
    EMS.Services, EMS.ResourceAPI, 
    EMS.ResourceTypes, APIDocumentationEndPointObjectsDefinitions; 

type 
    [ResourceName('Test')] 
    [EndPointObjectsYAMLDefinitions(YAMLDefinitions)] 
    [EndPointObjectsJSONDefinitions(JSONDefinitions)] 

    {$METHODINFO ON} 
    TTestResource = class 
    published 
    // Declare the function 
    function MakeJSON(I: Integer): TJSONObject; //It takes an integer as a parameter and returns a JSON Object. 
    [EndPointRequestSummary('Items', 'Get items', 'Used to retrieve all the items', 'application/json', '')] 
    [EndPointRequestParameter(TAPIDocParameter.TParameterIn.Path, 'Test', 'Path Parameter item Description', false, TAPIDoc.TPrimitiveType.spString, TAPIDoc.TPrimitiveFormat.None, TAPIDoc.TPrimitiveType.spString, '', '')] 
    [EndPointResponseDetails(200, 'Ok', TAPIDoc.TPrimitiveType.spObject, TAPIDoc.TPrimitiveFormat.None, '', '#/definitions/items')] 
    procedure Get(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse); 
    [ResourceSuffix('{item}')] 
    procedure GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse); 
    end; 
    {$METHODINFO OFF} 

implementation 
const 
    TestValues: array [0 .. 2] of string = ('a', 'b', 'c'); // It creates an array of string values. 

procedure TTestResource.Get(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse); 
var 
    LJSON: TJSONArray; 
    I: Integer; 
begin 
    LJSON := TJSONArray.Create; 
    for I := Low(TestValues) to High(TestValues) do 
    LJSON.Add(MakeJSON(I)); //[{"index":0,"value":"a"},{"index":1,"value":"b"},{"index":2,"value":"c"}] 
    AResponse.Body.SetValue(LJSON, True) // True causes AResponse to free JSON 
end; 

procedure TTestResource.GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse); 
var 
    I: Integer; 
begin 
    if not TryStrToInt(ARequest.Params.Values['item'], I) then //{"index":I,"value":value} 
    AResponse.RaiseBadRequest('Index expected'); 
    if (I < 0) or (I >= Length(TestValues)) then 
    AResponse.RaiseBadRequest('Index out of range'); 
    AResponse.Body.SetValue(MakeJSON(I), True); 
    // True causes AResponse to free JSON 
end; 

function TTestResource.MakeJSON(I: Integer): TJSONObject; 
begin 
    Result := TJSONObject.Create; 
    Result.AddPair('index', TJSONNumber.Create(I)); //Adds to the JSON object a pair {"index": I}, the index number. 
    Result.AddPair('value', TJSONString.Create(TestValues[I])); //Adds to the the JSON object a pair {"value":String}, the string corresponding to the index number. 

end; 

procedure Register; 
begin 
    RegisterResource(TypeInfo(TTestResource)); 
end; 

initialization 
    Register; 
end. 

あなたには何かがあるように見えますeサンプルプロジェクトは、RAD Studio EMSパッケージウィザードによって生成されたコードにはありません。

新しいEMSドキュメント属性を使用して、自分のEMSパッケージからYAMLドキュメントを作成できたのですか?RAD Studioに付属のサンプルプロジェクトではありませんか?

これを体験した他の人はいますか? getメソッドが完全に実装されていない可能性がありますか?この問題を修正しましたか(私はRAD Studio 10.2.1に更新しました)?

答えて

0

あなたが任意の負荷なしでEMSDevServer.exeを実行した場合には、このように、動作します:それは実行されません任意の負荷で

{"ConfigLoaded":{"Filename":"C:\Users\Public\Documents\Embarcadero\EMS\emsserver.ini","Thread":924}} 
{"DBConnection":{"InstanceName":"gds_db","Filename":"C:\Users\Public\Documents\Embarcadero\EMS\emsserver.ib","Thread":924}} 
{"Licensing":{"Licensed":false,"DefaultMaxUsers":5,"Thread":924}} 
{"RegResource":{"Resource":"Version","Endpoints":["GetVersion"],"Thread":924}} 
{"RegResource":{"Resource":"API","Endpoints":["API","GetAPIYAMLFormat EndPoint","GetAPIYAMLFormat","GetAPIJSONFormat"],"Thread":924}} 
{"RegResource":{"Resource":"Users","Endpoints":["GetUsers","GetUser","GetUserFields","GetUserGroups","SignupUser","LoginUser","AddUser","UpdateUser","DeleteUser"],"Thread":924}} 
{"RegResource":{"Resource":"Groups","Endpoints":["GetGroups","GetGroup","GetGroupFields","AddGroup","UpdateGroup","DeleteGroup"],"Thread":924}} 
{"RegResource":{"Resource":"Installations","Endpoints":["GetInstallations","GetChannels","GetInstallationFields","GetInstallation","AddInstallation","UpdateInstallation","DeleteInstallation"],"Thread":924}} 
{"RegResource":{"Resource":"Push","Endpoints":["Send"],"Thread":924}} 
{"RegResource":{"Resource":"Edgemodules","Endpoints":["GetModules","GetModule","GetResources","GetModuleResources","GetModulesFields","GetResourcesFields","GetModuleResource","RegisterModule","RegisterModuleResource","UpdateModule","UpdateModuleResource","UnregisterModule","UnregisterModuleResource","GetResourceEndpoint","GetResourceEndpointItem","PutResourceEndpoint","PutResourceEndpointItem","PostResourceEndpoint","PostResourceEndpointItem","PatchResourceEndpoint","PatchResourceEndpointItem","DeleteResourceEndpoint","DeleteResourceEndpointItem"],"Thread":924}} 
{"Request":{"Resource":"API","Endpoint":"GetAPIJSONFormat","Method":"GET","User":"(blank)","Time":"06.11.2017 15:42:28","Thread":8672}} 

、おそらくそれはバグです。

関連する問題