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

[cpp pistache] fix leading number in model names and apply modelNamePrefix in all cases #730

Merged

Conversation

etherealjoy
Copy link
Contributor

@etherealjoy etherealjoy commented Aug 3, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

  • Allow prefixing API Names and Model Names and their files, this allow usage of conflicting model names from different specs or to prevent a number in a class name and file name.
  • escape nameInCamelCase for variables with a leading number.
  • default prefix is empty string no change in current behaviour
  • other c++ petstore sample code remains unchanged.
  • Same behaviour as Qt5 client/server

usage example

java -jar ~/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar  \
generate -g cpp-pistache-server -i ~/test/swagger.yaml -o ~/gennew  \
--additional-properties modelNamePrefix=TET

With this sample spec

openapi: 3.0.0
info:
  version: 1.0.0
  title: Check 5gmmCapability
servers:
  - url: 'http://localhost:8080'
  
paths:
  /Check5gmmCapability:
    get:
      summary: Check property beginning with a number
      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/Content'
components:
  schemas:
    5gmmCapability:
      type: object
      properties:
        item1:
          type: string
        item2:
          type: integer
        5gItem:
          type: integer
    Content:
      type: object
      properties:
        type:
          $ref: '#/components/schemas/5gmmCapability'

we have something like this

class TET5gmmCapability --> File name model\TET5gmmCapability.h
class TETCheckApiImpl --> File name impl\TETCheckApiImpl.h
class TETCheckApi --> File name api\TETCheckApi.h
class TETModelBase --> File name model\TETModelBase.h
main --> File name TETCheckApiMainServer.cpp

Fixes #604

@stkrwork @MartinDelille @fvarose @ravinikam

@etherealjoy
Copy link
Contributor Author

etherealjoy commented Aug 3, 2018

@CyrilleBenard
This should solve your issue if you use it like mentioned in the example above

class  TET5gmmCapability
    : public TETModelBase
{


    bool _5gItemIsSet() const;

Copy link
Contributor

@stkrwork stkrwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you generate samples? also you might want to adapt the title to also mention that you are adding prefix to everything

@etherealjoy
Copy link
Contributor Author

etherealjoy commented Aug 4, 2018

@stkrwork
Default prefix is blank. So no change in sample code.
Also other c++ samples remain unchanged.
I generated all c++ samples

@etherealjoy etherealjoy changed the title [cpp pistache] fix leading number in model names [cpp pistache] fix leading number in model names and apply modelNamePrefix in all cases Aug 4, 2018
@etherealjoy
Copy link
Contributor Author

Shippable — Run 1974 status is TIMEOUT.

Issue not related to PR.

@etherealjoy etherealjoy deleted the cpp_pistache_fix_leading_number branch August 7, 2018 16:00
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
…refix in all cases (OpenAPITools#730)

* Fix numbers in nameInCamelCase. Add possibility to prefix Names to avoid conflicts
* Allow unique prefixing for template functions as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C++][Pistache-server] OpenApi properties starting with a number are not well handled
2 participants