Yaml генерирует requestBody для запроса HTTP GET

У меня есть этот метод GET:

@GET
@Path("/getlisteclients")
@Operation(summary = "Récupération de la liste des clients", description = "Envoi de la liste de clients à MyIris")
@ApiResponses(value = {@ApiResponse(
        content = @Content(mediaType = "application/json",
                schema = @Schema(implementation = ResponseMouvementStockDTO.class)),
        responseCode = "200", description = "Liste de clients envoyée."
),
        @ApiResponse(
                content = @Content(mediaType = "application/json",
                        schema = @Schema(implementation = ErreurMouvementStockDTO.class)),
                description = "Une erreur technique est survenue.")})

@Produces("application/json")
@GetMapping("/mobile/getlisteclients")
public ResponseEntity<ResponseMouvementStockDTO> getListeDeClients(@RequestHeader HttpHeaders headers);

и генерирует эту часть в файле mobile.yaml:

/mobile/getlisteclients:
get:
  summary: Récupération de la liste des clients
  description: Envoi de la liste de clients à MyIris
  operationId: getListeDeClients
  requestBody:
    content:
      '*/*':
        schema:
          type: object
          properties:
            all:
              type: object
              additionalProperties:
                type: string
              writeOnly: true
            empty:
              type: boolean
            location:
              type: string
              format: uri
            host:
              type: object
              properties:
                address:
                  type: object
                  properties:
                    canonicalHostName:
                      type: string
                    hostAddress:
                      type: string
                    address:
                      type: array
                      items:
                        type: string
                        format: byte
                    hostName:
                      type: string
                    multicastAddress:
                      type: boolean
                    anyLocalAddress:
                      type: boolean
                    loopbackAddress:
                      type: boolean
                    linkLocalAddress:
                      type: boolean
                    siteLocalAddress:
                      type: boolean
                    mcglobal:
                      type: boolean
                    mcnodeLocal:
                      type: boolean
                    mclinkLocal:
                      type: boolean
                    mcsiteLocal:
                      type: boolean
                    mcorgLocal:
                      type: boolean
                port:
                  type: integer
                  format: int32
                unresolved:
                  type: boolean
                hostName:
                  type: string
                hostString:
                  type: string
            lastModified:
              type: integer
              format: int64
            contentType:
              $ref: '#/components/schemas/MediaType'
            contentLength:
              type: integer
              format: int64
            date:
              type: integer
              format: int64
            ifModifiedSince:
              type: integer
              format: int64
            connection:
              type: array
              items:
                type: string
            origin:
              type: string
            range:
              type: array
              items:
                $ref: '#/components/schemas/HttpRange'
            acceptLanguageAsLocales:
              type: array
              items:
                type: object
                properties:
                  language:
                    type: string
                  script:
                    type: string
                  country:
                    type: string
                  variant:
                    type: string
                  extensionKeys:
                    uniqueItems: true
                    type: array
                    items:
                      type: string
                  unicodeLocaleAttributes:
                    uniqueItems: true
                    type: array
                    items:
                      type: string
                  unicodeLocaleKeys:
                    uniqueItems: true
                    type: array
                    items:
                      type: string
                  iso3Language:
                    type: string
                  iso3Country:
                    type: string
                  displayLanguage:
                    type: string
                  displayScript:
                    type: string
                  displayCountry:
                    type: string
                  displayVariant:
                    type: string
                  displayName:
                    type: string
            accessControlAllowMethods:
              type: array
              items:
                type: string
                enum:
                - GET
                - HEAD
                - POST
                - PUT
                - PATCH
                - DELETE
                - OPTIONS
                - TRACE
            accessControlExposeHeaders:
              type: array
              items:
                type: string
            accessControlMaxAge:
              type: integer
              format: int64
            accessControlRequestMethod:
              type: string
              enum:
              - GET
              - HEAD
              - POST
              - PUT
              - PATCH
              - DELETE
              - OPTIONS
              - TRACE
            accessControlAllowHeaders:
              type: array
              items:
                type: string
            accessControlRequestHeaders:
              type: array
              items:
                type: string
            contentDisposition:
              $ref: '#/components/schemas/ContentDisposition'
            accessControlAllowCredentials:
              type: boolean
            accessControlAllowOrigin:
              type: string
            ifUnmodifiedSince:
              type: integer
              format: int64
            etag:
              type: string
            ifMatch:
              type: array
              items:
                type: string
            ifNoneMatch:
              type: array
              items:
                type: string
            acceptPatch:
              type: array
              items:
                $ref: '#/components/schemas/MediaType'
            accept:
              type: array
              items:
                $ref: '#/components/schemas/MediaType'
            expires:
              type: integer
              format: int64
            allow:
              uniqueItems: true
              type: array
              items:
                type: string
                enum:
                - GET
                - HEAD
                - POST
                - PUT
                - PATCH
                - DELETE
                - OPTIONS
                - TRACE
            cacheControl:
              type: string
            upgrade:
              type: string
            acceptLanguage:
              type: array
              items:
                type: object
                properties:
                  range:
                    type: string
                  weight:
                    type: number
                    format: double
            basicAuth:
              type: string
              writeOnly: true
            vary:
              type: array
              items:
                type: string
            bearerAuth:
              type: string
              writeOnly: true
            contentLanguage:
              type: object
              properties:
                language:
                  type: string
                script:
                  type: string
                country:
                  type: string
                variant:
                  type: string
                extensionKeys:
                  uniqueItems: true
                  type: array
                  items:
                    type: string
                unicodeLocaleAttributes:
                  uniqueItems: true
                  type: array
                  items:
                    type: string
                unicodeLocaleKeys:
                  uniqueItems: true
                  type: array
                  items:
                    type: string
                iso3Language:
                  type: string
                iso3Country:
                  type: string
                displayLanguage:
                  type: string
                displayScript:
                  type: string
                displayCountry:
                  type: string
                displayVariant:
                  type: string
                displayName:
                  type: string
            pragma:
              type: string
            acceptCharset:
              type: array
              items:
                type: object
                properties:
                  registered:
                    type: boolean
          additionalProperties:
            type: array
            items:
              type: string
  responses:
    "200":
      description: Liste de clients envoyée.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ResponseMouvementStockDTO'
    default:
      description: Une erreur technique est survenue.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErreurMouvementStockDTO'

Когда я помещаю этот yaml в Swagger, у меня возникает эта ошибка:

Семантическая ошибка в путях./mobile/getlisteclients.get.requestBody Операции GET не могут иметь requestBody.

Я не знаю, почему здесь генерируется requestBody. Я уже пытаюсь удалить @RequestHeader, а затем Чистая установка Maven, но без изменений.

Ваш контроллер помечен как Controller или RestController ?

Mihail 22.03.2022 14:27

@Mihail Это отмечено RestController.

Bastien 22.03.2022 14:28

Вы используете Springfox или Springdoc или что-то еще? Какой DTO соответствует сгенерированному телу запроса (т. е. какой DTO имеет свойства all, empty, location, host и т. д.)? Упоминается ли этот DTO где-либо в аннотациях контроллера?

Helen 22.03.2022 14:38

@Helen Я не использую ни один из них, а all/empty/location/host... исходит из HttpHeadersHostAdresse, сгенерированного файла, полученного из HttpHeaders в моем методе

Bastien 22.03.2022 14:43
Пользовательский скаляр GraphQL
Пользовательский скаляр GraphQL
Листовые узлы системы типов GraphQL называются скалярами. Достигнув скалярного типа, невозможно спуститься дальше по иерархии типов. Скалярный тип...
Как вычислять биты и понимать побитовые операторы в Java - объяснение с примерами
Как вычислять биты и понимать побитовые операторы в Java - объяснение с примерами
В компьютерном программировании биты играют важнейшую роль в представлении и манипулировании данными на двоичном уровне. Побитовые операции...
Поднятие тревоги для долго выполняющихся методов в Spring Boot
Поднятие тревоги для долго выполняющихся методов в Spring Boot
Приходилось ли вам сталкиваться с требованиями, в которых вас могли попросить поднять тревогу или выдать ошибку, когда метод Java занимает больше...
Полный курс Java для разработчиков веб-сайтов и приложений
Полный курс Java для разработчиков веб-сайтов и приложений
Получите сертификат Java Web и Application Developer, используя наш курс.
1
4
29
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Итак, мне удалось заставить его работать и удалить ошибки в Swagger, добавив @параметр и @QueryParam :

@GET
@Path("/getlisteclients")
@Operation(summary = "Récupération de la liste des clients", description = "Envoi de la liste de clients à MyIris")
@ApiResponses(value = {@ApiResponse(
        content = @Content(mediaType = "application/json",
                schema = @Schema(implementation = ResponseMouvementStockDTO.class)),
        responseCode = "200", description = "Liste de clients envoyée."
),
        @ApiResponse(
                content = @Content(mediaType = "application/json",
                        schema = @Schema(implementation = ErreurMouvementStockDTO.class)),
                description = "Une erreur technique est survenue.")})

@Produces("application/json")
@GetMapping("/mobile/getlisteclients")
public ResponseEntity<ResponseMouvementStockDTO> getListeDeClients(@Parameter(description = "headers", required = true) @QueryParam("headers") @RequestHeader HttpHeaders headers);

Другие вопросы по теме