Search code examples
pythonflaskswaggerswagger-codegenconnexion

How to return only a status code without a body with connexion framework mock


I try to use Connexion as an API first framework the generates a Mock from a Swagger File (attached at the end). Then I run Connexion with the connexion run ./swagger/swagger.yaml --mock=all --debug command. This works for the get and post method but fails for the patch method that should only return a 201. For this cases Connexion returns the following: "No example response was defined."

Is there a way to tell Connexion that no example body is needed in the Mock and only a http code should be returned?

swagger: '2.0'
info:
  description: Manages the customer of a digital marketplace
  version: 1.0.0
  title: Customers
  contact:
    email: [email protected]
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: virtserver.swaggerhub.com
basePath: /
schemes:
  - https
paths:
  /customers/{customer-id}/clients:
    post:
      summary: Adds a client to a customer identity.
      description: https://auth0.com/docs/api/management/v2#!/Clients/post_clients
      parameters:
        - in: path
          name: customer-id
          type: string
          description: The id of the customer.
          required: true
        - in: body
          name: client
          description: "Client item data"
          required: false
          schema:
            type: object
            required:
              - client_name
              - client_description
            properties:
              client_name:
                type: string
                example: "Peffermiza Broker Frontend"
              client_description:
                type: string
                example: "This is the the frontend app for brokers."
              allowed_callback_urls:
                type: array
                items:
                  type: string
                  example: 'http://localhost:3000/callback'
              allowed_logout_urls:
                type: array
                items:
                  type: string
                  example: 'http://localhost:3000/logout'
      produces:
        - application/json
      responses:
        201:
          description: OK
          schema:
            $ref: '#/definitions/Client'
        400:
          description: "invalid input, object invalid"
        409:
          description: "an existing item already exists"
      security:
      - oauth2:
        - "https://api.d10l.de/customers:write"
    get:
      summary: Gets the clients of a customer identity.
      description: https://auth0.com/docs/api/management/v2#!/Clients/get_clients
      parameters:
        - in: path
          name: customer-id
          type: string
          description: The id of the customer.
          required: true
      produces:
        - application/json
      responses:
        200:
          description: A list of clients of the customer identity
          schema:
              type: object
              properties:
                clients:
                  type: array
                  items:
                    $ref: '#/definitions/Client'
              example:
                clients:
                  - date_created: "2016-08-29T09:12:33.001Z"
                    allowed_logout_urls:
                      - "http://localhost:3000/logout"
                      - "http://localhost:3000/logout"
                    client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
                    allowed_callback_urls:
                      - "http://localhost:3000/callback"
                      - "http://localhost:3000/callback"
                    client_name: "Peffermiza Broker Frontend"
                    client_description: 'The new broker application for the south region.'
                    client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
                  - date_created: "2016-08-29T09:12:33.001Z"
                    allowed_logout_urls:
                      - "http://localhost:3000/logout"
                      - "http://localhost:3000/logout"
                    client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
                    allowed_callback_urls:
                      - "http://localhost:3000/callback"
                      - "http://localhost:3000/callback"
                    client_name: "The new broker application for the south region."
                    client_description: 
                    client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
        400:
          description: "bad input parameter"
      security:
      - oauth2:
        - "https://api.d10l.de/customers:read"
  /customers/{customer-id}/clients/{client-id}:
    patch:
      summary: Update the client of a customer
      description: https://auth0.com/docs/api/management/v2#!/Clients/patch_clients_by_id
      parameters: 
        - in: path
          name: customer-id
          type: string
          description: The id of the customer.
          required: true
        - in: path
          name: client-id
          type: string
          description: The id of the customer.
          required: true
        - in: body
          name: client
          schema:
            $ref: '#/definitions/Client'
      responses:
        200:
          description: OK
      security: 
        - oauth2: 
          - "https://api.d10l.de/customers:write"
securityDefinitions:
  oauth2:
    type: oauth2
    authorizationUrl: 'https://d10l.eu.auth0.com/authorize'
    tokenUrl: 'https://d10l.eu.auth0.com/oauth/token'
    flow: accessCode
    scopes:
      'https://api.d10l.de/customers:write': Access right needed to write to the customers service.
      'https://api.d10l.de/customers:read': Access right needed to read from the customers service.
definitions:
  Client:
    type: object
    required:
      - client_id
      - client_name
      - client_description
      - date_created  
      - client_secret
      - allowed_callback_urls
      - allowed_logout_urls
    properties:
      client_id:
        type: string
        example: 94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G
      client_name:
        type: string
        example: 'Peffermiza Broker Frontend'
      client_description:
        type: string
        example: 'The new broker application for the south region.' 
      date_created:
        type: string
        format: int32
        example: '2016-08-29T09:12:33.001Z'
      client_secret:
        type: string
        example: 94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G
      allowed_callback_urls: 
        type: array
        items:
          type: string
          example: 'http://localhost:3000/callback'
      allowed_logout_urls:
        type: array
        items:
          type: string
          example: 'http://localhost:3000/logout'
    example:
      date_created: "2016-08-29T09:12:33.001Z"
      allowed_logout_urls:
      - "http://localhost:3000/logout"
      - "http://localhost:3000/logout"
      client_secret: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"
      allowed_callback_urls:
      - "http://localhost:3000/callback"
      - "http://localhost:3000/callback"
      client_name: "Peffermiza Broker Frontend"
      client_description: "The new broker backend for the south region."
      client_id: "94YJaDlR5QDpaS7Em6aC02_gj6kA1Q_G"

Solution

  • Currently Connexion does not support that. What you can do, is create a empty example. That should work for you case.

    I would also recommend opening a issue in the Connexion repository.