swagger-api / swagger-api/swagger-codegen

go-server: controller-api.mustache not used as template with -t flag

Open
#7,948 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 I generate a go-server with my own copy of the templates, any modification to the controller-api.mustache file does not change the generated code. In fact if I completely delete that template, the default.go file still gets generated. So it must be looking outside of the flagged -t directory.

Swagger-codegen version

swagger-codegen-cli-2.2.3

Swagger declaration file content or url
#https://swagger.io/specification
#https://openapi.design
paths:
  /Status:
    get:
      operationId: status
      summary: 'Returns important status information about Chain Query'
      consumes:
        - application/json
      produces:
        - application/json
      schemes:
        - http
      responses:
        '200':
          description: 'Chain Query status'
          schema:
            x-oad-type: reference
            $ref: '#/definitions/TableStatus'
          x-oad-type: response
    x-oad-type: operation
  /AddressSummary:
    get:
      operationId: AddressSummary
      summary: 'Returns a summary of Address activity'
      description: 'It returns sent, recieved, balance, and number of transactions it has been used in.'
      consumes:
        - application/json
      produces:
        - application/json
      schemes:
        - http
      responses:
        '200':
          description: 'It returns sent, recieved, balance, and number of transactions it has been used in.'
          schema:
            x-oad-type: reference
            $ref: '#/definitions/AddressSummary'
          x-oad-type: response
      parameters:
        -
          name: Address
          in: query
          description: 'LBRY Address you would like a summary on.'
          required: true
          type: string
          x-oad-type: parameter
    x-oad-type: operation
definitions:
  TableSize:
    x-oad-type: object
    type: object
    title: 'Table Size '
    description: 'Contains the name and number of rows for a table.'
    properties:
      TableName:
        x-oad-type: string
        type: string
        title: 'Table Name'
        description: 'Name of the table being referenced.'
      NrRows:
        x-oad-type: integer
        type: integer
        title: 'Number of Rows'
        description: 'The number of rows in the referenced table'
        format: int64
  TableStatus:
    x-oad-type: object
    type: object
    title: 'Table status of Chain Query'
    description: 'Contains an array of tables and their row count.'
    properties:
      Status:
        x-oad-type: array
        type: array
        title: 'Array of Tables'
        items:
          x-oad-type: reference
          $ref: '#/definitions/TableSize'
        uniqueItems: true
  AddressSummary:
    x-oad-type: object
    type: object
    title: 'Contains information about an address'
    properties:
      Address:
        x-oad-type: string
        type: string
        title: 'LBRY Address'
      TotalReceived:
        x-oad-type: number
        type: number
        title: ' Total Recieved'
        description: 'Total amount received by address from all transactions it was a part of.'
        format: double
        default: 0
      TotalSent:
        x-oad-type: number
        type: number
        title: 'Total Sent'
        description: 'Total amount sent from address for all transactions it was a part of.'
        format: double
        default: 0
      Balance:
        x-oad-type: number
        type: number
        title: Balance
        description: 'The current balance of an address'
        format: double
        default: 0
info:
  title: 'Chain Query'
  version: 0.1.0
  description: 'The LBRY blockchain is read into SQL where important structured information can be extracted through the Chain Query API.'
basePath: /api
schemes:
  - http
swagger: '2.0'
Command line used for generation
#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

(
    #download swagger-codegen-cli if not already there.
    cd "$DIR"
    mkdir -p $DIR/swagger
    if [ ! -f $DIR/swagger/swagger-codegen-cli.jar ]; then
        echo "swagger cli not found, downloading..."
        wget http://central.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.3/swagger-codegen-cli-2.2.3.jar -O ./swagger/swagger-codegen-cli.jar
    fi
    #Generate API docs

    executable="./swagger/swagger-codegen-cli.jar"

    export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
    agsDocs="$@ generate -i $DIR/chainquery.yaml -l dynamic-html  -o $DIR"
    agsServer="$@ generate -i $DIR/chainquery.yaml -l go-server -t $DIR/swagger/modules/go-server -DpackageName=chainqueryapis -o swagger/apiserver"
    agsClient_go="$@ generate -i $DIR/chainquery.yaml -l go  -o swagger/clients/go"
    agsClient_python="$@ generate -i $DIR/chainquery.yaml -l python  -o swagger/clients/python"


    java $JAVA_OPTS -jar $executable $agsDocs

    java $JAVA_OPTS -jar $executable $agsServer

    java $JAVA_OPTS -jar $executable $agsClient_go
    java $JAVA_OPTS -jar $executable $agsClient_python

)
Steps to reproduce

Just run the bash script on yaml. Review generated go-server content.

Suggest a fix/enhancement

Make sure the specified controller-api.mustache is actually used by the generator.

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

Start by reproducing the go-server generation command with the -t directory and inspect how controller-api.mustache is selected. Done means modifications or deletion of that custom template change the generated output, including whether default.go is produced.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.