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

[BUG][DART] Bad support for extension x-enum-varnames #5794

Closed
selankon opened this issue Apr 1, 2020 · 4 comments
Closed

[BUG][DART] Bad support for extension x-enum-varnames #5794

selankon opened this issue Apr 1, 2020 · 4 comments

Comments

@selankon
Copy link
Contributor

selankon commented Apr 1, 2020

Description

Enums that has the x-enum-varnames extension defined are not processed correctly and the enum var names seems to be generated automatically instead of get the names defined.

openapi-generator version
➜ openapi-generator version
4.2.3
OpenAPI declaration file content or url
openapi: 3.0.0
info:
    title: RetroShare OpenApi wrapper
    version: 0.0.1
    description: RetroShare OpenApi wrapper generated using Doxygen documentation
    license:
        name: AGPLv3
servers:
    - url: http://127.0.0.1:9092/
    
paths:
    /jsonApiServer/version:
        post:
            summary: blahblah             
            responses:
                '200':
                    description: >
                            return: 
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/FileChunksInfo'

components:      
    schemas:
        FileChunksInfo:
            type: object
            properties:
                chunks:
                    type: array
                    items:
                        $ref: '#/components/schemas/ChunkState'
        ChunkState:
            type: integer
            enum:
                
                    - 0
                    - 1
                    - 2
                    - 3
            x-enum-varnames:
                
                    - CHUNK_OUTSTANDING
                    - CHUNK_ACTIVE
                    - CHUNK_DONE
                    - CHUNK_CHECKING
Command line used for generation
➜ openapi-generator generate -i definition.yml -g dart -o openapi-dart-retroshare-api-wrapper
Steps to reproduce

Just copy the .yml definition and run the command.

After the code is generated be sure that all the dependencies are installed. I us VSCodium with Dart extension for that.

If you see a build error see: #4887.

The generated name for the enum values are like:

  static const ChunkState number0_ = const ChunkState._internal(0);
  static const ChunkState number1_ = const ChunkState._internal(1);
  static const ChunkState number2_ = const ChunkState._internal(2);
  static const ChunkState number3_ = const ChunkState._internal(3);
Suggest a fix

I check the template and all seems correct, the problem should be on the Java generator file on modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java but I'm not sure of how this work...

@auto-labeler
Copy link

auto-labeler bot commented Apr 1, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@sbu-WBT
Copy link
Contributor

sbu-WBT commented Aug 26, 2020

I had a look a the generator and found out by trial and error that removing the following method fixes the problem.

public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
List<Object> models = (List<Object>) objs.get("models");
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
boolean succes = buildEnumFromVendorExtension(cm) ||
buildEnumFromValues(cm);
for (CodegenProperty var : cm.vars) {
updateCodegenPropertyEnum(var);
}
}
return objs;
}

But there must be reason, why the method was overridden from the default generator. Can you remember it @pylaligand and @wing328? (Thanks to git blame^^) I couldn't find any during my short test. Is maybe "x-enum-values" missing then? If that's the problem, I would vote for #1486 which seem to solve the problem for all generators and we can remove this overriding (and some methods which will then be unused). I would even say, we should remove these methods regardless the PR to be consistent with the other generators which seem to support only "x-enum-varnames" and not "x-enum-values".

@pylaligand
Copy link
Contributor

AFAIR yes that was to support x-enum-values the way Bungie used it in their API.

@kuhnroyal
Copy link
Contributor

Can you try this again on master?

@wing328 wing328 closed this as completed Jan 22, 2021
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

5 participants