Skip to content

Open API to Client Codes

fonlow edited this page Mar 24, 2020 · 9 revisions

Open API Specification (Swagger) is designed for RESTful Web API, neutral to operation platforms and development platforms, generating codes for both servers and clients.

WebApiClientGen is designed for RPC Web API, optimizing the capacity and the abilities of ASP.NET, C# and TypeScript, generating codes for clients only.

Open API supports while WebApiClientGen doesn't

  • Server side codes.
  • Describe multiple responses of an operation, while WebApiClientGen supports only the response with status code 200 or 204.
  • Handle HTTP header and cookie as parameter
  • Handle authentication

WebApiClientGen supports while Open API doesn't

  • Namespaces.
  • Generic
  • Decimal (Currency) types.
  • ...

The overlapping areas:

  1. Strongly typed API.
  2. Client side data models.

Design Preferences

  • Headers and cookie manipulations are often for authentication. Such manipulations could be done through interception.
  • REST could be considered as technical details at the transportation layer, while RPC may provide higher abstraction of business logic.

More Details could be found at WebApiClientGen vs Swashbuckle.AspNetCore plus NSwag

OpenApiClientGen

OpenApiClientGen could generate cleaner and simpler client codes within the business scope of specific client programming.

In Open API Specification, there are some features not friendly to strongly typed languages like C# but to JavasScript:

  1. Discriminator Object with oneOf, anyOf, allOff. The best match could be object, rather than picking one.

In what scenarios you should not use OpenApiClientGen.

  • The Open API definitions use header for data payload.
  • Use arbitrary url paths without consistent patterns.
  • Request body of POST and Put uses content media types other than text/plain and application/json. For Example, application/x-www-form-urlencoded.
  • Swagger 1.0.

What not supported

  1. Post form data.
  2. Post stream data for upload
Clone this wiki locally