swagger-api / swagger-api/swagger-codegen

BUG: Empty response objects generating HTML client

Open
#7,825 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hi,

if I generate an HTML client from yaml file (with swagger-codegen v2.3.1) the response object of the endpoints is empty.

The response object sometimes appears as "undefined" but most of the time it's empty.

I think it's a bug. The next yaml produces it.

swagger: "2.0"
info:
  description: "This is a template of the API documentation. This is based on the Viapps Firewall API."
  version: "1.5"
  title: "Viapps Firewall API"
  contact:
    name: "Viapps API support"
    email: "support@opencloudfactory.com"
  license:
    name: "OSL 3.0"
    url: "http://opensource.org/licenses/OSL-3.0"
host: "viapps.loc"
basePath: "/cmi-api/appliances/1/fw"
tags:
- name: firewall
  description: Everything about firewalls
- name: host
  description: Everything about firewall hosts
- name: zone
  description: Everything about firewall zones
schemes:
- "http"
paths:
  /host:
    get:
      tags:
      - "firewall"
      - "host"
      summary: "Finds the Firewall hosts"
      produces:
      - "application/json"
      parameters:
      - name: "start-index"
        in: "query"
        description: "Page number"
        required: false
        type: "integer"
        default: 0
      - name: "max-results"
        in: "query"
        description: "results per page"
        required: false
        type: "integer"
        default: 25
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            type: "array"
            items:
              $ref: '#/definitions/Host'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Resource not found"
    post:
      tags:
      - "firewall"
      - "host"
      summary: "Add a new host to the firewall"
      description: ""
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        description: "Host object that needs to be added to the firewall"
        required: true
        schema:
          $ref: '#/definitions/Host'
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        201:
          description: "Host created successfully"
          schema:
            $ref: '#/definitions/Host'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
  /host/{hostId}:
    get:
      tags:
      - "firewall"
      - "host"
      summary: "Retrieves the detail of the host"
      produces:
      - "application/json"
      parameters:
      - name: "hostId"
        in: "path"
        description: "Host identifier"
        required: true
        type: "string"
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            $ref: '#/definitions/Host'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Resource not found"
    put:
      tags:
      - "firewall"
      - "host"
      summary: "Update an existing host"
      description: ""
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "hostId"
        in: "path"
        description: "Host identifier"
        required: true
        type: "string"
      - name: "body"
        in: "body"
        description: "Host object that needs to updated to the firewall"
        required: true
        schema:
          $ref: '#/definitions/Host'
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        201:
          description: "Host updated successfully"
          schema:
            $ref: '#/definitions/Host'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Host not found"
    delete:
      tags:
      - "firewall"
      - "host"
      summary: "Deletes an existing host"
      parameters:
      - name: "hostId"
        in: "path"
        description: "Host identifier"
        required: true
        type: "string"
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Resource not found"
  /zone:
    get:
      tags:
      - "firewall"
      - "zone"
      summary: "Finds the Firewall zones"
      produces:
      - "application/json"
      parameters:
      - name: "start-index"
        in: "query"
        description: "Page number"
        required: false
        type: "integer"
        default: 0
      - name: "max-results"
        in: "query"
        description: "results per page"
        required: false
        type: "integer"
        default: 25
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            type: "array"
            items:
              $ref: '#/definitions/Zone'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Resource not found"
    post:
      tags:
      - "firewall"
      - "zone"
      summary: "Add a new zone to the firewall"
      description: ""
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        description: "Zone object that needs to be added to the firewall"
        required: true
        schema:
          $ref: '#/definitions/Zone'
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        201:
          description: "Zone created successfully"
          schema:
            $ref: '#/definitions/Zone'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
  /zone/{zoneId}:
    get:
      tags:
      - "firewall"
      - "zone"
      summary: "Retrieves the detail of the zone"
      produces:
      - "application/json"
      parameters:
      - name: "zoneId"
        in: "path"
        description: "Zone identifier"
        required: true
        type: "string"
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
          schema:
            $ref: '#/definitions/Zone'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Resource not found"
    put:
      tags:
      - "firewall"
      - "zone"
      summary: "Update an existing zone"
      description: ""
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "zoneId"
        in: "path"
        description: "Zone identifier"
        required: true
        type: "string"
      - name: "body"
        in: "body"
        description: "Zone object that needs to updated to the firewall"
        required: true
        schema:
          $ref: '#/definitions/Zone'
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        201:
          description: "Zone updated successfully"
          schema:
            $ref: '#/definitions/Zone'
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Host not found"
    delete:
      tags:
      - "firewall"
      - "zone"
      summary: "Deletes an existing zone"
      parameters:
      - name: "zoneId"
        in: "path"
        description: "Zone identifier"
        required: true
        type: "string"
      - name: "X-cmix-username"
        in: "header"
        required: true
        type: "string"
      - name: "X-cmix-token"
        in: "header"
        required: true
        type: "string"
      responses:
        200:
          description: "successful operation"
        400:
          description: "Bad request"
        401:
          description: "Unauthorized"
        404:
          description: "Resource not found"
definitions:
  Host:
    type: "object"
    required:
    - "id"
    - "name"
    - "zone"
    - "enabled"
    properties:
      id:
        type: "string"
        description: "Host identifier"
        example: "e8768da83081cbf7d3274c0f10cbf991"
      name:
        type: "string"
        description: "interface:{[{address-or-range[,address-or-range]}"
        example: "eth0:252.34.2.4/32"
      zone:
        type: "string"
        description: "firewall zone"
        example: "untrust"
      options:
        type: "string"
        description: "Host options (values separated by commas)"
        enum:
        - "blacklist"
        - "broadcast"
        - "destonly"
        - "ipsec"
        - "maclist"
        - "mss="
        - "nosmurfs"
        - "routeback"
        - "tcpflags"
        example: "ipsec,destonly"
      enabled:
        type: "boolean"
        description: "Parameter enables/disables host"
        example: true
      comments:
        type: "string"
        description: "Comments about host"
        example: "Host local printing (office 101)"
  Zone:
    type: "object"
    required:
    - "id"
    - "name"
    - "type"
    - "enabled"
    properties:
      id:
        type: "string"
        description: "Zone identifier"
        example: "e8768da83081cbf7d3274c0f10cbf991"
      name:
        type: "string"
        description: "Zone name"
        example: "a:b"
      type:
        type: "string"
        description: "Zone type"
        enum:
        - "ip"
        - "ipsec"
        - "firewall"
        - "bport"
        - "vserver"
        - "loopback"
        - "local"
        example: "ipsec"
      options:
        type: "string"
        description: "Zone options (values separated by commas) for the both (the ingoing and outgoing transit)"
        enum:
        - "dynamic_shared"
        - "reqid="
        - "spi="
        - "proto="
        - "mss="
        - "mode="
        - "tunnel-src="
        - "tunnel-dst="
        - "strict"
        - "next"
        example: "dynamic_shared,strict"
      options_in:
        type: "string"
        description: "Zone options (values separated by commas) for ingoing transit"
        enum:
        - "dynamic_shared"
        - "reqid="
        - "spi="
        - "proto="
        - "mss="
        - "mode="
        - "tunnel-src="
        - "tunnel-dst="
        - "strict"
        - "next"
        example: "dynamic_shared,strict"
      options_out:
        type: "string"
        description: "Zone options (values separated by commas) for outgoing transit"
        enum:
        - "dynamic_shared"
        - "reqid="
        - "spi="
        - "proto="
        - "mss="
        - "mode="
        - "tunnel-src="
        - "tunnel-dst="
        - "strict"
        - "next"
        example: "dynamic_shared,strict"
      enabled:
        type: "boolean"
        description: "Parameter enables/disables the zone"
        example: true
      comments:
        type: "string"
        description: "Comments about zone"
        example: "Local zone a for backoffice"
  ApiResponse:
    type: "object"
    properties:
      code:
        type: "integer"
        format: "int32"
      type:
        type: "string"
      message:
        type: "string"

Executed command: java -jar swagger-codegen-cli.jar generate -i Downloads/swagger-firewall-api-doc.yaml -l html2 -o ~/html2

Swagger-codegen version: 2.3.1

Thanks in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with swagger-codegen v2.3.1 using the supplied Swagger 2.0 YAML and generate the HTML client. Inspect the generated response objects for the Host and Zone endpoints, then verify that defined response schemas produce non-empty output rather than undefined or empty objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
html
Domain
tooling, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.