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++][RESTSDK] support enums #2749

Merged
merged 9 commits into from
May 1, 2019
Merged

[C++][RESTSDK] support enums #2749

merged 9 commits into from
May 1, 2019

Conversation

dan-drl
Copy link
Contributor

@dan-drl dan-drl commented Apr 26, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to ls
    update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{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, 3.4.x, 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

This is a fix for #1316 (Enumerations not generated). It closely follows the recommendations provided by the poster with a couple minor differences.

Fixes #1316
@ravinikam @stkrwork @fvarose @etherealjoy @MartinDelille

@etherealjoy etherealjoy changed the title Cpp support enums [C++][RESTSDK] support enums Apr 27, 2019
@etherealjoy
Copy link
Contributor

etherealjoy commented Apr 28, 2019

The generated code does not compile in Linux.
I used this spec

---
# This is a sample Swagger spec, describing a simple API as a starting point.
swagger: "2.0"
info:
  description: Template Description
  version: 1.0.0
  title: Testspec


host: 0.0.0.0:8080
basePath: /api
schemes:
- http

paths:
  /v1.0/testintenum:
    get:
      description: ""
      operationId: testintenum
      responses:
        200:
          description: "Successful response"
          schema:
            $ref: '#/definitions/intEnum'
        400:
          description: "The request was not successfully executed."

  /v1.0/teststringenum:
    get:
      description: ""
      operationId: teststringenum
      responses:
        200:
          description: "Successful response"
          schema:
            $ref: '#/definitions/stringEnum'
        400:
          description: "The request was not successfully executed."

  /v1.0/testintenum1:
    get:
      description: ""
      operationId: testintenum1
      responses:
        200:
          description: "Successful response"
          schema:
            type: object
            additionalProperties:            
              $ref: '#/definitions/intEnum'
        400:
          description: "The request was not successfully executed."

  /v1.0/teststringenum1:
    get:
      description: ""
      operationId: teststringenum1
      responses:
        200:
          description: "Successful response"
          schema:
            type: array
            items:
              $ref: '#/definitions/stringEnum'
        400:
          description: "The request was not successfully executed."          

  /v1.0/test:
    get:
      description: ""
      operationId: test
      responses:
        200:
          description: "Successful response"
          schema:
            $ref: '#/definitions/enumeration'
        400:
          description: "The request was not successfully executed."

definitions:
  stringEnum:
    description: "string enum"
    enum:
      - abc
      - def
      - ghi
    type: string

  intEnum:
    description: "integer enum"
    enum:
      - 1
      - 2
      - 3
    type: integer

  enumeration:
    type: object
    description: "string enum"
    properties:
      enint:
        $ref: '#/definitions/intEnum'
      enstr:
        $ref: '#/definitions/stringEnum'
      enarr:
        type: array
        items:
          $ref: '#/definitions/stringEnum'
      enaobj:
        type: object
        additionalProperties:
          $ref: '#/definitions/intEnum' 

enum e{{classname}}
{
{{#allowableValues}}
{{#values}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Wont it be better to add {{#enumDescription}} ?

@etherealjoy
Copy link
Contributor

@stkrwork
Any comments from your side?

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.

looks good. maybe for the future it would be a good idea to extend samples for generators that support enums, to also generate samples including enums. @etherealjoy @wing328

@etherealjoy etherealjoy merged commit 40759a5 into OpenAPITools:master May 1, 2019
@etherealjoy etherealjoy added this to the 4.0.0 milestone May 1, 2019
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.

[cpp-restsdk] Enumerations not generated
4 participants