Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
88 stars 33 forks source link

Bug: The rules required: true and nullable: false do not apply #170

Closed koutja closed 4 months ago

koutja commented 4 months ago
swagger_parser:
  language: dart
  squash_clients: true
  json_serializer: freezed
  put_in_folder: true
  required_by_default: true
  root_client: false
  client_postfix: ApiClient
  # You can pass a list of schemes.
  schemas:
    - schema_path: lib/src/features/chats/schemas/openapi/chats.yaml
      output_directory: lib/src/features/chats/api
      required_by_default: true
      replacement_rules: []
openapi: 3.1.0
info:
  title: Messenger API
  version: 1.0.0
paths:
  /chats:
    get:
      responses:
        '200':
          description: List of chats
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Chat'
components:
  schemas:
    Chat:
      type: object
      properties:
        id:
          type: string
          required: true
          nullable: false

In result after build_runner, I have String? id:


import 'package:freezed_annotation/freezed_annotation.dart';

part 'chat.freezed.dart';
part 'chat.g.dart';

@Freezed()
class Chat with _$Chat {
  const factory Chat({
    String? id,
  }) = _Chat;

  factory Chat.fromJson(Map<String, Object?> json) => _$ChatFromJson(json);
}

I need required String id :


import 'package:freezed_annotation/freezed_annotation.dart';

part 'chat.freezed.dart';
part 'chat.g.dart';

@Freezed()
class Chat with _$Chat {
  const factory Chat({
    required String id,
  }) = _Chat;

  factory Chat.fromJson(Map<String, Object?> json) => _$ChatFromJson(json);
}
koutja commented 4 months ago

I solved. I should use

ChatMessage:
  type: object
  required:
     - id