Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Pistache server - ModelBase::toJson prototype is not accorded with its implementation #414

Closed
CyrilleBenard opened this issue Jun 28, 2018 · 3 comments

Comments

@CyrilleBenard
Copy link

Description

The cpp-pistache-server code does not compile anymore (regression).
The generator produces two different method prototype between .cpp and .h content :

In model/ModelBase.h :

class  ModelBase
{
public:
    static nlohmann::json toJson(ModelBase const& content );
};

In model/ModelBase.cpp :

nlohmann::json ModelBase::toJson(ModelBase content )
{
    return content.toJson();
}
openapi-generator version

3.1.0-SNAPSHOT

OpenAPI declaration file content or url

All but here is a small example to facilitate ;)

openapi: 3.0.0
info:
  version: 1.0.0
  title: Simple API
  description: A simple API to illustrate OpenAPI concepts

servers:
  - url: https://example.io/v1

components:
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
security:
  - BasicAuth: []

paths:
  /artists:
    get:
      operationId: getList
      description: Returns a list of artists 
      responses:
        '200':
          description: Successfully returned a list of artists
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  required:
                    - username
                  properties:
                    artist_name:
                      type: string
                    artist_genre:
                      type: string
                    albums_recorded:
                      type: integer
                    username:
                      type: string

        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                properties:   
                  message:
                    type: string
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Simple API",
    "description": "A simple API to illustrate OpenAPI concepts"
  },
  "servers": [
    {
      "url": "https://example.io/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "BasicAuth": {
        "type": "http",
        "scheme": "basic"
      }
    }
  },
  "security": [
    {
      "BasicAuth": []
    }
  ],
  "paths": {
    "/artists": {
      "get": {
        "operationId": "getList",
        "description": "Returns a list of artists",
        "responses": {
          "200": {
            "description": "Successfully returned a list of artists",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "username"
                    ],
                    "properties": {
                      "artist_name": {
                        "type": "string"
                      },
                      "artist_genre": {
                        "type": "string"
                      },
                      "albums_recorded": {
                        "type": "integer"
                      },
                      "username": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Command line used for generation

openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-pistache-server -o .

Steps to reproduce

N/A

Related issues/PRs

N/A

Suggest a fix/enhancement

Declare the method in .cpp in the same way than in the header file

nlohmann::json ModelBase::toJson(ModelBase const & content)
{
    return content.toJson();
}


@etherealjoy
Copy link
Contributor

static nlohmann::json toJson(ModelBase const& content );

I don't know if we should revert this, because once the const is added we might need to implement const methods and stuff.

@CyrilleBenard
Copy link
Author

@etherealjoy I'm not sure to understand what you mean (?)
The const specifier is only onto the parameter, meaning that the method will not modify the object passed in argument. No more than that.
This must to be set to be compliant with its header declaration. Are you sure you do not confuse with the const onto the object (class) itself ?

@etherealjoy
Copy link
Contributor

Fixed with ##497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants