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

Issues found after trying to generate big swagger file #58

Closed
szotp opened this issue Sep 24, 2020 · 8 comments · Fixed by #60
Closed

Issues found after trying to generate big swagger file #58

szotp opened this issue Sep 24, 2020 · 8 comments · Fixed by #60
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@szotp
Copy link

szotp commented Sep 24, 2020

Hi, I like the idea of dart only code generator, but unfortunately, I found a lot of issues while trying to generate code for my API:

  1. additionalProperties key from schema is not handled, I'm getting final null foo; variables. At least it should use final null foo;.
  2. Responses that return bool don't work, it will generate Future<Response<Bool>>. It seems that only num primitive is handled properly.
  3. Models with strange names are not supported, I had few named Foo-Bar. Model name was ok, But parameter name in request method was not.
  4. Keywords are not handled in all places, I had enum cases named default or new.
  5. The code quality is not so good, I'm seeing a lot of duplicate code that creates the mismatch.
  6. Generated enum name may conflict with generated class name.
  7. I don't see any benefit of chopper here, you could generate very similiar code to what chopper does and avoid unnecessary dependency.
@fryette
Copy link
Contributor

fryette commented Sep 24, 2020

Thanks for your feedback.

Could you please share swagger.json?
We will try to handle all of the points.

We tested it on more than 100 swagger files and everything was OK.

Also can send it to ysampir@gmail.com if you don't want to share it with others.

about:

  1. additionalProperties key from schema is not handled, I'm getting final null foo; variables. At least it should use final null foo;. It would be nice to have a swagger file to fix it.
  2. Responses that return bool don't work, it will generate Future<Response<Bool>>. It seems that only num primitive is handled properly. Nice catch, really, will be fixed in the next version.
  3. Models with strange names are not supported, I had few named Foo-Bar. Model name was ok, But parameter name in request method was not. Could you please provide concrete examples and responses?(what you expect here)
  4. Keywords are not handled in all places, I had enum cases named default or new. Will be fixed soon
  5. The code quality is not so good, I'm seeing a lot of duplicate code that creates the mismatch. Pr's welcome, but I will be very appreciated if you can review or provide more concrete examples. Let's make it better together.
  6. Generated enum name may conflict with generated class name. As I know it's not possible, but will recheck
  7. I don't see any benefit of chopper here, you could generate very similiar code to what chopper does and avoid unnecessary dependency. You are right, but we need to invent our own chopper. In the first versions, we would like to avoid such things. In the future, we can generate similar code as chopper provide, but now - as is. Pr's are welcome also.

And again, big thanks for your review and testing!

@Vovanella95 could you please handle points above?

@fryette fryette added bug Something isn't working good first issue Good for newcomers labels Sep 24, 2020
@Vovanella95
Copy link
Collaborator

Hi @szotp,

About point 2.

To have Future at response, you need to have "boolean" return type in response. I guess you have "bool" now. But according spec there is no "bool" base type https://swagger.io/specification/. There is only "boolean".

Please correct me if I wrong.

@szotp
Copy link
Author

szotp commented Sep 25, 2020

Hi, thanks for feedback, I will prepare minimal swagger spec to illustrate the problems.

@fryette
Copy link
Contributor

fryette commented Sep 26, 2020

@szotp any progress?

@szotp
Copy link
Author

szotp commented Sep 28, 2020

Sorry I had some work to do during the weekend, I'll do it this week.

@fryette fryette reopened this Sep 28, 2020
@Vovanella95
Copy link
Collaborator

@szotp Hey,

Points 3, 4 and 6 are already fixed!

@szotp
Copy link
Author

szotp commented Sep 30, 2020

Here is the json, some issues still remain. Good luck!

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Swagger Petstore",
        "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
        "termsOfService": "http://swagger.io/terms/",
        "contact": {
            "name": "Swagger API Team"
        },
        "license": {
            "name": "MIT"
        }
    },
    "host": "petstore.swagger.io",
    "basePath": "/api",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/pets": {
            "get": {
                "description": "Returns all pets from the system that the user has access to",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "foobar",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/foo-Bar"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "responses": {
                            "200": {
                                "description": "No response was specified",
                                "schema": {
                                    "type": "boolean"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "Response": {
            "type": "object",
            "required": [],
            "properties": {
                "preferences": {
                    "additionalProperties": {
                        "type": "string"
                    }
                },
                "foo": {
                    "type": "string",
                    "enum": [
                        "1ENUM",
                        "2$@!enum",
                        "new",
                        "default"
                    ]
                }
            }
        },
        "ResponseFoo": {
            "type": "object"
        },
        "foo-Bar": {
            "type": "object"
        }
    }
}

@Vovanella95
Copy link
Collaborator

Hi @szotp , We fixed all issues in 1.2.0 version. Refactoring issue is moved to separate one. In future we're going to implement native requests (not using chopper), but not right now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants