TrueNas API and FreeNas API

JM2K69

Dabbler
Joined
Feb 17, 2019
Messages
22
Where can I find the Swaffer or OpenApi file for TrueNas or FreeNas API . It’s a simple YAML or JSON document describing the service. It includes paths or resources, operations or verbs, parameters and responses representations.
I need this to use Autorest application.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
On your system, browse to https://<your system IP>/api/docs/, and go to the RESTful 2.0 tab.
 

JM2K69

Dabbler
Joined
Feb 17, 2019
Messages
22
Ok I know but i need the JSON definition or YML file because when I connect to http://<your system IP> /api/v2.0 i have A json file but with autorest schemas error
1595504658132.png
 

JM2K69

Dabbler
Joined
Feb 17, 2019
Messages
22
Because I Already developped an powershell module to interact with TrueNas and FreeNas it works well but to cover more api path Autorest generate all function for all path and command.
 

UtopianIT

Cadet
Joined
Dec 6, 2018
Messages
4
Hi Jerome,
I forked your github repo for the PS module but rather than build on it further manually and make corrections, I was looking at using something like AutoRest to create a new PS SwaggerClient. Have you been able to get a valid JSON or have you got any further with AutoRest?
Thanks.
 

JM2K69

Dabbler
Joined
Feb 17, 2019
Messages
22
Hi Jerome,
I forked your github repo for the PS module but rather than build on it further manually and make corrections, I was looking at using something like AutoRest to create a new PS SwaggerClient. Have you been able to get a valid JSON or have you got any further with AutoRest?
Thanks.
Hi, thanks for your help, which github repos used for the fork, because I have two the first release :
In th folder TrueNas you can find all function in v2.0.
For Autorest I need to make some other test but I have a valid JSON but always the same error ;(.
 

UtopianIT

Cadet
Joined
Dec 6, 2018
Messages
4
Hi Jerome,

It was the PowerTrueNAS/TrueNas repo I forked so looking at that at the moment. Thank you for your work on that!

I've also been looking at using the latest AutoRest, with PowerShell 7 and get a similar error to you when using the OpenAPI definition provided by TrueNAS. It does appear to be an issue with AutoRest Remodeler itself as the JSON is indeed valid OpenAPI3.

$TrueNASHost = '' # Enter the TrueNAS Hostname or IP here
$OutputFolder = '' # Enter existing output path here

$TrueNASJSONRequest = Invoke-WebRequest -uri "http://$TrueNASHost/api/v2.0"
$TrueNASJSONFile = ".\truenas_api_v2.0.json"
$TrueNASJSONObj = $TrueNASJSONRequest.Content | Out-File $TrueNASJSONFile

& autorest --preview --reset
& autorest --powershell --input-file:$TrueNASJSONFile --v3 --preview --output-folder=$OutputFolder


Even using the preview version (on a crash and burn dev server) still gives:

1604339450015.png


If you change the output to --csharp and --debug, it provides a little more detail.

1604341152136.png


I'll get back to the existing repo anyway and look at building on it and standardising some of the arguments.

Cheers,
Chris
 

UtopianIT

Cadet
Joined
Dec 6, 2018
Messages
4
Good news Jerome! Progress.

AutoRest doesn't currently support AllOf or OneOf and naturally the TrueNAS API has six (6) function variants that can be loaded with different attribute types. If we edit the JSON and amend the use of AllOf to a temporary hardcoded type of string, it gets a lot further.

After creating the PS functions it bombs out with an issue around the failover_call_remote schema, but I'll have a further look tomorrow and see if I can get it to finish generating. It could be because I changed it from JSON to YAML for manipulation. If it works, I'll put it in a repo if it does work, along with the generation code and changes.

Cheers,
Chris
 
Top