英文:
Can I create a swagger or other API documentation from Angular Services?
问题
在创建后端之前,我创建了一个Angular应用程序。是否有一个可以扫描整个应用程序服务以及其http请求并生成swagger文档,以便后端开发人员使用的服务/npm包/库等?
我知道有一些工具可以反向生成Angular服务(从swagger生成),但我已经有了代码,我想为我正在使用/期望的端点创建文档。
英文:
I created an Angular app before creating a backend. Is there a service/npm package/library/etc I can use that scans the whole app services and its http requests and generate a swagger so the backend dev uses that?
I know there are some tools to do it the other way around (generate Angular Services out of a swagger) but I already have the code, I want to create the documentation for the endpoints I am using/expecting
答案1
得分: 0
Here are the translated parts:
-
compodoc
应该能够通过遵循添加到Angular服务方法的JSDoc注释来生成JSON。 https://compodoc.github.io/compodoc-demo-todomvc-angular/index.html ,然后可以提供给Swagger。 -
npm install -g @compodoc/compodoc
-
然后配置compdoc
{
"title": "My Angular App API Documentation",
"sourceDir": "src/app",
"exportFormats": ["swagger"]
}
- 注释服务
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
/**
* 用于与我的API交互的服务。
*/
@Injectable({
providedIn: 'root'
})
export class MyApiService {
/**
* 检索用户列表。
* @returns 一个发出用户列表的可观察对象。
*/
getUsers() {
return this.http.get<User[]>('/api/users');
}
constructor(private http: HttpClient) { }
}
- 生成swagger.json
compodoc -p tsconfig.app.json
- 然后可以将输出文件提供给后端开发人员。
英文:
compodoc
should be able to to Generate json by following JSDoc annotations added to Angular service methods. https://compodoc.github.io/compodoc-demo-todomvc-angular/index.html which then can be fed to swagger.
npm install -g @compodoc/compodoc
Then configure compdoc
{
"title": "My Angular App API Documentation",
"sourceDir": "src/app",
"exportFormats": ["swagger"]
}
Annotate services
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
/**
* A service for interacting with the My API.
*/
@Injectable({
providedIn: 'root'
})
export class MyApiService {
/**
* Retrieves the list of users.
* @returns An observable that emits the list of users.
*/
getUsers() {
return this.http.get<User[]>('/api/users');
}
constructor(private http: HttpClient) { }
}
To generate swagger.json
compodoc -p tsconfig.app.json
Output file can be then given to BE guys?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论