Recent

Author Topic: New Swagger/OpenAPI Client Generator for FPC  (Read 618 times)

abouchez

  • Full Member
  • ***
  • Posts: 118
    • Synopse
New Swagger/OpenAPI Client Generator for FPC
« on: September 06, 2024, 06:18:24 pm »
Since it seems to be a trending subject, a new OpenAPI client generator is now available for FPC:
https://blog.synopse.info/?post/2024/09/06/Swagger/OpenAPI-Client-Generator-for-Delphi-and-FPC
 ;D

Here are some features of our OpenAPI code generator for Delphi and FPC:
- Fully OpenSource, both generator and generated source code
- Use high-level pascal records and dynamic arrays for "object" DTOs
- Use high-level pascal enumerations and sets for "enum" values
- Translate HTTP status error codes into high-level pascal Exceptions
- Recognize similar "properties" or "enum" to reuse the same pascal type
- Support of nested "$ref" for objects, parameters or types
- Support "allOf" attribute, with proper properties inheritance/overloading
- Support "oneOf" attribute, for strings or alternate record types
- Support of "in":"header" and "in":"cookie" parameter attributes
- Fallback to variant pascal type for "oneOf" or "anyOf" JSON values
- Generated source code units are very small and easy to use, read and debug
- Can generate very detailed comment documentation in the unit source code
- Tunable engine, with plenty of generation options (e.g. about verbosity)
- Leverage the mORMot RTTI and JSON kernel for its internal plumbing
- Compatible with FPC and oldest Delphi (7-2009)
- Tested with several Swagger 2 and OpenAPI 3 reference content
But still not fully compliant to all existing files: feedback is welcome!

The source code of the generator is a single unit:
https://github.com/synopse/mORMot2/blob/master/src/net/mormot.net.openapi.pas

And you will find several generated sample code units in the blog article, to make yourself your idea about the level of this little unit.

Feedback is welcome!

vfclists

  • Hero Member
  • *****
  • Posts: 1074
    • HowTos Considered Harmful?
Re: New Swagger/OpenAPI Client Generator for FPC
« Reply #1 on: September 14, 2024, 09:16:18 pm »
Being not familiar with the process of exposing my applications functionality through a REST interface, my question then is:

When you are designing an application what principles and methods do you have to apply to make it suitable for providing a REST API?

Can it also take an existing application and create a REST API from the function signatures?
Lazarus 3.0/FPC 3.2.2

PierceNg

  • Sr. Member
  • ****
  • Posts: 386
    • SamadhiWeb
Re: New Swagger/OpenAPI Client Generator for FPC
« Reply #2 on: September 16, 2024, 09:58:24 am »
When you are designing an application what principles and methods do you have to apply to make it suitable for providing a REST API?

The two relevant sets of keywords are CRUD - create, read, update, delete, and HTTP verbs - GET, POST, PUT, PATCH, DELETE.

Some expositions/opinions by various people:

- https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/
- https://github.com/stickfigure/blog/wiki/How-to-%28and-how-not-to%29-design-REST-APIs
- https://learn.microsoft.com/en-us/azure/architecture/best-practices/api-design

 

TinyPortal © 2005-2018