[dart-dio] Correctly serialize path parameters (#14666)

This commit is contained in:
Szabolcs Székelyi 2023-06-15 01:45:19 -04:00 committed by GitHub
parent 8c1f4b1a62
commit bca80c0d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 24 deletions

View File

@ -83,7 +83,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
.includeClientModificationFeatures( .includeClientModificationFeatures(
ClientModificationFeature.Authorizations, ClientModificationFeature.Authorizations,
ClientModificationFeature.UserAgent ClientModificationFeature.UserAgent
).includeSchemaSupportFeatures( ).includeSchemaSupportFeatures(
SchemaSupportFeature.Polymorphism, SchemaSupportFeature.Polymorphism,
SchemaSupportFeature.Union, SchemaSupportFeature.Union,
SchemaSupportFeature.Composite, SchemaSupportFeature.Composite,
@ -277,7 +277,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
imports.put("Uint8List", "dart:typed_data"); imports.put("Uint8List", "dart:typed_data");
imports.put("MultipartFile", DIO_IMPORT); imports.put("MultipartFile", DIO_IMPORT);
} }
private void configureDateLibrary(String srcFolder) { private void configureDateLibrary(String srcFolder) {
switch (dateLibrary) { switch (dateLibrary) {
case DATE_LIBRARY_TIME_MACHINE: case DATE_LIBRARY_TIME_MACHINE:
@ -364,12 +364,12 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
} }
} }
for (CodegenModel model : allModels.values()) { for (CodegenModel model : allModels.values()) {
syncRootTypesWithInnerVars(allModels, model); syncRootTypesWithInnerVars(allModels, model);
} }
} }
private void syncRootTypesWithInnerVars(Map<String, CodegenModel> objs, CodegenModel model) { private void syncRootTypesWithInnerVars(Map<String, CodegenModel> objs, CodegenModel model) {
List<CodegenProperty> allVars = new ArrayList<>(); List<CodegenProperty> allVars = new ArrayList<>();
allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kSelfAndAncestorOnlyProps))); allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kSelfAndAncestorOnlyProps)));
allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kSelfOnlyProps))); allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kSelfOnlyProps)));
allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kAncestorOnlyProps))); allVars.addAll(((Collection<CodegenProperty>) model.vendorExtensions.get(kAncestorOnlyProps)));
@ -383,8 +383,8 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
//fill the property's VendorExtensions with the type's VendorExtensions //fill the property's VendorExtensions with the type's VendorExtensions
prop.getVendorExtensions().put(kIsParent, relatedModel.getVendorExtensions().get(kIsParent)); prop.getVendorExtensions().put(kIsParent, relatedModel.getVendorExtensions().get(kIsParent));
prop.isEnum = relatedModel.isEnum; prop.isEnum = relatedModel.isEnum;
} }
} }
} }
private final String kIsChild = "x-is-child"; private final String kIsChild = "x-is-child";
@ -397,7 +397,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
private final String kSelfAndAncestorOnlyProps = "x-self-and-ancestor-only-props"; private final String kSelfAndAncestorOnlyProps = "x-self-and-ancestor-only-props";
private final String kHasSelfAndAncestorOnlyProps = "x-has-self-and-ancestor-only-props"; private final String kHasSelfAndAncestorOnlyProps = "x-has-self-and-ancestor-only-props";
private final String kParentDiscriminator = "x-parent-discriminator"; private final String kParentDiscriminator = "x-parent-discriminator";
// adapts codegen models and property to dart rules of inheritance // adapts codegen models and property to dart rules of inheritance
private void adaptToDartInheritance(Map<String, ModelsMap> objs) { private void adaptToDartInheritance(Map<String, ModelsMap> objs) {
// get all models // get all models
@ -425,7 +425,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
allAncestorsForAllModelsFlat.addAll(allAncestors); allAncestorsForAllModelsFlat.addAll(allAncestors);
} }
Set<String> allPureClasses = new HashSet<>(); Set<String> allPureClasses = new HashSet<>();
// set isChild,isParent,isPure // set isChild,isParent,isPure
@ -546,11 +546,11 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
} }
} }
/// override the default behavior of createDiscriminator /// override the default behavior of createDiscriminator
/// to remove extra mappings added as a side effect of setLegacyDiscriminatorBehavior(false) /// to remove extra mappings added as a side effect of setLegacyDiscriminatorBehavior(false)
/// this ensures 1-1 schema mapping instead of 1-many /// this ensures 1-1 schema mapping instead of 1-many
@Override @Override
protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, OpenAPI openAPI) { protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, OpenAPI openAPI) {
CodegenDiscriminator sub = super.createDiscriminator(schemaName, schema, openAPI); CodegenDiscriminator sub = super.createDiscriminator(schemaName, schema, openAPI);
Discriminator originalDiscriminator = schema.getDiscriminator(); Discriminator originalDiscriminator = schema.getDiscriminator();
if (originalDiscriminator!=null) { if (originalDiscriminator!=null) {
@ -566,7 +566,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
} }
} }
} }
} }
return sub; return sub;
} }
@ -674,7 +674,7 @@ public class DartDioClientCodegen extends AbstractDartCodegen {
} }
} }
if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library) && (op.getHasFormParams() || op.getHasQueryParams())) { if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library) && (op.getHasFormParams() || op.getHasQueryParams() || op.getHasPathParams())) {
resultImports.add("package:" + pubName + "/" + sourceFolder + "/api_util.dart"); resultImports.add("package:" + pubName + "/" + sourceFolder + "/api_util.dart");
} }

View File

@ -51,7 +51,7 @@ class {{classname}} {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{{baseName}}}' '}', {{{paramName}}}.toString()){{/pathParams}}; final _path = r'{{{path}}}'{{#pathParams}}.replaceAll('{' r'{{{baseName}}}' '}', {{#includeLibraryTemplate}}api/query_param{{/includeLibraryTemplate}}.toString()){{/pathParams}};
final _options = Options( final _options = Options(
method: r'{{#lambda.uppercase}}{{httpMethod}}{{/lambda.uppercase}}', method: r'{{#lambda.uppercase}}{{httpMethod}}{{/lambda.uppercase}}',
{{#isResponseFile}} {{#isResponseFile}}

View File

@ -117,7 +117,7 @@ class PetApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/pet/{petId}'.replaceAll('{' r'petId' '}', petId.toString()); final _path = r'/pet/{petId}'.replaceAll('{' r'petId' '}', encodeQueryParameter(_serializers, petId, const FullType(int)).toString());
final _options = Options( final _options = Options(
method: r'DELETE', method: r'DELETE',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -341,7 +341,7 @@ class PetApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/pet/{petId}'.replaceAll('{' r'petId' '}', petId.toString()); final _path = r'/pet/{petId}'.replaceAll('{' r'petId' '}', encodeQueryParameter(_serializers, petId, const FullType(int)).toString());
final _options = Options( final _options = Options(
method: r'GET', method: r'GET',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -499,7 +499,7 @@ class PetApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/pet/{petId}'.replaceAll('{' r'petId' '}', petId.toString()); final _path = r'/pet/{petId}'.replaceAll('{' r'petId' '}', encodeQueryParameter(_serializers, petId, const FullType(int)).toString());
final _options = Options( final _options = Options(
method: r'POST', method: r'POST',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -577,7 +577,7 @@ class PetApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/pet/{petId}/uploadImage'.replaceAll('{' r'petId' '}', petId.toString()); final _path = r'/pet/{petId}/uploadImage'.replaceAll('{' r'petId' '}', encodeQueryParameter(_serializers, petId, const FullType(int)).toString());
final _options = Options( final _options = Options(
method: r'POST', method: r'POST',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -683,7 +683,7 @@ class PetApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/fake/{petId}/uploadImageWithRequiredFile'.replaceAll('{' r'petId' '}', petId.toString()); final _path = r'/fake/{petId}/uploadImageWithRequiredFile'.replaceAll('{' r'petId' '}', encodeQueryParameter(_serializers, petId, const FullType(int)).toString());
final _options = Options( final _options = Options(
method: r'POST', method: r'POST',
headers: <String, dynamic>{ headers: <String, dynamic>{

View File

@ -8,6 +8,7 @@ import 'package:built_value/serializer.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:built_collection/built_collection.dart'; import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/api_util.dart';
import 'package:openapi/src/model/order.dart'; import 'package:openapi/src/model/order.dart';
class StoreApi { class StoreApi {
@ -41,7 +42,7 @@ class StoreApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/store/order/{order_id}'.replaceAll('{' r'order_id' '}', orderId.toString()); final _path = r'/store/order/{order_id}'.replaceAll('{' r'order_id' '}', encodeQueryParameter(_serializers, orderId, const FullType(String)).toString());
final _options = Options( final _options = Options(
method: r'DELETE', method: r'DELETE',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -168,7 +169,7 @@ class StoreApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/store/order/{order_id}'.replaceAll('{' r'order_id' '}', orderId.toString()); final _path = r'/store/order/{order_id}'.replaceAll('{' r'order_id' '}', encodeQueryParameter(_serializers, orderId, const FullType(int)).toString());
final _options = Options( final _options = Options(
method: r'GET', method: r'GET',
headers: <String, dynamic>{ headers: <String, dynamic>{

View File

@ -243,7 +243,7 @@ class UserApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/user/{username}'.replaceAll('{' r'username' '}', username.toString()); final _path = r'/user/{username}'.replaceAll('{' r'username' '}', encodeQueryParameter(_serializers, username, const FullType(String)).toString());
final _options = Options( final _options = Options(
method: r'DELETE', method: r'DELETE',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -290,7 +290,7 @@ class UserApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/user/{username}'.replaceAll('{' r'username' '}', username.toString()); final _path = r'/user/{username}'.replaceAll('{' r'username' '}', encodeQueryParameter(_serializers, username, const FullType(String)).toString());
final _options = Options( final _options = Options(
method: r'GET', method: r'GET',
headers: <String, dynamic>{ headers: <String, dynamic>{
@ -492,7 +492,7 @@ class UserApi {
ProgressCallback? onSendProgress, ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress, ProgressCallback? onReceiveProgress,
}) async { }) async {
final _path = r'/user/{username}'.replaceAll('{' r'username' '}', username.toString()); final _path = r'/user/{username}'.replaceAll('{' r'username' '}', encodeQueryParameter(_serializers, username, const FullType(String)).toString());
final _options = Options( final _options = Options(
method: r'PUT', method: r'PUT',
headers: <String, dynamic>{ headers: <String, dynamic>{