You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Define swagger_parser: 1.18.1 or 1.18.2 in pubspec.yaml.
Define the yaml file as described in Your OpenApi snippet.
Run dart run swagger_parser.
Run flutter pub run build_runner build -d.
Expected results
I would like the code to be generated as follows.
import'package:freezed_annotation/freezed_annotation.dart';
import'gender.dart';
part'user_request.freezed.dart';
part'user_request.g.dart';
/// User request.@Freezed()
classUserRequestwith_$UserRequest {
constfactoryUserRequest({
/// User name.requiredString name,
/// User gender.Gender? gender,
}) =_UserRequest;
factoryUserRequest.fromJson(Map<String, Object?> json) =>_$UserRequestFromJson(json);
}
Actual results
Specifically:
When a property is referenced using $ref, it becomes required even if it is not listed in the required section of the schema.
If nullable: true is specified in the referenced schema (e.g., Gender), it should be reflected in the generated Dart code. However, the required annotation is still added, making the property non-nullable.
Additionally, when using $ref, the description specified in the referenced schema is not carried over into the generated doc comments.
It would be helpful if the code generation could respect the nullable property and ensure that the description from the $ref schema is included in the generated code.
Your OpenApi snippet
openapi: 3.0.3
Example YAML:
paths:
/sample:
post:
tags:
- Usersummary: Sample APIdescription: Sample API.operationId: PostSamplerequestBody:
required: truecontent:
application/json:
schema:
$ref: '#/components/schemas/UserRequest'responses:
'201':
description: Created.default:
$ref: '#/components/responses/default'components:
schemas:
UserRequest:
description: User request.type: objectproperties:
name:
type: stringdescription: User name.gender:
$ref: '#/components/schemas/Gender'required:
# gender is not required, but required is added when generating code.
- nameGender:
type: string# here, even if you specify nullable, required is added when generating code.nullable: trueenum:
- MALE
- FEMALE
- OTHER
- UNKNOWN# $ref is ignored description in code generation.description: User gender.
Code sample
The code sample is all as described above.
Logs
Logs
┃ ____ _ _ _ ____ ____ ____ ____ ____ ___ ____ ____ ____ ____ ____ ┃ [__ | | | |__| | __ | __ |___ |__/ |__] |__| |__/ [__ |___ |__/ ┃ ___] |_|_| | | |__] |__] |___ | \ ___ | | | | \ ___] |___ | \┃Generate...
> api_client v1.0.0: 7 rest clients, 38 requests, 43 data classes. 52 files with 2 068 lines of code. Success (0.03 seconds)The generation was completed successfully. You can run the generation using build_runner.cd medeta_app_packages/api_client && flutter pub run build_runner build -dDeprecated. Use `dart run` instead.Building package executable... Built build_runner:build_runner.[INFO] Generating build script completed, took 150ms[INFO] Reading cached asset graph completed, took 59ms[INFO] Checking for updates since last build completed, took 416ms[INFO] Running build completed, took 1.4s[INFO] Caching finalized dependency graph completed, took 32ms[INFO] Succeeded after 1.5s with 3 outputs (6 actions)
Steps to reproduce
swagger_parser: 1.18.1 or 1.18.2
inpubspec.yaml
.Your OpenApi snippet
.dart run swagger_parser
.flutter pub run build_runner build -d
.Expected results
I would like the code to be generated as follows.
Actual results
Specifically:
$ref
, it becomesrequired
even if it is not listed in therequired
section of the schema.nullable: true
is specified in the referenced schema (e.g.,Gender
), it should be reflected in the generated Dart code. However, therequired
annotation is still added, making the property non-nullable.$ref
, thedescription
specified in the referenced schema is not carried over into the generated doc comments.Generated Dart Code:
It would be helpful if the code generation could respect the
nullable
property and ensure that thedescription
from the$ref
schema is included in the generated code.Your OpenApi snippet
openapi: 3.0.3
Example YAML:
Code sample
The code sample is all as described above.
Logs
Logs
Dart version and used packages versions
Dart version
Packages version
1.18.1 or 1.18.2
The text was updated successfully, but these errors were encountered: