resources.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. package tst
  2. import (
  3. "fmt"
  4. "strings"
  5. . "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/common" // . "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/gen"
  6. TS "git.eugeniocarvalho.dev/eugeniucarvalho/gg/generators/typescript"
  7. )
  8. var (
  9. FormatMap map[string]string
  10. // TemplatesMethods = map[string]func(p *Project, method *Method) (*G.Statement, error){
  11. // "post": GenCreateStmts,
  12. // "put": GenUpdateStmts,
  13. // "delete": GenDeleteStmts,
  14. // "get_one": GenGetStmtsOne,
  15. // "get_list": GenGetStmtsList,
  16. // }
  17. angularServiceOption = []TS.CodeInterface{}
  18. angularServiceOptionMap = map[string]string{}
  19. )
  20. func GenResources(p *Project) {
  21. var (
  22. // angularServiceStmtName string
  23. angularResourceName string
  24. ServiceStmt = "ServiceStmt"
  25. // angularServiceMethods []TS.CodeInterface
  26. angularServiceStmtMethods []TS.CodeInterface
  27. )
  28. // imports(module)
  29. // module.Line().Export().Class().Id(ServiceStmt).Block(
  30. // TS.Public().Id("Url").Call(TS.Raw("u: string, options:{}")).Op(":").String().Block(
  31. // TS.Raw(""),
  32. // ),
  33. // ).Line()
  34. module.Line().Raw(`
  35. export type HttpOptions = {
  36. headers?: HttpHeaders;
  37. params?: any;
  38. withCredentials?: boolean;
  39. id?: string;
  40. } & {
  41. [prop: string]: any;
  42. };
  43. export class ServiceStmt {
  44. // constructor(protected api: `).Id(ApiClassName(p)).Raw(`) {}
  45. constructor(protected api: ApiInterface) {
  46. }
  47. get authorized$(){
  48. // return this.api.Auth.Authorize()
  49. return this.api.Auth.grant
  50. ? of(true)
  51. : this.api.Auth.Authorize().pipe(map(() => true))
  52. }
  53. public Url(u: string, opts: {}): string {
  54. (u.match(/{(\w+)}/gm)||[]).map(argExpression => {
  55. const
  56. prop = argExpression.replace(/({|})/gm,''),
  57. value = opts[prop];
  58. if (!value) { throw Error(`).Raw("`Url params '${prop}' is required`").Raw(`);}
  59. u = u.replace(argExpression, value);
  60. });
  61. return u;
  62. }
  63. _event<T = any>(url, opt: HttpOptions): Observable<EventSourcePolyfill> {
  64. opt = this.api.options(opt);
  65. const _url = new URL(this.Url(url, opt)), { params = null } = opt;
  66. if (params) {
  67. params.map.forEach((values, prop) => values.map(value => _url.searchParams.append(prop, value)));
  68. }
  69. return new Observable(o => o.next(new EventSourcePolyfill(
  70. _url.toString(),
  71. { heartbeatTimeout: 86400000, headers: { Authorization: this.api.Auth.Token() } },
  72. ))).pipe(take(1));
  73. }
  74. _get<T = any>(url, opt: HttpOptions):Observable<T> {
  75. opt = this.api.options(opt);
  76. return this.api.http.get<any>(this.Url(url, opt), opt).pipe(take(1));
  77. }
  78. _put<T = any>(url, entity: any, opt: HttpOptions):Observable<T> {
  79. opt = this.api.options(opt);
  80. return this.api.http.put<any>(this.Url(url, opt), entity, opt).pipe(take(1));
  81. }
  82. _patch<T = any>(url, entity: any, opt: HttpOptions):Observable<T> {
  83. opt = this.api.options(opt);
  84. return this.api.http.patch<any>(this.Url(url, opt), entity, opt).pipe(take(1));
  85. }
  86. _post<T = any>(url, entity: any, opt: HttpOptions):Observable<T> {
  87. opt = this.api.options(opt);
  88. return this.api.http.post<any>(this.Url(url, opt), entity, opt).pipe(take(1));
  89. }
  90. _delete<T = any>(url, opt: HttpOptions) {
  91. opt = this.api.options(opt);
  92. return this.api.http.delete<any>(this.Url(url, opt), opt).pipe(take(1));
  93. }
  94. }`).Line()
  95. for _, resource := range p.Resources {
  96. FormatMap = map[string]string{}
  97. // angularServiceMethods = []TS.CodeInterface{}
  98. angularServiceStmtMethods = []TS.CodeInterface{}
  99. angularResourceName = strings.Title(resource.ID) + "Service"
  100. module.Comment(resource.Description).Line()
  101. // angularServiceMethods = append(angularServiceMethods, TS.Constructor(
  102. // TS.Protected().Id("api").Op(":").Id(ApiClassName(p)),
  103. // ).Block(
  104. // // TS.This().Dot("Url").Op("="),
  105. // ))
  106. // angularServiceStmtMethods = append(angularServiceStmtMethods, TS.Public().Id("Url").Op(":").String())
  107. // angularServiceStmtMethods = append(angularServiceStmtMethods, TS.Constructor(
  108. // TS.Protected().Id("api").Op(":").Id(ApiClassName(p)),
  109. // TS.Protected().Id("options").Op(":").Id("ServiceOptions"),
  110. // ).Block(
  111. // // TS.Raw("this.url").Op("=").Lit(p.UrlFromMethod()).Endl(),
  112. // TS.Raw("super();"),
  113. // TS.Raw("if (this.options == null)").Block(
  114. // // TS.Raw("this.options = new ServiceOptions();"),
  115. // TS.Raw("this.options = {};"),
  116. // ),
  117. // // TS.Super().Call(TS.Id("options")),
  118. // ))
  119. // angularServiceStmtName = angularResourceName + "Stmt"
  120. // angularServiceMethods = append(angularServiceMethods, TS.Id("Options").Params(
  121. // TS.Id("options?").Op(":").Id("ServiceOptions"),
  122. // ).Op(":").Id(angularServiceStmtName).Block(
  123. // TS.Return().New().Id(angularServiceStmtName).Call(
  124. // TS.Id("this.api"),
  125. // TS.Id("options"),
  126. // ),
  127. // ).Line())
  128. // angularServiceStmtMethods = append(angularServiceStmtMethods, TS.Line().Raw(`
  129. // options(opts?: HttpOptions): this {
  130. // opts && Object.assign(this.opts, opts)
  131. // return this;
  132. // }`).Line())
  133. for _, method := range resource.Methods {
  134. // if method.Template == "implement" {
  135. // continue
  136. // }
  137. GenAngularMethodStmt(
  138. p,
  139. resource,
  140. method,
  141. &angularServiceStmtMethods,
  142. angularResourceName,
  143. )
  144. // Vai ser usado no metodo de construcao da classe chamado em createAngularService
  145. for paramName, param := range method.Parameters {
  146. // fmt.Println("param >>>>>>>>>", resource.ID, method.ID, paramName)
  147. if _, find := angularServiceOptionMap[paramName]; find {
  148. continue
  149. }
  150. angularServiceOptionMap[paramName] = param.Location
  151. angularServiceOption = append(angularServiceOption,
  152. TS.Comment(param.Description).Id(paramName+"?").Op(":").Id(TS.ConvType(param.Type)).Endl(),
  153. )
  154. }
  155. }
  156. module.Line().Export().Class().Id(
  157. angularResourceName,
  158. // ).Extends().Id(fmt.Sprintf("%s<%s>",ServiceStmt, resource.Entity )).Block(
  159. ).Extends().Id(fmt.Sprintf("%s", ServiceStmt)).Block(
  160. angularServiceStmtMethods...,
  161. ).Line()
  162. // module.Line().Export().Class().Id(
  163. // angularResourceName,
  164. // ).Block(
  165. // angularServiceMethods...,
  166. // ).Line()
  167. }
  168. // Cria o arquivo de servido da api
  169. createAngularService(p, module)
  170. // Fim do laco de recurso
  171. // Salva o arquivo do modulo
  172. }
  173. func ApiClassName(p *Project) string {
  174. return p.Name + "Api"
  175. }
  176. func createAngularService(p *Project, module *TS.File) error {
  177. // var (
  178. // service = Ts.NewFile("api.service.ts")
  179. // )
  180. // Define a class que representa uma resposta da api
  181. // "Class gerencia todos os serviços da api.",
  182. module.Export().Interface().Id("ServiceResponse<T = any>").Block(
  183. TS.Raw("resultSizeEstimate: number;"),
  184. TS.Raw("nextPageToken: string;"),
  185. TS.Raw("entity?:T;"),
  186. TS.Raw("itens?:T[];"),
  187. )
  188. // Define todos os parametros atribuiveis as opcoes de uma requisicao da api
  189. module.Line().Export().Interface().Id("ServiceOptions").BlockFun(func(g *TS.Group) {
  190. g.Stmts = angularServiceOption
  191. })
  192. //
  193. createClientClass(p, module)
  194. //
  195. createAuthClass(p, module)
  196. module.Line().Comment("Objeto acessivel pelo usuario para realizar requisicoes à api.").Raw(`
  197. @Injectable({ providedIn: 'root' })
  198. // @Injectable()
  199. export class `).Raw(ApiClassName(p)).Raw(` {
  200. public Client: Client;
  201. // public BASE_URL = environment.BASE_URL;
  202. public Auth: Auth;
  203. // public queryParams: any = {};
  204. public poolReady = [];
  205. public httpOptions = {
  206. headers: new HttpHeaders({
  207. 'Content-Type': 'application/json',
  208. 'Accept': 'application/json'
  209. }),
  210. withCredentials: true,
  211. };
  212. constructor(
  213. public http: HttpClient,
  214. // public route: ActivatedRoute,
  215. // public router: Router,
  216. // @Inject(ApiOptionsParams) public apiOptions: `).Raw(ApiClassName(p) + "Options").Raw(`,
  217. public apiOptions: `).Raw(ApiClassName(p) + "Options").Raw(`,
  218. ) {
  219. console.log('apiOptions `).Raw(ApiClassName(p)).Raw(`',apiOptions);
  220. // this.route.queryParams.subscribe(params => { this.queryParams = params; });
  221. this.Client = new Client(this);
  222. if (Boolean(window[oauthWindowProp])) {
  223. this.Auth = window[oauthWindowProp];
  224. } else {
  225. this.Auth = window[oauthWindowProp] = new Auth(this);
  226. }
  227. }
  228. onready(fn: () => void) {
  229. this.Auth.onAuthorize$.pipe(filter(grant => Boolean(grant))).subscribe(fn);
  230. // if (this.Auth.grant) {
  231. // fn();
  232. // } else {
  233. // this.poolReady.push(fn);
  234. // }
  235. }
  236. // options(opts?: HttpOptions): HttpOptions {
  237. // console.log({ ...this.httpOptions.headers });
  238. // opts = Object.assign(
  239. // {
  240. // headers: new HttpHeaders({
  241. // ...this.httpOptions.headers,
  242. // }),
  243. // params: {},
  244. // },
  245. // opts
  246. // );
  247. // // const headers = {
  248. // // Authorization: this.Auth.Token(),
  249. // // };
  250. // opts.headers.set("Authorization", this.Auth.Token());
  251. // //this.copyHeader(this.httpOptions.headers, headers);
  252. // //this.copyHeader(opts.headers, headers);
  253. // const params = opts.params;
  254. // // Converte a query para base64
  255. // if (params.q) {
  256. // params.q = window.btoa(unescape(encodeURIComponent(params.q)));
  257. // }
  258. // // delete opts.headers;
  259. // // delete opts.params;
  260. // // const options = Object.assign(
  261. // // {
  262. // // headers: new HttpHeaders(headers),
  263. // // params: new HttpParams({ fromObject: params }),
  264. // // },
  265. // // opts
  266. // // );
  267. // // const options = Object.assign({
  268. // // headers: new HttpHeaders(hopts),
  269. // // params: {}
  270. // // }, opts);
  271. // // // Converte a query para base64
  272. // // if (options.params.q) {
  273. // // options.params.q = window.btoa(unescape(encodeURIComponent(options.params.q)));
  274. // // }
  275. // return opts;
  276. // }
  277. options(opts?: HttpOptions): HttpOptions {
  278. opts = Object.assign({
  279. headers: new HttpHeaders(),
  280. params: {},
  281. }, opts);
  282. const headers = {
  283. 'Authorization': this.Auth.Token()
  284. };
  285. this.copyHeader(this.httpOptions.headers, headers);
  286. this.copyHeader(opts.headers, headers);
  287. const params = opts.params;
  288. // Converte a query para base64
  289. if (params.q) {
  290. params.q = window.btoa(unescape(encodeURIComponent(params.q)));
  291. }
  292. delete opts.headers;
  293. delete opts.params;
  294. const options = Object.assign({
  295. headers: new HttpHeaders(headers),
  296. params: new HttpParams({ fromObject: params }),
  297. }, opts);
  298. // const options = Object.assign({
  299. // headers: new HttpHeaders(hopts),
  300. // params: {}
  301. // }, opts);
  302. // // Converte a query para base64
  303. // if (options.params.q) {
  304. // options.params.q = window.btoa(unescape(encodeURIComponent(options.params.q)));
  305. // }
  306. return options;
  307. }
  308. copyHeader(headers, hopts) {
  309. if (!headers) { return; }
  310. headers.keys().map(key => { hopts[key] = headers.get(key); });
  311. }
  312. }`)
  313. // .Injetable("{providedIn: 'root'}").Export().Class().Id(ApiClassName(p)).Block(
  314. // TS.Public().Id("Client").Op(":").Id("Client").Endl(),
  315. // TS.Public().Id("baseURL").Op("=").Lit(p.BaseURL).Endl(),
  316. // TS.Public().Id("Auth").Op(":").Id("Auth").Endl(),
  317. // TS.Public().Id("httpOptions").Id("=").Block(
  318. // TS.Id("headers").Op(":").Raw("new HttpHeaders").Call(TS.Block(
  319. // TS.Raw("'Content-Type': 'application/json',"),
  320. // TS.Raw("'Accept': 'application/json'"),
  321. // )),
  322. // ).Endl(),
  323. // // TS.Public().Id("http").Op(":").Id("HttpClient").Endl(),
  324. // TS.Constructor(
  325. // TS.Public().Id("http").Op(":").Id("HttpClient"),
  326. // ).Block(
  327. // TS.This().Dot("Client").Op("=").New().Id("Client").Call(TS.This()).Endl(),
  328. // // TS.Id("this.http").Op("=").New().Id("Client").Call(TS.This()).Endl(),
  329. // ),
  330. // TS.Id("Options").Params(
  331. // TS.Id("opts").Op(":").Id("ServiceOptions"),
  332. // ).Op(":").Id("{headers: HttpHeaders,params: any}").Block(
  333. // TS.Return().Block(
  334. // TS.Raw("headers: this.httpOptions.headers,"),
  335. // // TS.Raw("params : opts.Params()"),
  336. // TS.Raw("params : opts"),
  337. // ),
  338. // ),
  339. // ).Line()
  340. module.Line().Raw(`
  341. export function ApiOptionsProvider(options) {
  342. console.log('ApiOptionsProvider', options);
  343. return options;
  344. }
  345. @NgModule({
  346. imports: [
  347. CommonModule,
  348. HttpClientModule,
  349. ]
  350. })
  351. `).Export().
  352. Class().
  353. Id(p.Name + "ApiModule").
  354. Block(
  355. TS.Raw(`
  356. static forRoot( options?: `).Raw(ApiClassName(p) + "Options").Raw(` ) : ModuleWithProviders {
  357. // static forRoot( options?:any ) : ModuleWithProviders {
  358. return({
  359. ngModule: `).Raw(p.Name + "ApiModule").Raw(`,
  360. providers: [
  361. {
  362. provide: ApiOptionsParams,
  363. useValue: options,
  364. },
  365. {
  366. provide: `).Raw(ApiClassName(p) + "Options").Raw(`,
  367. useFactory: ApiOptionsProvider,
  368. deps:[ApiOptionsParams]
  369. }
  370. ]
  371. });
  372. }
  373. `),
  374. ).
  375. Line()
  376. return nil
  377. }
  378. // createClientClass cria a classe de cliente que guarda a referencia para todos os servicos da api
  379. func createClientClass(p *Project, file *TS.File) {
  380. var (
  381. angularResourceName string
  382. angularClientStmts = []TS.CodeInterface{}
  383. angularClientConstructor = []TS.CodeInterface{}
  384. )
  385. for _, resource := range p.Resources {
  386. angularResourceName = strings.Title(resource.ID) + "Service"
  387. angularClientStmts = append(
  388. angularClientStmts,
  389. TS.Public().Id(strings.Title(resource.ID)).Op(":").Id(angularResourceName).Endl(),
  390. )
  391. angularClientConstructor = append(
  392. angularClientConstructor,
  393. TS.This().Dot(strings.Title(resource.ID)).Op("=").New().Id(angularResourceName).Call(TS.Id("api")).Endl(),
  394. )
  395. }
  396. angularClientConstructor = append(
  397. angularClientConstructor,
  398. TS.Raw("this.Generic = new ServiceStmt").Call(TS.Id("api")).Endl(),
  399. )
  400. // angularClientStmts = append(
  401. // angularClientStmts,
  402. // TS.Raw(`public onready = new EventEmitter<any>();`),
  403. // )
  404. angularClientStmts = append(
  405. angularClientStmts,
  406. TS.Public().Id("Generic: ServiceStmt").Endl(),
  407. )
  408. angularClientStmts = append(
  409. angularClientStmts,
  410. TS.Constructor(
  411. TS.Protected().Id("api").Op(":").Id("ApiInterface"),
  412. ).Block(angularClientConstructor...),
  413. )
  414. file.Line().Comment(
  415. "Class gerencia todos os serviços da api.",
  416. ).Export().Class().Id("Client").Block(angularClientStmts...)
  417. }
  418. func GenAngularMethodStmt(p *Project, r *Resource, method *Method, methods *[]TS.CodeInterface, angularResourceName string) {
  419. var (
  420. typ string
  421. params = []TS.CodeInterface{}
  422. paramsHttp = []TS.CodeInterface{}
  423. // id = method.ID
  424. // ret = TS.Id("Observable")
  425. param = "entity"
  426. returnTemplate *TS.Group
  427. template string
  428. templateValue interface{}
  429. defined bool
  430. )
  431. if templateValue, defined = method.Custom["ts.template.method"]; defined {
  432. template = templateValue.(string)
  433. } else {
  434. template = method.HttpMethod
  435. }
  436. template = strings.ToLower(template)
  437. entityType := method.Entity
  438. if entityType == "" {
  439. entityType = "any"
  440. }
  441. switch template {
  442. case "post":
  443. typ = "post"
  444. params = append(params, TS.Id(param).Op(":").Id(entityType))
  445. // ret.TypeAliase(method.Entity)
  446. case "filter":
  447. typ = "get"
  448. // ret.TypeAliase(method.Entity)
  449. param = ""
  450. // params = append(params, TS.Id(param).Op(":").String())
  451. case "get":
  452. typ = "get"
  453. // ret.TypeAliase(method.Entity)
  454. param = ""
  455. case "put":
  456. typ = "put"
  457. // ret.TypeAliase(method.Entity)
  458. params = append(params, TS.Id(param).Op(":").Id(entityType).Op("|").String())
  459. case "delete":
  460. typ = "delete"
  461. // ret.TypeAliase(method.Entity)
  462. // params = append(params, TS.Id(param).Op(":").Id(method.Entity).Op("|").String())
  463. case "patch":
  464. typ = "patch"
  465. params = append(params, TS.Id(param).Op(":").Id(entityType).Op("|").String())
  466. // ret.TypeAliase(method.Entity)
  467. // params = append(params, TS.Id(param).Op(":").Id(method.Entity).Op("|").String())
  468. case "sse":
  469. typ = "event"
  470. default:
  471. panic(fmt.Sprintf("Method '%s' template not defined!", template))
  472. }
  473. path := method.Path
  474. for _, parameter := range method.Parameters {
  475. alias := getCustom(parameter.Custom, "ts.api.alias")
  476. if aliasString, ok := alias.(string); ok {
  477. path = strings.ReplaceAll(
  478. path,
  479. fmt.Sprintf("{%s}", parameter.ID),
  480. fmt.Sprintf("{%s}", aliasString),
  481. )
  482. }
  483. }
  484. // paramsHttp = append(paramsHttp, TS.Raw("this.Url(url, opt.params)"))
  485. paramsHttp = append(paramsHttp, TS.Raw(fmt.Sprintf("`${this.api.apiOptions.BASE_URL}%s`", path)))
  486. switch typ {
  487. case "post", "put", "patch":
  488. paramsHttp = append(paramsHttp, TS.Id("entity"))
  489. }
  490. params = append(params, TS.Id("opt?: HttpOptions"))
  491. paramsHttp = append(paramsHttp, TS.Id("opt"))
  492. response := strings.Replace(method.Response, "*", "", -1)
  493. if response == "" {
  494. response = method.Entity
  495. }
  496. if response == "" {
  497. response = "any"
  498. }
  499. if getCustom(method.Custom, "client.authorization.required", true).(bool) {
  500. returnTemplate = TS.Line().Raw(
  501. fmt.Sprintf(`return this.authorized$.pipe(
  502. switchMap(() => this._%s<%s>`,
  503. typ,
  504. response,
  505. ),
  506. ).Call(paramsHttp...).
  507. Raw(")\n)").
  508. Endl()
  509. } else {
  510. returnTemplate = TS.Line().Raw(
  511. fmt.Sprintf(
  512. "return this._%s<%s>",
  513. typ,
  514. response,
  515. ),
  516. ).Call(paramsHttp...).
  517. Endl()
  518. }
  519. // *methods = append(*methods, TS.Id(method.ID).Params(params...).Op(":").Id("Observable<ServiceResponse>").Block(
  520. *methods = append(*methods, TS.Id(method.ID).Params(params...).Block(
  521. returnTemplate,
  522. ).Line())
  523. // TS.Raw("let opt = this.api.Options(this.options)").Endl(),
  524. // TS.Raw("let url = ").Lit(p.GetUrlFromMethod(method)).Endl(),
  525. // TS.Raw("let url = ").Raw(fmt.Sprintf("`${this.api.BASE_URL}%s`", method.Path)).Endl(),
  526. // TS.Line().Raw(fmt.Sprintf("return this._%s", typ )).Call(paramsHttp...).Endl(),
  527. }
  528. // func GenAngularMethod(p *Project, r *Resource, method *Method, methods *[]TS.CodeInterface, angularResourceName string) {
  529. // params := []TS.CodeInterface{}
  530. // param := "entity"
  531. // methodId := method.ID
  532. // callOptionsParam := ""
  533. // switch strings.ToLower(method.HttpMethod) {
  534. // case "post":
  535. // params = append(params, TS.Id(param).Op(":").Id(method.Entity))
  536. // case "filter":
  537. // // methodId = "get"
  538. // param = ""
  539. // case "get":
  540. // param = ""
  541. // // params = append(params, TS.Id(param).Op(":").String())
  542. // case "get_list":
  543. // param = ""
  544. // // params = append(params, TS.Id(param).Op(":").Id(method.Entity).Op("|").String())
  545. // case "patch":
  546. // param = ""
  547. // params = append(params, TS.Id(param).Op(":").Id(method.Entity))
  548. // // params = append(params, TS.Id(param).Op(":").Id(method.Entity).Op("|").String())
  549. // case "put":
  550. // params = append(params, TS.Id(param).Op(":").Id(method.Entity))
  551. // callOptionsParam = "{id: entity.id}"
  552. // case "delete":
  553. // // params = append(params, TS.Id(param).Op(":").Id(method.Entity).Op("|").String())
  554. // params = append(params, TS.Id(param).Op(":").Id(method.Entity))
  555. // callOptionsParam = "{id: entity.id}"
  556. // param = ""
  557. // default:
  558. // panic(fmt.Sprintf("O método http '%s' para o recurso %s não foi definido!", method.HttpMethod, method.ID))
  559. // }
  560. // // *methods = append(*methods, TS.Id(method.ID).Params(params...).Op(":").Id("Observable<ServiceResponse>").Block(
  561. // *methods = append(*methods, TS.Id(method.ID).Params(params...).Op(":").Id("Observable<ServiceResponse>").Block(
  562. // TS.Return().This().Dot("options").Call(TS.Raw(callOptionsParam)).Dot(methodId).Call(TS.Id(param)).Endl(),
  563. // ).Line())
  564. // }