Я сталкиваюсь с проблемой в Apag Swagger? - PullRequest
0 голосов
/ 13 марта 2019

Swagger.yml

swagger: "2.0"
info:
  version: "0.0.1"
  title: Movie DB
# during dev, should point to your local machine
host: localhost:8000
# basePath prefixes all resource paths 
basePath: /
# 
schemes:
  # tip: remove http to make production-grade
  - http
  - https
# format of bodies a client can send (Content-Type)
consumes:
  - application/json
# format of the responses to the client (Accepts)
produces:
  - application/json
paths:
  /movies:
    # binds a127 app logic to a route
    x-swagger-router-controller: movies
    get:
      description: Returns 'Hello' to the caller
      # used as the method name of the controller
      operationId: index
      parameters:
        - name: name
          in: query
          description: The name of the person to whom to say hello
          required: false
          type: string
      responses:
        "200":
          description: Success
          schema:
            # a pointer to a definition
            $ref: "#/definitions/MovieListBody"
        # responses may fall through to errors
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
  /swagger:
    x-swagger-pipe: swagger_raw
# complex objects have schema definitions

    post:
      description: Creates a new movie entry
      operationId: create
      parameters:
        - name: movie
          required: true
          in: body
          description: a new movie details
          schema:
            $ref: "#/definitions/MovieBody"
      responses:
        "200":
          description: a successfully stored movie details
          schema:
            $ref: "#/definitions/MovieBody"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse" 

definitions:
  MovieListBody:
    required:
      - movies
    properties:
      movies:
        type: array
        items:
          $ref: "#/definitions/Movie"

  Movie:
    required:
      - title
      - gener
      - year
    properties:
      title:
        type: string
      gener:
        type: string
      year:
        type: integer

  MovieBody:
    required:
      - movie
    properties:
      movie:
        $ref: "#/definitions/Movie"

  ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string

Получаю эту ошибку:

Маршрут, определенный в спецификации Swagger (/ movies), но не определен после операции

Я новичок в этой концепции Swagger API. Я попробовал грубую операцию в Swagger API. Метод get работает нормально, но я попытался post показать этот тип проблемы. Я пытался шаг за шагом смотреть видео API Swagger. Я попытался получить функцию, данные успешно извлечены в db.but я пытался опубликовать данные на mongodb, используя Swagger API, он выдает этот тип ошибки ....

Как это исправить? Кто-нибудь может предложить какое-либо решение?

1 Ответ

0 голосов
/ 13 марта 2019

Вам не нужен узел /swagger, просто узел post на том же уровне, что и узел get в пути /movies.POST и GET - это операции, которые могут выполняться на конечной точке «фильмов».

В настоящее время ваш чванство поддерживает GET /movies/ и POST /swagger/, поскольку у вас есть путь, называемый «чванство».

Структура должна стать:

paths:
  /movies:
    get:
      # All the get properties
    post:
      # All the post properties
definitions:
  # All the definitions you need

А вот обновленная копия вашего чванства:

swagger: "2.0"
info:
  version: "0.0.1"
  title: Movie DB
# during dev, should point to your local machine
host: localhost:8000
# basePath prefixes all resource paths 
basePath: /
# 
schemes:
  # tip: remove http to make production-grade
  - http
  - https
# format of bodies a client can send (Content-Type)
consumes:
  - application/json
# format of the responses to the client (Accepts)
produces:
  - application/json
paths:
  /movies:
    # binds a127 app logic to a route
    x-swagger-router-controller: movies
    get:
      description: Returns 'Hello' to the caller
      # used as the method name of the controller
      operationId: index
      parameters:
        - name: name
          in: query
          description: The name of the person to whom to say hello
          required: false
          type: string
      responses:
        "200":
          description: Success
          schema:
            # a pointer to a definition
            $ref: "#/definitions/MovieListBody"
        # responses may fall through to errors
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
    post:
      description: Creates a new movie entry
      operationId: create
      parameters:
        - name: movie
          required: true
          in: body
          description: a new movie details
          schema:
            $ref: "#/definitions/MovieBody"
      responses:
        "200":
          description: a successfully stored movie details
          schema:
            $ref: "#/definitions/MovieBody"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse" 
definitions:
  MovieListBody:
    required:
      - movies
    properties:
      movies:
        type: array
        items:
          $ref: "#/definitions/Movie"

  Movie:
    required:
      - title
      - gener
      - year
    properties:
      title:
        type: string
      gener:
        type: string
      year:
        type: integer

  MovieBody:
    required:
      - movie
    properties:
      movie:
        $ref: "#/definitions/Movie"

  ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string
...