Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait {{{classname}}}: Send + Sync {
### &str and Vec<&str>
}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&'{{#lambda.lifetimeName}}{{{paramName}}}{{/lambda.lifetimeName}} str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{!
### UUIDs
}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{!
}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&'{{#lambda.lifetimeName}}{{{paramName}}}{{/lambda.lifetimeName}} str{{#isArray}}>{{/isArray}}{{/isUuid}}{{!
### Models and primative types
}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{!
### Option End
Expand Down Expand Up @@ -155,7 +155,7 @@ impl {{classname}} for {{classname}}Client {
### &str and Vec<&str>
}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&'{{#lambda.lifetimeName}}{{{paramName}}}{{/lambda.lifetimeName}} str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{!
### UUIDs
}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{!
}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&'{{#lambda.lifetimeName}}{{{paramName}}}{{/lambda.lifetimeName}} str{{#isArray}}>{{/isArray}}{{/isUuid}}{{!
### Models and primative types
}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{!
### Option End
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,24 @@ public void testArrayWithObjectEnumValues() throws IOException {
TestUtils.assertFileExists(outputPath);
TestUtils.assertFileContains(outputPath, enumSpec);
}

@Test
public void testReqwestTraitUuidParamsUseNamedLifetimes() throws IOException {
Path target = Files.createTempDirectory("test");
target.toFile().deleteOnExit();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setGeneratorName("rust")
.setLibrary("reqwest-trait")
.addAdditionalProperty("mockall", true)
.setInputSpec("src/test/resources/3_0/rust/reqwest-trait-uuid-params.yaml")
.setSkipOverwrite(false)
.setOutputDir(target.toAbsolutePath().toString().replace("\\", "/"));
new DefaultGenerator().opts(configurator.toClientOptInput()).generate();
Path outputPath = Path.of(target.toString(), "/src/apis/widget_api.rs");
TestUtils.assertFileExists(outputPath);
// mockall's #[automock] cannot elide the lifetime of a reference nested in Option<..>
TestUtils.assertFileContains(outputPath,
"async fn list_widget_items<'id, 'run_id>(&self, id: &'id str, run_id: Option<&'run_id str>)");
TestUtils.assertFileNotContains(outputPath, "Option<&str>");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.3
info:
title: UUID parameters with the reqwest-trait library
description: >-
Regression test for #24912. UUID parameters must use the named lifetime
declared on the trait method (e.g. Option<&'run_id str>), otherwise
mockall's #[automock] fails to compile.
version: 1.0.0
paths:
/widgets/{id}/items:
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
get:
operationId: listWidgetItems
tags:
- widget
parameters:
- name: run_id
in: query
required: false
schema:
type: string
format: uuid
responses:
"204":
description: No content
Loading