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] All generated methods return nullable types #670

Closed
denisano opened this issue Oct 30, 2023 · 7 comments
Closed

[BUG] All generated methods return nullable types #670

denisano opened this issue Oct 30, 2023 · 7 comments
Assignees
Labels
bug Something isn't working Triage needed

Comments

@denisano
Copy link

denisano commented Oct 30, 2023

It seems in version 2.11.13 signature of generated methods has been changed.

It was earlier (before version 2.11.13) - see: TeacherDto:

  ///@param id
  Future<chopper.Response<TeacherDto>> teachersGetTeacherById(
      {required int? id}) {
    generatedMapping.putIfAbsent(TeacherDto, () => TeacherDto.fromJsonFactory);

    return _teachersGetTeacherById(id: id);
  }

Now all return types of generated methods are nullable - see: TeacherDto?:

 ///Get Teacher data by  ID
  ///@param id
  Future<chopper.Response<TeacherDto?>> teachersGetTeacherById(
      {required int? id}) {
    generatedMapping.putIfAbsent(TeacherDto, () => TeacherDto.fromJsonFactory);

    return _teachersGetTeacherById(id: id);
  }

Version 2.11.13

@denisano denisano added bug Something isn't working Triage needed labels Oct 30, 2023
@Vovanella95
Copy link
Collaborator

Hi @DenisAnkh , could you please share swagger file (or part of it)?

@denisano
Copy link
Author

denisano commented Oct 30, 2023

Hi @Vovanella95, here is the part of swagger file:

        "/teachers/{id}": {
            "get": {
                "tags": [
                    "Teachers"
                ],
                "summary": "Get Teacher data by  ID",
                "operationId": "teachersGetTeacherById",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "successful operation",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/TeacherDto"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Invalid id supplied"
                    },
                    "404": {
                        "description": "Teacher is not found"
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        },

Currently we have rolled back to version 2.11.11 of swagger_dart_code_generator. The version generates correct code. Version 2.11.13 (as well as 2.11.12) generates different code with the same swagger file.

Our current (working correct) pubspec.yaml:

dev_dependencies:
  build_runner: ^2.4.6
  chopper: ^7.0.9
  chopper_generator: ^7.0.6
  lints: ^3.0.0
  swagger_dart_code_generator: 2.11.11

@Vovanella95
Copy link
Collaborator

Thanks @DenisAnkh ! Will handle it this week!

@Vovanella95
Copy link
Collaborator

Fixed in 2.12.1

@frederikstonge
Copy link

frederikstonge commented Nov 10, 2023

Fixed in 2.12.1

There are still models generating non-nullable properties when they are.

So my whole models has "nullable: true" on properties, except the one that are just "$ref: XX". However, these properties are nullable in my model. Is the issue in the package i'm using to generate my swagger.json?

"Cart": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "nullable": true
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "$ref": "#/components/schemas/StatusEnum"
          },
          "mode": {
            "$ref": "#/components/schemas/ModeEnum"
          },
          "accountId": {
            "type": "string",
            "nullable": true
          },
          "orgId": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "lastModified": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "richSynchronizedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "billingAddress": {
            "$ref": "#/components/schemas/CartAddress"
          },
          "logisticDetails": {
            "$ref": "#/components/schemas/LogisticDetails"
          },
          "marketplaceLogisticDetailsList": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LogisticDetails"
            },
            "nullable": true
          },
          "opcoCartId": {
            "type": "string",
            "nullable": true
          },
          "orderAdditionalInformation": {
            "$ref": "#/components/schemas/OrderAdditionalInformation"
          },
          "includeAllSpas": {
            "type": "boolean",
            "nullable": true
          },
          "specialPriceAgreements": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SpecialPriceAgreement"
            },
            "nullable": true
          },
          "project": {
            "$ref": "#/components/schemas/Project"
          },
          "quote": {
            "$ref": "#/components/schemas/Quote"
          },
          "approvalInfo": {
            "$ref": "#/components/schemas/ApprovalInfo"
          },
          "refusalInfo": {
            "$ref": "#/components/schemas/RefusalInfo"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Item"
            },
            "nullable": true
          },
          "itemsNotAdded": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ItemNotAdded"
            },
            "nullable": true
          },
          "coupons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Coupon"
            },
            "nullable": true
          },
          "contributors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Contributor"
            },
            "nullable": true
          },
          "synchronizationErrors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SynchronizationError"
            },
            "nullable": true
          },
          "totalPrice": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalPriceExcludingPromotions": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalPromotions": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalSurchargeTaxes": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalPriceIncludingSurcharges": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalPriceIncludingSurchargesAndShipping": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalShippingCosts": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalPriceIncludingTaxes": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalPriceAllIncluded": {
            "$ref": "#/components/schemas/PriceField"
          },
          "totalVatByPercentage": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tax"
            },
            "nullable": true
          },
          "discountDetails": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DiscountDetail"
            },
            "nullable": true
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            },
            "nullable": true
          },
          "persistentMessages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PersistentMessage"
            },
            "nullable": true
          },
          "products": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Product"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },

@Vovanella95
Copy link
Collaborator

Hi @frederikstonge , let me release new version first :) Please check behavior in 2.12.2

@Vovanella95
Copy link
Collaborator

@frederikstonge it's done

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

No branches or pull requests

4 participants