swagger-api / swagger-api/swagger-codegen

[cpprest] Codegen generates class with invalid syntax code causing compilation failure

Open
#8,464 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

The cpprest codegen generates the Client code with invalid syntax for API definition which contains list of strings as the body content.

Swagger-codegen version

2.3.1

Swagger declaration file content or url
swagger: '2.0'
info:
  title: Test Service API
  description: >-
    Test API definition
  version: 1.0.0
host: api.test.swagger.codegen
schemes:
  - https
basePath: /testswagger
produces:
  - application/json
paths:
  '/namespaces/{namespace}':
    post:
      summary: Summary
      description: >-
                  Some description
      operationId: addNamespaces
      parameters:
        - name: namespace
          in: path
          description:  namespace containing
          required: true
          type: string
        - name: subnamespace
          in: body
          description: List of sub namespace
          required: false
          schema:
            type: array
            items:
              type: string
      tags:
        - namespaces
      responses:
        '200':
          description: Map of  namespace

        '404':
          description: Namespace not found

        '500':
          description: Internal server error

Command line used for generation
Steps to reproduce

Copy the yaml content into online Swagger Editor. Generate client using the cpprest
Try to compile. Compilation will fails at
"jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() );"

Related issues/PRs
Suggest a fix/enhancement

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 by importing the supplied YAML into Swagger Editor and generating a cpprest client. Start at the generated code around jsonArray.push_back( item.get() ? item->toJson() : web::json::value::null() );, then trace the cpprest generator output that produced it. Done means the generated client compiles for this array-of-strings request body.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.