#1 2025-01-27 10:37:01

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 50

Pass ObjectOption parameter for PayLoad OpeAPI

Hello everyone!

Thank you, ab, for a great tool for working with OpenAPI.

How can I pass the ObjectOption parameter to Request (IJsonClient) method, so that the parameter PayLoad is saved to JSON only with non-empty values for POST method?

"required": [
  "projectId",
  "subject"
],
"properties": {
  "projectId": {
    "type": "integer"
  },
  "subject": {
    "type": "string"
  },
  "statusId": {
    "type": "integer"
  },
  "priorityId": {
    "type": "integer"
  }


For example:

PayLoad.ProjectID:=21;
PayLoad.Subject:='subject'
//PayLoad.StatusId:=0
//PayLoad.PriorityId:=0

OpenApiClient.IssueCreate(eo2Json,PayLoad, [woDontStoreDefault,woDontStoreVoid]);

PayLoad --> {ProjectID:21,Subject:'subject'}, but not {ProjectID:21,Subject:'subject',StatusId:0,PriorityId:0} as now

Last edited by Alek (2025-01-27 10:57:04)

Offline

#2 2025-01-27 13:55:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,895
Website

Re: Pass ObjectOption parameter for PayLoad OpeAPI

I have added a new  jcoPayloadWithoutVoid option.
But note that it is global for all methods.
You can change the option before the call, if you are sure that your code is thread-safe (which should be the case from an UI).
See https://github.com/synopse/mORMot2/commit/7795c5a3b

For something tuned for a given method, you could make a manual call to the server, managing by hand the input/output parameters.

Offline

#3 2025-01-28 06:27:10

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 50

Re: Pass ObjectOption parameter for PayLoad OpeAPI

It works perfectly.

Also a similar questions. Sometimes you need to pass a list of parameters in a query (array of simple type), id=1,2,3 but not as id=1&id=2&id=3
or name=str1,str2,str3 but not name=str1?name=str2&name=str3

mormot has an excellent opportunity to use the second way.

The lines are generated in the code:

'*id', IntegerDynArrayToCsv(id) or '*name', GetSetNameCustom(TypeInfo(TEnumNameArray))

If I remove the sign *, I will get the result I need.

How can I do this in an elegant way?

Last edited by Alek (2025-01-28 10:25:06)

Offline

#4 2025-02-11 05:53:09

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 50

Re: Pass ObjectOption parameter for PayLoad OpeAPI

Hello

I did this with the "explode" parameter.

According to the specification 3, when the value of the parameter explode = true for the array type, we get param=abc&param=xyz, and for the value of the parameter explode=false, we get param=abc,xyz

By default, the mORMot behaves like "explode" = true

It is enough to enter a check for the "explode" parameter

function TOpenApiParameter.Explode: boolean;
var lValue:Boolean;
begin
  if Data.GetAsBoolean('explode',lValue) then Result:=lValue
    else result:=true;
end;

....

if p.ParamType.IsArray and p.fExplode then
              w.AddDirect('*'); // ueStarNameIsCsv for UrlEncodeFull()
....

Offline

#5 2025-02-11 08:05:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,895
Website

Re: Pass ObjectOption parameter for PayLoad OpeAPI

Nice idea!

Please try
https://github.com/synopse/mORMot2/commit/2b3cd1a17

Thanks for the feedback!

Offline

#6 2025-02-11 08:41:24

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 50

Re: Pass ObjectOption parameter for PayLoad OpeAPI

It works

Last edited by Alek (2025-02-11 08:41:38)

Offline

Board footer

Powered by FluxBB