cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Expected enum instead of string in the output result #252

Closed mmza94 closed 1 year ago

mmza94 commented 1 year ago

It would be great to have the same output as openapi-generator produces in case of enum properties parsing.

Yaml snippet:

system-file:
  properties:
    autoStart:
      enum:
      - true
      - false
      - always
      type: string
    ...

Generated by openapi-generator:

export interface SystemFile { 
  autoStart?: SystemFileAutoStartEnum;
  ...
}
export enum SystemFileAutoStartEnum {
    True = 'true',
    False = 'false',
    Always = 'always'
};

Generated by ng-openapi-gen:

export interface SystemFile {
  autoStart?: 'true' | 'false' | 'always';
  ...
}

"ng-openapi-gen": "0.23.0"

luisfpg commented 1 year ago

I'm sorry, but that's a design decision in ng-openapi-gen.

gwesterman commented 1 year ago

Could you go into detail as to why this is not something we should choose for ourselves?

Without an enum I'd be using magic strings, which I would rather avoid.

For example I want to limit the possible input values in a component to the values provided by the JSON schema. I do not want to copy the possible values from the generated model and would rather point to the generated enum.

MassimilianoOreto commented 1 year ago

I have the same problem. Generating the enum like a string, then when i pass to my backend (nestjs) doesn't accept this string value

bkhayargoli commented 9 months ago

Do we have any update to this? would love to have this. @luisfpg