#angular #observable #angular-services #openapi-generator
Вопрос:
Я сгенерировал API-сервисы и модели, используя генератор OpenAPI для Angular.
Я хочу опубликовать сообщение, используя сгенерированный сервис API. Это сгенерированная служба:
/**
* Create a Issue
* @param requestId Unique identifier of the call determined by the client.
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public createIssue(requestId: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<object>;
public createIssue(requestId: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpResponse<object>>;
public createIssue(requestId: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpEvent<object>>;
public createIssue(requestId: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable<any> {
// some code here
return this.httpClient.post<object>(`${this.configuration.basePath}/tickets`,
{
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}
В своем компоненте я называю службу таким образом:
submitForm(): void {
for (const i in this.newTickettForm.controls) {
this.newTickettForm.controls[ i ].markAsDirty();
this.newTickettForm.controls[ i ].updateValueAndValidity();
}
let request = '382288f0-eb39-4985-9474-e9a1ae62f7e4'; // string
let body = this.newTickettForm.value; // object form values
this.issueService.createIssue(request, body).subscribe(
response => {
console.log(response);
}
)
}
Но я получаю 404, когда звоню, и в браузере я получаю этот полезный ответ:
{
"responseType":"json",
"headers":{
"normalizedNames":{
},
"lazyUpdate":[
{
"name":"requestId",
"value":"382288f0-eb39-4985-9474-e9a1ae62f7e4",
"op":"s"
},
{
"name":"Accept",
"value":"application/json",
"op":"s"
},
{
"name":"Content-Type",
"value":"application/json",
"op":"s"
}
],
"headers":{
},
"lazyInit":{
"normalizedNames":{
},
"lazyUpdate":null,
"headers":{
}
}
},
"observe":"body",
"reportProgress":false
}
Что я делаю не так?
Комментарии:
1. Вы ввели правильный базовый путь в app.module.ts?