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] OpenAPI 3.1 nullable types not supported #741

Open
juliansteenbakker opened this issue Mar 23, 2024 · 2 comments
Open

[BUG] OpenAPI 3.1 nullable types not supported #741

juliansteenbakker opened this issue Mar 23, 2024 · 2 comments
Assignees
Labels
bug Something isn't working Triage needed

Comments

@juliansteenbakker
Copy link
Contributor

I'm having some issues using the generated json to generate API endpoint for Flutter using the this package. It seems to fail on the notation for nullable types.

It seems as if the following notation for a nullable value (expires_at) which is valid in the openAPI 3.1 editor, is not being generated correctly.

      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                role:
                  type: string
                expires_at:
                  type:
                    - string
                    - 'null'

when i change the type to type: string, everything works as expected
error:

type 'List<dynamic>' is not a subtype of type 'String?' in type cast
package:swagger_dart_code_generator/src/swagger_models/responses/swagger_schema.g.dart 11:26  _$SwaggerSchemaFromJson
package:swagger_dart_code_generator/src/swagger_models/responses/swagger_schema.dart 118:7    new SwaggerSchema.fromJson
package:swagger_dart_code_generator/src/swagger_models/responses/swagger_schema.g.dart 16:43  _$SwaggerSchemaFromJson.<fn>

Swagger specification link
3.1.0

Library version used:
2.15.2

@CarlMichaelFabe
Copy link

I tried the fixes and it mostly works, except on nullable lists.

@numbermess
Copy link

I updated my project's pubspec.yaml entry for swagger_dart_code_generator to

#  swagger_dart_code_generator: ^2.15.2
  swagger_dart_code_generator:
    git:
      url: https://github.com/juliansteenbakker/swagger-dart-code-generator.git
      ref: openapi-3.1-fix

And I was able to build the client library without error for resources that had a list of types that included null, like:

...
          "account": {
            "type": [
              "string",
              "null"
            ],
            "format": "iri-reference",
            "example": "https://example.com/"
          },
...

This got rid of the "type 'List' is not a subtype of type 'String?' in type cast" error for me. Thanks!

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

5 participants