Closed naipaka closed 6 months ago
I wanted to add to this issue since it deals with an area I am having problems with as well.
My swagger.json is generated by the web framework I'm using and for all my requests the request parameters are not inlined with the endpoint but instead put under a model and referenced. Eg:
"AgathaApiEndpointsAdministrationDoctorsPatchDoctorMediaContentRequest": {
"type": "object",
"additionalProperties": false,
"properties": {
"description": {
"type": "array",
"nullable": true,
"items": {
"$ref": "#/components/schemas/AgathaApiStrongTypesTranslation"
}
},
"url": {
"type": "string",
"nullable": true
},
"image": {
"type": "string",
"format": "binary",
"nullable": true
}
}
},
Because of this, swagger_parser
tries to create a class for it with freezed
that looks like this
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
import 'dart:io';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'agatha_api_strong_types_translation.dart';
part 'administration_doctors_patch_doctor_media_content_request.freezed.dart';
part 'administration_doctors_patch_doctor_media_content_request.g.dart';
@Freezed()
class AdministrationDoctorsPatchDoctorMediaContentRequest with _$AdministrationDoctorsPatchDoctorMediaContentRequest {
const factory AdministrationDoctorsPatchDoctorMediaContentRequest({
List<AgathaApiStrongTypesTranslation>? description,
String? url,
File? image,
}) = _AdministrationDoctorsPatchDoctorMediaContentRequest;
factory AdministrationDoctorsPatchDoctorMediaContentRequest.fromJson(Map<String, Object?> json) => _$AdministrationDoctorsPatchDoctorMediaContentRequestFromJson(json);
}
Because freezed
can't deal with File
this results in build_runner errors.
If there is some workaround here please let me know.
@SasLuca Hi, can you provide the full expected result of the generated code? As far as I understand, this class is not expected to be generated at all, but all the properties from it should be present in the query itself, like in the @naipaka example?
I will look into this problem shortly.
Hi @StarProxima, not sure I understand what you are asking but I made a reproduction of my issue.
The jist of it is that json_serializable cant handle File
instances in data structures, which means we cant have code generation for endpoints with file form data (eg: an endpoint for uploading a file picture).
It would be nice if this can be fixed (or maybe it is and just needs documentation?) so that we can also generate endpoints with File
s sent as form data.
Reproduction: https://github.com/SasLuca/SwaggerParserIssueRepro/tree/master
If you have more questions let me know.
@naipaka Can you see if the generation on your schema works correctly for the swagger_parser version from the git?
@SasLuca Your problem is now related to https://github.com/Carapacik/swagger_parser/issues/154
Hi @StarProxima, i am on holiday til Friday, but i will ask someone at my office to try if they have time until then and report back here. If not i will try it on friday and let you know.
Ah, seems like you wanted someone else to test not me. If you need me to test anything let me know with a ping.
@StarProxima I have confirmed that all three issues initially mentioned in the issue have been resolved. Your support in this matter has been incredibly helpful. Thank you very much.
Hello.
First of all, I want to express my gratitude for your excellent work on this package. It has been a valuable tool in my projects.
However, I have encountered a few issues with the automatic code generation for multipart requests in Dart. These issues arise specifically from OpenAPI definitions, similar to the ones provided in the Swagger documentation under Multipart Requests.
Here is an example of the OpenAPI 3.0.3 definition I used, written in YAML format:
From this definition, the following Dart code is generated:
However, there are several issues with the generated code:
Ignoring
required
fields in schema: Therequired
fieldsid
,address
, andprofileImage
in the schema are not reflected in the generatedpostSample
method. The parameters in this method lack therequired
keyword, which is necessary for ensuring data integrity. This makes the code unusable as is. Furthermore, even explicitly specifyingnullable: false
for each property resulted in the same issue.Missing
dart:convert
import: In thesample_client.g.dart
file generated by theRetrofitGenerator
,jsonEncode
is implemented for theaddress
, but since there is no import fordart:convert
, it results in a compilation error.Omission of descriptions in documentation comments: Although the schema's
description
defines explanations forid
,address
, andprofileImage
, the doc comments for thepostSample
method do not include descriptions for these arguments.The ideal solution would be for the code generation to respect these aspects of the OpenAPI definition, producing something along these lines:
I hope these issues can be addressed in a future update to improve the tool's functionality and usability. Thank you for your efforts in maintaining this valuable project.