Невозможно подключить параметр go -swagger к маршруту - PullRequest
0 голосов
/ 07 февраля 2020

У меня есть следующая аннотация go -wagger:

// swagger:parameters callbackReg
type registrationParms struct {
    // Description of callback.
    // in: query
    // required: true
    callback string
}

// OK indicates that the HTTP request was successful.
//
// swagger:response
type OK struct {
    responseCode int
}

// BadRequest indicates that there was an error in
// the HTTP request.
//
// swagger:response
type BadRequest struct {
    responseCode int
}

// swagger:route POST /eprouter/1.0/registration callbackReg
//
// Callback registration API.
//
// Registers a callback URL for unsolicited messages.  A callback is registered for a given
// combination of message type (alarm, metric) and message encoding (Protobuf, XML).
//
// Schemes: http, https
//
// Responses:
//   200: OK
//   400: BadRequest

Я генерирую чванство YAML с swagger generate spec -o docs/swagger.yaml -w eprouter. Результирующий YAML не включает параметр запроса. Насколько я понимаю, идентификатор callbackReg должен t ie структура параметров маршрута. Что я делаю не так?

Сгенерированный YAML:

info: {}
paths:
  /eprouter/1.0/registration:
    post:
      description: |-
        Registers a callback URL for unsolicited messages.  A callback is registered for a given
        combination of message type (alarm, metric) and message encoding (Protobuf, XML).
      operationId: callbackReg
      responses:
        "200":
          $ref: '#/responses/OK'
        "400":
          $ref: '#/responses/BadRequest'
      schemes:
      - http
      - https
      summary: Callback registration API.
responses:
  BadRequest:
    description: |-
      BadRequest indicates that there was an error in
      the HTTP request.
    headers:
      responseCode:
        format: int64
        type: integer
  OK:
    description: OK indicates that the HTTP request was successful.
    headers:
      responseCode:
        format: int64
        type: integer
swagger: "2.0"

1 Ответ

0 голосов
/ 07 февраля 2020

Ответ заключается в том, что значения внутри структур параметров должны быть экспортированы (с большой буквы).

...