简体   繁体   中英

How to ignore Swagger request fields using Spring OpenAPI 3.0?

We have the following Token schema while scmOrg is defined as a foreign key.

{
  id        integer($int64)
  scmOrg    ScmOrg{...}
  type      string
  rawToken  string
}

When opening the Swagger console, it builds the example input like this:

{
  "id": 0,
  "scmOrg": {
    "id": 0,
    "scm": {
      "id": 0,
      "name": "string",
      "baseUrl": "string",
      "clientId": "string",
      "clientSecret": "string"
    },
    "name": "string",
    "team": "string"
  },
  "type": "string",
  "rawToken": "string"
}

A new token can be added only for an existing scmOrg entity, so what I really want it to be is something more strait forward like this:

{
  "id": 0,
  "scmOrg": {
    "id": 0
  },
  "type": "string",
  "rawToken": "string"
}

Is it possible with Swagger?

AFAIK there is no way to achieve this. In fact you can edit your models to set @ApiModelProperty(hidden = true) . But, I am against doing so and in addition whatever you do on the model will be overwritten next time it is regenerated. Check this link, it is a bit old but it seems that the guys behind swagger don't seem to have this in their roadmap. https://community.smartbear.com/t5/Swagger-Open-Source-Tools/How-to-hide-Model-Information/mp/183188#M347

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM