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] model is not a namespace-name #637

Closed
CyrilleBenard opened this issue Jul 24, 2018 · 4 comments
Closed

[C++][Pistache-server] model is not a namespace-name #637

CyrilleBenard opened this issue Jul 24, 2018 · 4 comments
Assignees
Milestone

Comments

@CyrilleBenard
Copy link

Description

The generator seems to add systematically the instruction using namespace xxx::yyy::model ; without any needs and without, at least, one corresponding definition of the model namespace. The C++ compilation failed.

Compilation error looks like

In file included from api/CheckApi.cpp:13:0:
api/CheckApi.h:39:60: error: ‘model’ is not a namespace-name
 using namespace com::bcom::amf::microservice::server::ms1::model;
                                                            ^
api/CheckApi.h:39:65: error: expected namespace-name before ‘;’ token
 using namespace com::bcom::amf::microservice::server::ms1::model;
                                                                 ^
api/CheckApi.cpp:23:60: error: ‘model’ is not a namespace-name
 using namespace com::bcom::amf::microservice::server::ms1::model;
                                                            ^
api/CheckApi.cpp:23:65: error: expected namespace-name before ‘;’ token
 using namespace com::bcom::amf::microservice::server::ms1::model;
                                                                 ^

NOTE : The hierarchical namespace names shown above is mine but the bug issue is non dependent. Using the default namespaces will produce a similar compilation error.
If needed, you will find my config.json file content below

openapi-generator version

3.1.2-SNAPSHOT

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Check unknown namespace-name model
servers:
  - url: http://localhost:8080
paths:
  /check:
    get:
      summary: blabla
      operationId: list
      tags:
        - Check
      responses:
        '200':
          description: Everythings gonna be alright
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Bytes"
      default:
        description: unexpected error
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Bytes"

components:
  schemas:
    Bytes:
      format: byte
      type: string

    Content:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/Bytes'
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Check unknown namespace-name model"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/check": {
      "get": {
        "summary": "blabla",
        "operationId": "list",
        "tags": [
          "Check"
        ],
        "responses": {
          "200": {
            "description": "Everythings gonna be alright",
            "headers": {
              "x-next": {
                "description": "A link to the next page of responses",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Bytes"
                }
              }
            }
          }
        },
        "default": {
          "description": "unexpected error",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Bytes"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Bytes": {
        "format": "byte",
        "type": "string"
      },
      "Content": {
        "type": "object",
        "properties": {
          "type": {
            "$ref": "#/components/schemas/Bytes"
          }
        }
      }
    }
  }
}

config.json :

{
    "modelPackage"   : "com.bcom.amf.microservice.server.ms1.model",
    "apiPackage"     : "com.bcom.amf.microservice.server.ms1.api"
}
Command line used for generation

Generate :

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

Compile :

g++ -c  -I./api -I./model -I./impl -Wall -g -std=c++11 -o obj/api/CheckApi.o api/CheckApi.cpp
Steps to reproduce

Generate & compile

Related issues/PRs

N/A

Suggest a fix/enhancement

In case the generator needs to let this behavior as this, include systematically the ModelBase.h header file ... but I don't think its the best proposal ever seen 🤣
The generator should add the using namespace xxx::yyyy::model only when using, at least, one model class.

@etherealjoy
Copy link
Contributor

@CyrilleBenard
Will be solved by #733

@etherealjoy etherealjoy self-assigned this Aug 7, 2018
@etherealjoy etherealjoy added this to the 3.2.1 milestone Aug 7, 2018
@CyrilleBenard
Copy link
Author

Unfortunately there is another condition in which this bug occurs. I just found it using a heavy YAML file. Below a minimalist YAML file to reproduce it.

If one path uses a model content and a second path below the first one does NOT need a model, the generator still insert the line using namespace xx::yyy::model without any corresponding include file.

See below the YAML file to reproduce this bug
First path is /CheckByteArray
Second path is /check

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Check unknown namespace-name model
servers:
  - url: https://{apiRoot}/namf-comm/v1
    variables:
      apiRoot:
        default: locahhost:8080
paths:
  /CheckByteArray:
    get:
      summary: Check Byte Array generation
      operationId: list
      tags:
        - Check
      responses:
        '200':
          description: Every things gonna be alright
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Content"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Content"
  /check:
    get:
      summary: blabla
      operationId: list
      tags:
        - Check Model Namespace
      responses:
        '200':
          description: Everythings gonna be alright
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                type: string
        default:
          description: unexpected error

components:
  schemas:
    Bytes:
      format: byte
      type: string

    Content:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/Bytes'

@etherealjoy
Copy link
Contributor

@CyrilleBenard

description: Every things gonna be alright

XD

[100%] Linking CXX executable check_api_server
[100%] Built target check_api_server

Solved in #775.

@wing328 wing328 modified the milestones: 3.2.2, 3.2.3 Aug 22, 2018
@CyrilleBenard
Copy link
Author

CyrilleBenard commented Aug 22, 2018

Confirmed. It fixes this issue 👍
EDIT : (in #775)

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

No branches or pull requests

3 participants