从API Explorer(Swagger)中删除嵌套关系

发布于 2025-01-24 17:02:07 字数 1685 浏览 0 评论 0 原文

我有 application 具有以下关系的模型:

  @belongsTo(() => Ido)
  idoId: string;


export interface ApplicationRelations {
  ido?: IdoWithRelations;
}

export type ApplicationWithRelations = Application & ApplicationRelations;

application 存储库如下:

  export class ApplicationRepository extends DefaultCrudRepository<
  Application,
  typeof Application.prototype.id,
  ApplicationRelations
> {
  public readonly user: BelongsToAccessor<
    User,
    typeof Application.prototype.id
  >;

  constructor(
    @inject('datasources.db') dataSource: DbDataSource,
    @repository.getter('UserRepository')
    protected userRepositoryGetter: Getter<UserRepository>,
  ) {
    super(Application, dataSource);
    this.user = this.createBelongsToAccessorFor('user', userRepositoryGetter);

    this.inclusionResolvers.delete('ido');
  }
}

以及以下关系 IDO Modal> Modal> Modal:

 @hasMany(() => Application)
  applications: Application[];

in post/ido 在Swagger中,我得到了此示例的创建示例:

{
  "applications": [
    {
      "status": "string",
      "createdAt": 0,
      "idoId": "string",
      "userId": "string",
      "ido": {
        "applications": [
          {
            "status": "string",
            "createdAt": 0,
            "idoId": "string",
            "userId": "string",
            "ido": {
              "applications": [
                "string"
              ],
}

是否有任何方法可以从Swagger中删除 IDO in IDO 的副本关系 ?,否则这并不重要,我可以手动删除第一个应用程序上方的所有字段?

I have Application model with following relation:

  @belongsTo(() => Ido)
  idoId: string;


export interface ApplicationRelations {
  ido?: IdoWithRelations;
}

export type ApplicationWithRelations = Application & ApplicationRelations;

Application repository looks like this:

  export class ApplicationRepository extends DefaultCrudRepository<
  Application,
  typeof Application.prototype.id,
  ApplicationRelations
> {
  public readonly user: BelongsToAccessor<
    User,
    typeof Application.prototype.id
  >;

  constructor(
    @inject('datasources.db') dataSource: DbDataSource,
    @repository.getter('UserRepository')
    protected userRepositoryGetter: Getter<UserRepository>,
  ) {
    super(Application, dataSource);
    this.user = this.createBelongsToAccessorFor('user', userRepositoryGetter);

    this.inclusionResolvers.delete('ido');
  }
}

And the following relation in IDO model:

 @hasMany(() => Application)
  applications: Application[];

In post /ido in swagger i am getting this example for creating:

{
  "applications": [
    {
      "status": "string",
      "createdAt": 0,
      "idoId": "string",
      "userId": "string",
      "ido": {
        "applications": [
          {
            "status": "string",
            "createdAt": 0,
            "idoId": "string",
            "userId": "string",
            "ido": {
              "applications": [
                "string"
              ],
}

Is there any ways to remove the duplicate and kind of curricular relation for ido in application from swagger? Or this doesn't really matter and i can just manually delete all fields above the first application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

背叛残局 2025-01-31 17:02:07

此答案从


OpenAPI/Swagger在其余层,这意味着您需要在各自的REST控制器内部查看,这将具有类似的内容:

@post('...')
function create(
  @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Application, {
            title: 'NewApplication',
            exclude: ['id'],
          }),
        },
      },
    })
)

您可以将其修改为排除关系:

@post('...')
function create(
  @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Application, {
            title: 'NewApplication',
            exclude: ['id'],
+          includeRelations: false,
          }),
        },
      },
    })
)

另一种选择是使用排除

更多信息可以在API文档中找到:

This answer was copied over from https://github.com/loopbackio/loopback-next/discussions/8536#discussioncomment-2655375.

OpenAPI/Swagger is at the REST layer, which means you'll need to look inside the respective REST Controller, which would have something similar to this:

@post('...')
function create(
  @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Application, {
            title: 'NewApplication',
            exclude: ['id'],
          }),
        },
      },
    })
)

You can modify it as such to exclude relations:

@post('...')
function create(
  @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Application, {
            title: 'NewApplication',
            exclude: ['id'],
+          includeRelations: false,
          }),
        },
      },
    })
)

An alternative is to use exclude.

More info can be found in the API docs: https://loopback.io/doc/en/lb4/apidocs.repository-json-schema.getjsonschemaref.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文