Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
21 stars 12 forks source link

feat(model-ad): add OpenAPI description and API client for Angular #2705

Closed tschaffter closed 1 week ago

tschaffter commented 3 weeks ago

Description

Create a minimal OpenAPI specification for MODEL-AD to illustrate spec-first development, then create an API client for Angular using OpenAPI Generator.

This project was created by adapting the following projects:

image

Changelog

References

Preview

Lint and build the API description

nx build model-ad-api-description
nx lint model-ad-api-description

[!NOTE]
In general, build files are not tracked with git. The output file build/openapi.yaml is an exception as it is handy to have this file hosted on a remote server for the sake of reference and to enable anyone to generate an API client for their favorite programming languages with the OpenAPI Generator (the input can be a URL to the API description).

Generate the API client for Angular

(Re-)generate the API client, for example after updating the API description.

nx run model-ad-api-client-angular:generate

Build the API client for Angular

nx build model-ad-api-client-angular

The files generated below could be published to npmjs. When developing inside the monorepo, we simply import the client with @sagebionetworks/model-ad/api-client-angular.

$ ls -al dist/libs/model-ad/api-client-angular/
total 12
drwxr-xr-x. 4 vscode vscode  88 Jun 14 21:35 .
drwxr-xr-x. 3 vscode vscode  32 Jun 14 21:35 ..
drwxr-xr-x. 3 vscode vscode  89 Jun 14 21:35 esm2022
-rw-r--r--. 1 vscode vscode  23 Jun 14 21:35 index.d.ts
drwxr-xr-x. 4 vscode vscode 157 Jun 14 21:35 lib
-rw-r--r--. 1 vscode vscode  72 Jun 14 21:35 .npmignore
-rw-r--r--. 1 vscode vscode 706 Jun 14 21:35 package.json

Test the API client for Angular

The client comes with unit testing configured (Jest). While we may not need to test the code generated by the OpenAPI Generator, we could add custom template to override the code generated by the OA Generator.

$ nx test model-ad-api-client-angular

> nx run model-ad-api-client-angular:test

No tests found, exiting with code 0
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Successfully ran target test for project model-ad-api-client-angular (3s)