I use in a REST app a class like:
TMyClass = class
FId: int64;
FName: string;
end;
In Swagger the model comes as:
TMyClass {
Id Integer
Name string
}
How I can export "Id" as Long?
I use in a REST app a class like:
TMyClass = class
FId: int64;
FName: string;
end;
In Swagger the model comes as:
TMyClass {
Id Integer
Name string
}
How I can export "Id" as Long?
Hi,
The class generator uses Integer or Int64. If you want to use Long that's possible, but you'll need to manually fix the definition after generating the classes.
Where I can do it?
Unless I'm misunderstanding your question, in the output, after you copy the class structure into your own units. The REST client is designed to generate the class structure based on JSON once. The REST client can be used to test requests and responses, afterwards you can use it to create an application with those requests and the generated Delphi classes. Delphi classes that can be modified to your likings. Nothing prevents you from changing the type you need.
I don't think that's a good idea. It would have to be changed manually after every update. Isn't there an attribute for this? Or is it possible to modify the export?
Does anyone else have any ideas?
Do you use the REST Editor or do you programmatically execute the class creation? Please provide some code snippets you are currently using.
I do not use a REST editor.
There is also no code snippet.
The XDataServer component with activated SwaggerOptions is used.
I'm not sure where are you seeing this. In XData, the Swagger is exported correctly:
Note that in Swagger (more specifically Json Schema) there is no "long" type. The type is integer
, with format int64
. That's what displayed in Swagger UI and that's how XData published the Swagger model.
Delphi:
Model:
How I can add "x-data-type"
I didn't have to do anything, just an empty XData server with such class and Swagger and SwaggerUI enabled. It works out of the box. Are you using latest XData version?
Please send a small project reproducing the issue.
A simple Server based on XData Demo:
SwaggerTest-int64.zip (75.4 KB)
Created with Delphi 10.2 and TMS XData 5.15.0.0
I see it now. The x-data-type
appears only for entities, and is not Swagger-related, but specific for XData.
Actually, JSON Schema doesn't have a "int64" (or "long") data type. All types are integer, and only the "format" can be set as "int64", but still that is not displayed in SwaggerUI.
We have improved our Swagger generation here to include the "int64" format, and next version will include this improvement, but that won't change the UI for the end-user, it will still show the type as integer
.
Nevertheless, note that what is displayed in the JSON specification. It's not the data type of the underlying class in the development language (in this case, Delphi). In JSON, integer
also includes Int64 types. There isn't much that can be done here.
Will this change import the type correctly for autogenerated non Delphi clients e.g. Unchase OpenAPI(Swagger) ?
If such tools take the format
property into account, yes.