Invalidation of swagger documentation

I can't figure out how to implement swagger (using the swagger-node -express project) in a node that just returns a response code

For example, for this markup path:

/api/user/create:
x-swagger-router-controller: api
get:
  operationId: userCreate
  parameters:
    - name: username
      in: query
      description: The username of the user.
      required: true
      type: string
    - name: password
      in: query
      description: The password of the user.
      required: true
      type: string
    - name: email
      in: query
      description: The email of the user.
      required: true
      type: string
  responses:
    '200':
      description: OK
    '412':
      description: User already exists

I would like to send an answer.

If i try

res.json(200);

or

res.sendStatus(200);

or even

res.sendStatus();

I get an error message: Answer verification error: void does not allow values

I get parseerror in the swagger editor if I submit

res.json()

And I get a void of no value

I feel like I have no way to try so that I can really use some kind of input.

+4
source share
2 answers

Finally it became clear what the error was:

: void

swagger.yaml

responses:
  '200':
    description: OK

, . , , .

responses:
  200:
    description: Success
    schema:
      title: reset
      properties:
        message:
          type: string
+2

, node , :

res.writeHead(code, message);
res.end();
0

Source: https://habr.com/ru/post/1619518/


All Articles