Closed JohnGalt1717 closed 6 months ago
I also experience this issue.
Here is a minimal reproducible sample:
{
"openapi": "3.0.3",
"info": {
"title": "Parser Test",
"description": "Parser Test",
"version": "1.0.0"
},
"externalDocs": {
"url": "/"
},
"servers": [],
"tags": [],
"paths": {},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"a": {
"type": "string",
"nullable": false
}
}
}
},
"examples": {}
}
}
This snippet generates the following dart code:
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
import 'package:json_annotation/json_annotation.dart';
part 'user.g.dart';
@JsonSerializable()
class User {
const User({
this.a,
});
factory User.fromJson(Map<String, Object?> json) => _$UserFromJson(json);
final String? a;
Map<String, Object?> toJson() => _$UserToJson(this);
}
But for my understanding, this should actually mark a
as String
(and therefore required
) instead of String?
.
Can I somehow help solve the problem? Or someone is already doing this. Just a very critical thing...
I already have the code and offered to do a pull request. I didn’t get a response.
Yes, I am work on it
@JohnGalt1717 @Darkildo Check branch 1.15
swagger_parser:
git:
url: https://github.com/Carapacik/swagger_parser
ref: 1.15
path: swagger_parser
Turns out, I was just writing my swagger docs incorrectly and required_by_default: false
is actually just vastly more desirable.
I apologize for that.
A swagger doc were all required parameters are annotated with required: true
is much easier to generate that one which doesnt do that but assumes all parameters to be required.
Strangely enough, required_by_default: false
seems to not actually turn off the required
part for parameters?
Consider the following definition:
It clearly defines what fields are required and nullable, but the generation doesn't use these, so everything is nullable when it really isn't.