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

invalid enum generation on javascript-closure-angular-client and typescript-angular-client #2739

Open
dusty opened this issue Apr 29, 2016 · 3 comments

Comments

@dusty
Copy link

dusty commented Apr 29, 2016

Using swagger editor 2.9.9 when I generate a closure angular or typescript angular enums are not properly defined when spaces appear in the string. They are normalized in the javascript client.

schema:

{
  "swagger" : "2.0",
  "info" : {
    "description" : "Enum",
    "version" : "1.0.0",
    "title" : "Enum"
  },
  "host" : "localhost",
  "basePath" : "/api",
  "schemes" : [ "http" ],
  "consumes" : [ "application/json" ],
  "produces" : [ "application/json" ],
  "paths" : {
    "/example" : {
      "post" : {
        "summary" : "Example",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : true,
          "schema" : {
            "$ref" : "#/definitions/body"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "success"
          }
        }
      }
    }
  },
  "definitions" : {
    "body" : {
      "type" : "object",
      "properties" : {
        "someProperty" : {
          "type" : "string",
          "enum" : [ "1", "Good", "With Spaces" ]
        }
      }
    }
  }
}

JAVASCRIPT CLIENT

exports.SomePropertyEnum = { 
    /**
     * value: 1
     * @const
     */
    _1: "1",

    /**
     * value: Good
     * @const
     */
    GOOD: "Good",

    /**
     * value: With Spaces
     * @const
     */
    WITH_SPACES: "With Spaces"
  };

JAVASCRIPT CLOSURE ANGULAR CLIENT

API.Client.Body.SomePropertyEnum = { 
  1: '1',
  Good: 'Good',
  With Spaces: 'With Spaces',
}

TYPESCRIPT ANGULAR CLIENT

export enum SomePropertyEnum { 
  1 = <any> '1',
  Good = <any> 'Good',
  With Spaces = <any> 'With Spaces'
}
@dusty
Copy link
Author

dusty commented Apr 29, 2016

Tried a couple more unusual values (# and * as strings, that I actually need to use). These failed on all of them.

{
  "swagger" : "2.0",
  "info" : {
    "description" : "Enum",
    "version" : "1.0.0",
    "title" : "Enum"
  },
  "host" : "localhost",
  "basePath" : "/api",
  "schemes" : [ "http" ],
  "consumes" : [ "application/json" ],
  "produces" : [ "application/json" ],
  "paths" : {
    "/example" : {
      "post" : {
        "summary" : "Example",
        "parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : true,
          "schema" : {
            "$ref" : "#/definitions/body"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "success"
          }
        }
      }
    }
  },
  "definitions" : {
    "body" : {
      "type" : "object",
      "properties" : {
        "someProperty" : {
          "type" : "string",
          "enum" : [ "1", "Good", "With Spaces", "*", "#" ]
        }
      }
    }
  }
}

javascript client (made both the keys _)

exports.SomePropertyEnum = { 
    /**
     * value: 1
     * @const
     */
    _1: "1",

    /**
     * value: Good
     * @const
     */
    GOOD: "Good",

    /**
     * value: With Spaces
     * @const
     */
    WITH_SPACES: "With Spaces",

    /**
     * value: *
     * @const
     */
    _: "*",

    /**
     * value: #
     * @const
     */
    _: "#"
  };

closure angular

API.Client.Body.SomePropertyEnum = { 
  1: '1',
  Good: 'Good',
  With Spaces: 'With Spaces',
  *: '*',
  #: '#',
}
export enum SomePropertyEnum { 
  1 = <any> '1',
  Good = <any> 'Good',
  With Spaces = <any> 'With Spaces',
   * = <any> '*',
   # = <any> '#'
}

@wing328
Copy link
Contributor

wing328 commented Apr 29, 2016

@dusty thanks for reporting the issue. We plan to introduce better support of enum via #2508

@aws-na-ss-usplu
Copy link

Novice: Our very small two cents ;-)

We currently develop solutions in two worlds… LoopBack/Node.js & WebApi/Asp.net

We would love to have a solution that complements each others interpretation of the concepts around

  • Generic Extensions for Enum
  • Implement of Enum
  • Solution path to transition from Swagger Extension to first class member of Swagger 2.x schema

We currently use swagger to generate both client/server code for LoopBack & .NET, and client code in Java and PHP. When it comes to Enum and Additional Properties we have to deal with exceptions because like HTML specs each community is interpreting the specifications a little differently rather than each community discussing the discrepancy to improve the understanding and interpreting of the Swagger Specs.

Here is Swagger API discussion around ENUMs for C-Sharp

Here is StrongLooop / Loopback discussion around Enums

Here is how AutoRest community is currently dealing with Enums with AutoRest

We still need to investigate where the StrongLoops/ IBM thoughts on implementing Enum, and we plan to review shortly.

We just propose that all participants in providing a Swagger Code Generators to deal with Enum to converge on a solution rather than have a lot of silo implementations of swagger generic extensions for Enum.

We have investigated the following code generators to date. Non have a consist implementation to deal with Additional Properties or Enum

Appreciate feedback, concerns and issues with our thoughts…

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