Skip to content

[Typescript][Angular] bug: Enum generates empty name. #6822

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

Closed
HermenOtter opened this issue Oct 26, 2017 · 16 comments · Fixed by #6833
Closed

[Typescript][Angular] bug: Enum generates empty name. #6822

HermenOtter opened this issue Oct 26, 2017 · 16 comments · Fixed by #6833

Comments

@HermenOtter
Copy link

HermenOtter commented Oct 26, 2017

Description

I think something went wrong when the enum generation recently changed. It currently generates empty names?

Swagger-codegen version

The current(time of writing) master (commit f78d958 ))

Swagger declaration file content or url

The defined enum:

indicatie_actief:
    type: "string"
    maxLength: 1
    description: "Indication whether the object is active or not"
    enum: 
    - J
    - N

Referenced in:

responses:
        200:
          description: "Status 200"
          schema:
            type: "object"
            properties:
              items:
                type: "array"
                items:
                  type: "object"
                  allOf:
                  - type: "object"
                    properties:
                      ...more props...
                      indicatie_actief:
                        $ref: "#/definitions/indicatie_actief"

Results in:


export const  = {
    J: 'J' as ,
    N: 'N' as 
}

Bug: The names are missing
Any ideas how to fix?

Command line used for generation

generate -i -l typescript-angular

@macjohnny
Copy link
Contributor

@bedag-moo could you have a look at this?

@bedag-moo
Copy link
Contributor

That is not my code; emitting this const was added by @kenisteward in f7471ad

@kenisteward
Copy link
Contributor

I'll take a look at this. Could you give me the complete example of your yaml or is this it?

@kenisteward
Copy link
Contributor

Also could you give me the full model generation so I can make sure I know what is wrong

@kenisteward
Copy link
Contributor

@HermenOtter I have a feeling it is because I used enum name somewhere I should have used class name but when I get your fully generated model example and a yaml to go off I can check for sure

@kenisteward
Copy link
Contributor

@HermenOtter Please check #6833 changes on my forked repo to see if it fixes your issue

@HermenOtter
Copy link
Author

HermenOtter commented Oct 30, 2017

Thank you all for the fast responses. @kenisteward I tried your pull request with mvn clean package, but it didn't seem to work when I generated code from the new build. While building it gave a ton of warnings, but not sure if that is relevant.

edit:
What more do you need?

 responses:
        200:
          description: "Status 200"
          schema:
            type: "object"
            properties:
              items:
                type: "array"
                items:
                  type: "object"
                  allOf:
                  - type: "object"
                    properties:
                      code_bik:
                        type: "string"
                      bik:
                        type: "string"
                      indicatie_actief:
                        $ref: "#/definitions/indicatie_actief"

indicatieActief.ts

export type  = 'J' | 'N';

export const  = {
    J: 'J' as ,
    N: 'N' as 
}
``

@kenisteward
Copy link
Contributor

kenisteward commented Oct 30, 2017 via email

@kenisteward
Copy link
Contributor

kenisteward commented Oct 30, 2017 via email

@HermenOtter
Copy link
Author

HermenOtter commented Oct 30, 2017

These are the definitions:

definitions:
  indicatie_actief:
    type: "string"
    description: "Indication whether the object is active or not"
    enum: 
      - "J"
      - "N"
  indicatie_uniek:
    type: "string"
    description: "Indication whether the object is unique or not"
    enum: 
      - "J"
      - "N"

@kenisteward I have been researching the issue and it seems you can't declare an enum in the root of a definition or something with the allOf like you said.

I will try a code generation without using allOf and then report back to you.

Do you have any idea on how to rewrite it having the same result, but without using an allOf?

@HermenOtter
Copy link
Author

HermenOtter commented Oct 30, 2017

 Soorten_relatie:        
    type: "object"
    required:
      - "code_soort_relatie"
      - "soort_relatie"
      - "indicatie_uniek"
      - "indicatie_actief"
    properties:
      code_soort_relatie:
        type: "string"
        maxLength: 3
      soort_relatie: 
        type: "string"
        maxLength: 40
      indicatie_uniek:
        $ref: "#/definitions/indicatie_uniek"
      indicatie_actief:
        $ref: "#/definitions/indicatie_actief"

Here is it used without an allOf.

import { IndicatieActief } from './indicatieActief';
import { IndicatieUniek } from './indicatieUniek';


export interface SoortenRelatie {
    codeSoortRelatie: string;
    soortRelatie: string;
    indicatieUniek: IndicatieUniek;
    indicatieActief: IndicatieActief;
}

It references IndicatieActief properly, but it does not generate the IndicatieActief nor IndicatieUniek.
However when I use an enum as property on a definition is does work.

@kenisteward
Copy link
Contributor

@HermenOtter Good news! I think I may have found the issue. The mustache template variable for class name should have been {{classname}} but i made it {{className}} in mine. my apologies. check my pr for the latest. Sorry for the issue!

I made sure to use your exmaples using allof as well.

@HermenOtter
Copy link
Author

HermenOtter commented Oct 31, 2017

@kenisteward I tried your new pr, but it doesn't seem to work. Are there any additional steps I have to perform to make it work? Can you show the allOf example that works for you?

Thank you for your effort I appreciate it. ps.

@kenisteward
Copy link
Contributor

@HermenOtter
This is what I used and it generates fine.

the definitions section is copied right from what you gave.

swagger: "2.0"
info:
  description: "This is a sample server Petstore server.  You can find out more about     Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).      For this sample, you can use the api key `special-key` to test the authorization     filters."
  version: "1.0.0"
  title: "Swagger Petstore"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "[email protected]"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
- name: "pet"
  description: "Everything about your Pets"
  externalDocs:
    description: "Find out more"
    url: "http://swagger.io"
- name: "store"
  description: "Access to Petstore orders"
- name: "user"
  description: "Operations about user"
  externalDocs:
    description: "Find out more about our store"
    url: "http://swagger.io"
schemes:
- "http"
paths:
  /pets:
    get:
       responses:
              200:
                description: "Status 200"
                schema:
                  type: "object"
                  properties:
                    items:
                      type: "array"
                      items:
                        type: "object"
                        allOf:
                        - type: "object"
                          properties:
                            code_bik:
                              type: "string"
                            bik:
                              type: "string"
                            indicatie_actief:
                              $ref: "#/definitions/indicatie_actief"
definitions:
  indicatie_actief:
    type: "string"
    description: "Indication whether the object is active or not"
    enum: 
      - "J"
      - "N"
  indicatie_uniek:
    type: "string"
    description: "Indication whether the object is unique or not"
    enum: 
      - "J"
      - "N"

@HermenOtter
Copy link
Author

@kenisteward
Seems there was some caching issue with the swagger specification being retrieved from swaggerhub. It is working now!

Thank you very much for your effort.

@kenisteward
Copy link
Contributor

kenisteward commented Nov 2, 2017 via email

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