'Observable<Pet>&Observable<HttpResponse<Pet>>&Observable<HttpEvent<Pet>>' 类型的参数不可分配给 'Observable<HttpResponse<Pet>>'

Argument of type 'Observable<Pet>&Observable<HttpResponse<Pet>>&Observable<HttpEvent<Pet>>' is not assignable to 'Observable<HttpResponse<Pet>>'

我正在尝试将生成的 openapi-generator angular 代码与 JHipster CRUD 视图连接起来。我试图为 Pet 实体一起编辑和定制它们,但是,我收到以下错误:

"Argument of type 'Observable & Observable<HttpResponse> & Observable<HttpEvent>' is not assignable to parameter of type 'Observable<HttpResponse>'."

JHipster 生成具有模型、服务和 CRUD 操作的实体。 OpenAPI 生成器生成的代码只有服务和模型。我正在尝试在 JHipster 模板中使用来自 OpenAPI gen 的模型和服务。我不知道要更改什么以消除错误。 来自 pet-update-component.ts 的代码,其中 petService.updatePet(pet)petService.addPet(宠物):

    import { Component, OnInit } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { finalize, map } from 'rxjs/operators';

import { Pet } from '../pet.model';
//import { PetService } from '../service/pet.service';
import { PetService } from 'build/openapi/api/pet.service';
import { ICategory } from 'app/entities/category/category.model';
import { CategoryService } from 'app/entities/category/service/category.service';
import { PetStatus } from 'app/entities/enumerations/pet-status.model';

@Component({
  selector: 'jhi-pet-update',
  templateUrl: './pet-update.component.html',
})
export class PetUpdateComponent implements OnInit {
  isSaving = false;
  petStatusValues = Object.keys(PetStatus);

  categoriesSharedCollection: ICategory[] = [];

  editForm = this.fb.group({
    id: [],
    petId: [],
    name: [null, [Validators.required]],
    petStatus: [],
    category: [],
  });

  constructor(
    protected petService: PetService,
    protected categoryService: CategoryService,
    protected activatedRoute: ActivatedRoute,
    protected fb: FormBuilder
  ) {}

  ngOnInit(): void {
    this.activatedRoute.data.subscribe(({ pet }) => {
      this.updateForm(pet);

      this.loadRelationshipsOptions();
    });
  }

  previousState(): void {
    window.history.back();
  }

  save(): void {
    this.isSaving = true;
    const pet = this.createFromForm();
    if (pet.id !== undefined) {
      this.subscribeToSaveResponse(this.petService.updatePet(pet));
    } else {
      this.subscribeToSaveResponse(this.petService.addPet(pet));
    }
  }

  trackCategoryById(index: number, item: ICategory): number {
    return item.id!;
  }

  protected subscribeToSaveResponse(result: Observable<HttpResponse<Pet>>): void {
    result.pipe(finalize(() => this.onSaveFinalize())).subscribe({
      next: () => this.onSaveSuccess(),
      error: () => this.onSaveError(),
    });
  }

  protected onSaveSuccess(): void {
    this.previousState();
  }

  protected onSaveError(): void {
    // Api for inheritance.
  }

  protected onSaveFinalize(): void {
    this.isSaving = false;
  }

  protected updateForm(pet: Pet): void {
    this.editForm.patchValue({
      id: pet.id,
      petId: pet.petId,
      name: pet.name,
      petStatus: pet.petStatus,
      category: pet.category,
    });

    this.categoriesSharedCollection = this.categoryService.addCategoryToCollectionIfMissing(this.categoriesSharedCollection, pet.category);
  }

  protected loadRelationshipsOptions(): void {
    this.categoryService
      .query()
      .pipe(map((res: HttpResponse<ICategory[]>) => res.body ?? []))
      .pipe(
        map((categories: ICategory[]) =>
          this.categoryService.addCategoryToCollectionIfMissing(categories, this.editForm.get('category')!.value)
        )
      )
      .subscribe((categories: ICategory[]) => (this.categoriesSharedCollection = categories));
  }

  protected createFromForm(): Pet {
    return {
      ...new Pet(),
      id: this.editForm.get(['id'])!.value,
      petId: this.editForm.get(['petId'])!.value,
      name: this.editForm.get(['name'])!.value,
      petStatus: this.editForm.get(['petStatus'])!.value,
      category: this.editForm.get(['category'])!.value,
    };
  }
}

这是 pet.service 的代码:

/**
     * Update an existing pet
     * Update an existing pet by Id
     * @param body Update an existent pet in the store
     * @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 updatePet(body: Pet, observe?: 'body', reportProgress?: boolean): Observable<Pet>;
    public updatePet(body: Pet, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<Pet>>;
    public updatePet(body: Pet, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<Pet>>;
    public updatePet(body: Pet, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (body === null || body === undefined) {
            throw new Error('Required parameter body was null or undefined when calling updatePet.');
        }

        let headers = this.defaultHeaders;

        // authentication (petstore_auth) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }

        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/xml',
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
            'application/json',
            'application/xml',
            'application/x-www-form-urlencoded'
        ];
        const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
        if (httpContentTypeSelected != undefined) {
            headers = headers.set('Content-Type', httpContentTypeSelected);
        }

        return this.httpClient.request<Pet>('put',`${this.basePath}/pet`,
            {
                body: body,
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

最后 pet.ts:

/**
 * Swagger Petstore - OpenAPI 3.0
 * This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! You can now help us improve the API whether it's by making changes to the definition itself or the code. That way, with time, we can improve the API in general, and expose some of the new features in OAS3. Some useful links: - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
 *
 * OpenAPI spec version: 1.0.11
 * Contact: apiteam@swagger.io
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */
import { Category } from './category';
import { Tag } from './tag';

export interface Pet { 
    id?: number;
    name: string;
    category?: Category;
    photoUrls: Array<string>;
    tags?: Array<Tag>;
    /**
     * pet status in the store
     */
    status?: Pet.StatusEnum;
}
export namespace Pet {
    export type StatusEnum = 'available' | 'pending' | 'sold';
    export const StatusEnum = {
        Available: 'available' as StatusEnum,
        Pending: 'pending' as StatusEnum,
        Sold: 'sold' as StatusEnum
    };
}

如果您对我应该更改的内容有任何想法,究竟是什么问题,或者我应该以什么方式解决这个问题,将不胜感激。谢谢!

好的,所以我所做的是用 Observable 和“Observable>”注释掉方法声明。我现在有不同的问题,但至少那些不再以红色突出显示。

/**
     * Update an existing pet
     * Update an existing pet by Id
     * @param body Update an existent pet in the store
     * @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 updatePet(body: Pet, observe?: 'body', reportProgress?: boolean): Observable<Pet>;
    public updatePet(body: Pet, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<Pet>>;
    //public updatePet(body: Pet, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<Pet>>;
    public updatePet(body: Pet, observe: any = 'body', reportProgress: boolean = false ): Observable<any>