swagger-api / swagger-api/swagger-codegen

[HTML] Code generating into html, doesn't render additionalProperties of the object properly

Open
#10,014 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

Description

When trying to render my api generated into html2, responses do not render properly. The additionalProperties field seems to bug out and show empty object. On the other hand it works in the swagger editor.

swagger editor shows

generated html

Swagger-codegen version

Docker image of swagger codegen cli version 3 link

Swagger declaration file content or url
openapi: 3.0.0
info:
  version: "1.0.0"
  title: Example
servers:
  - description: Production API server
    url: https://prod-api-url.com
paths:
  /cmc/summary:
    get:
      summary: Summary of all market pairs and currencies available
      operationId: Get market summary
      responses:
        '200':
          description: OK
          content: 
            application/json:
              schema:
                $ref: '#/components/schemas/Summary'
        '400':
          $ref: '#/components/responses/400'
        '404':
          $ref: '#/components/responses/404'
        '500': 
          $ref: '#/components/responses/500'
  /cmc/assets:
    get:
      summary: Details of each currency available
      operationId: Get market assets
      responses:
        '200':
          description: OK
          content: 
            application/json:
              schema:
                $ref: '#/components/schemas/MarketAsset'
        '400':
          $ref: '#/components/responses/400'
        '404':
          $ref: '#/components/responses/404'
        '500': 
          $ref: '#/components/responses/500'
  /cmc/ticker:
    get:
      summary: Summary of all market pairs
      operationId: Get ticker summary
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  $ref: '#/components/schemas/MarketPair'
        '400':
          $ref: '#/components/responses/400'
        '404':
          $ref: '#/components/responses/404'
        '500': 
          $ref: '#/components/responses/500'
  /cmc/status:
    get:
      summary: Server status
      operationId: Get server status
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
        '400':
          $ref: '#/components/responses/400'
        '404':
          $ref: '#/components/responses/404'
        '500': 
          $ref: '#/components/responses/500'
  '/cmc/orderbook/{pair_symbol}':
    get:
      summary: Orderbook of given pair aranged by best asks/bids
      operationId: Get orderbook of coin pair 
      parameters:
        - $ref: '#/components/parameters/PairSymbol'
        - name: depth
          in: query
          description: Number of bids and asks to include or "None" to include none
          required: false
          schema:
            default: 0
            type: integer
            minimum: 0
        - name: level
          in: query
          required: false
          description: 1 for only best ask and bid, 2 for sorted asks and bids, 3 for no sorting
          schema:
            default: 2
            type: number
            enum: [1,2,3]
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrderBook'
        '400':
          $ref: '#/components/responses/400'
        '404':
          $ref: '#/components/responses/404'
        '500': 
          $ref: '#/components/responses/500'
  '/cmc/trades/{pair_symbol}':
    get:
      summary: Gets either buy, sell or all trades of last 24 hours
      operationId: get trades of coin pair 
      parameters:
        - $ref: '#/components/parameters/PairSymbol'
        - name: side
          in: query
          required: false
          description: Wether to return buy, sell orders when not provided all orders are returned 
          schema:
            $ref: '#/components/schemas/BuyOrSell'
        - name: type
          in: query
          required: false
          description: Wether to return buy, sell orders when not provided all orders are returned 
          schema:
            $ref: '#/components/schemas/BuyOrSell'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CoinPairTrades'
        '400':
          $ref: '#/components/responses/400'
        '404':
          $ref: '#/components/responses/404'
        '500': 
          $ref: '#/components/responses/500'
components:
  schemas:
    PositiveStringFloatOrInt:
      type: string
      pattern: '^([0-9]*[.])?\d+$'
      example: "0.1241"
    PositiveStringInteger:
      type: string
      pattern: '^\d+$'
      example: "1"
    StringZeroOrOne:
      type: string
      enum: ["0", "1"]
      example: "1"
    StringTrueOrFalse:
      type: string
      enum: ["true", "false"]
      example: "true"
    BuyOrSell:
      type: string
      enum: ["buy", "sell"]
      example: "buy"
    EthAddress:
      type: string
      minLength: 42
      maxLength: 42
      example: "0x0472ec0185ebb8202f3d4ddb0226998889663cf2"
    TxHash:
      type: string
      minLength: 85
      maxLength: 85
      example: "0x28b2aa205726766fb5ffe79ca2d1d498c7dd2f579b2164db2017e5019713df61"
    DailyTradeSummary:
      type: object
      properties:
        id: 
         $ref: '#/components/schemas/TxHash'
        last: 
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        percentChange: 
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        high24hr:
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        low24hr: 
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        highestBid:
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        lowestAsk:
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        baseVolume:
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        quoteVolume:
          $ref: "#/components/schemas/PositiveStringFloatOrInt" 
        isFrozen:  
          $ref: "#/components/schemas/StringZeroOrOne"
    Coin:
      type: object
      properties:
        name: 
          type: string
          example: "Purpose"
        address: 
          $ref: '#/components/schemas/EthAddress'
        image: 
          type: string
          format: uri
          example: '<url>/static/coins/byAddress/123.png'
        withdraw: 
          type: string
          enum: ["ON", "OFF"]
          example: "ON"
        deposit:
          type: string
          enum: ["ON", "OFF"]
          example: "OFF"
    Summary:
      type: object
      properties:
        data:
          type: object
          additionalProperties:
            $ref: "#/components/schemas/DailyTradeSummary" 
        coins:
          type: object
          additionalProperties:
            $ref: "#/components/schemas/Coin" 
    MarketAsset:
      type: object
      description: Returns object of objects that have dynamic keys which are the token names. 
          Response includes\n
          name - as name of the token\n
          unified_cryptoasset_id - the id of the token\n
          can_withdraw - string true or false\n
          can_deposit - string true or false\n
          min_withdraw - smallest amount possible to withdraw as a string\n 
          max_withdraw - biggest amount possible to withdraw as a string\n
          maker_fee - fee cost maker of the order pays\n
          taker_fee - fee cost taker of the order pays\n
      additionalProperties: 
        type: object
        properties:
          name: 
            type: string
            example: "Purpose"
          unified_cryptoasset_id: 
            $ref: '#/components/schemas/PositiveStringInteger'
          can_withdraw:
            $ref: '#/components/schemas/StringTrueOrFalse'
          can_deposit: 
            $ref: '#/components/schemas/StringTrueOrFalse'
          min_withdraw:
            $ref: '#/components/schemas/PositiveStringFloatOrInt'
          max_withdraw:
            $ref: '#/components/schemas/PositiveStringFloatOrInt'
          maker_fee: 
            $ref: '#/components/schemas/PositiveStringFloatOrInt'
          taker_fee:
            $ref: '#/components/schemas/PositiveStringFloatOrInt'
      
    TradeVolumes:
      type: object
      properties:
        base_volume: 
          $ref: '#/components/schemas/PositiveStringFloatOrInt'
        quote_volume: 
          $ref: '#/components/schemas/PositiveStringFloatOrInt'
    MarketPair:
      type: object
      allOf:
        - $ref: '#/components/schemas/TradeVolumes'       
        - type: object
          properties:
            base_id: 
              $ref: '#/components/schemas/PositiveStringInteger'
            quote_id: 
              $ref: '#/components/schemas/PositiveStringInteger' 
            last_price:
              $ref: '#/components/schemas/PositiveStringFloatOrInt'
            isFrozen: 
              $ref: '#/components/schemas/StringZeroOrOne'
    CoinPairTrades:
      type: array
      items:
        allOf:
        - $ref: '#/components/schemas/TradeVolumes'
        - type: object
          properties:
            tradeID: 
              type: string
              minLength: 66
              maxLength: 66
              example: "0x46d8a47176b478c5ed587b485fa6030ee2867c6d9480b7183050e146a93f8902"
            price: 
              $ref: '#/components/schemas/PositiveStringFloatOrInt'
            trade_timestamp:
              $ref: '#/components/schemas/PositiveStringInteger'
            type: 
              $ref: '#/components/schemas/BuyOrSell'
    OrderBookAsksOrBids:
      type: array
      items:
        type: array
        maxItems: 2
        minItems: 2
        example: ["0.11", "0.24"]
        items:
          type: string
          
    OrderBook:
      type: object
      properties:
        timestamp: 
          type: string
          example: '1557147462000'
        bids: 
          $ref: '#/components/schemas/OrderBookAsksOrBids'
        asks: 
          $ref: '#/components/schemas/OrderBookAsksOrBids'
    Error:
      type: object
      properties:
        error:
          type: string
  responses:
    '400':
      description: Invalid parameter was passed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '404':
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '500':
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  parameters:
    PairSymbol:
      name: pair_symbol
      in: path
      description: pair of coins symbol
      example: TRN_ETH
      required: true
      schema:
        type: string
Command line used for generation

Using powershell and docker by typing command

docker run -v path to swagger:/swagger.yaml -v path to output folder:/out swaggerapi/swagger-codegen-cli-v3 generate -l html2 -i /swagger.yaml -o /out

Steps to reproduce

In powershell type in the command mentioned above and open the index file in out folder

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 the supplied OpenAPI YAML and the swagger-codegen CLI Docker command, comparing the generated HTML with Swagger Editor. Focus on schemas using additionalProperties, including Summary, MarketAsset, and the /cmc/ticker response. Done means referenced object properties render in the generated HTML instead of appearing as empty objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, html, yaml
Domain
documentation, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.