Skip to content

Generator fails on YAML with no defined schemas #8

@ynnob

Description

@ynnob

Hey this is just a little bug i found that is not really important but it could confuse some people if they just test a generation with an basic yaml file.

If there is no schema defined in the components section, the generator fails beacuse your generation script is missing some null checks at openapi_code_builder line 150:

    for (final schemaEntry in api.components!.schemas!.entries) {
      _schemaReference(schemaEntry.key, schemaEntry.value!);
    }
    if (api.components!.securitySchemes != null && !ignoreSecuritySchemes) {
      for (final securityScheme in api.components!.securitySchemes!.entries) {
        _securitySchemeReference(securityScheme.key, securityScheme.value!);
      }
    }

I think components and api.components!.schemas should be null checked there. There is a chance that line 153 will also fail if yo security scheme is defined in the yaml but i cant confitm atm.

Following this the generator should not generate the *.g.dart file and has to remove the part '*.g.dart'; link in the api file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions