Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI template support in RLC #2814

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open

Conversation

MaryGao
Copy link
Member

@MaryGao MaryGao commented Sep 11, 2024

fixes #2793
fixes #2792

Breakings

CollectionFormat with csv and multi are most commonly used cases, for csv there is no breaking. And for multi there will be a breaking and enabling the option compatibilityQueryMultiFormat: true would mitigate this breaking.

CollectionFormat with tsv is no longer supported and we are not aware of any real cases yet.

Possible values

  • allowReserved: true/false
  • value: primitive/array/object
  • explode: true/false
  • style: form/spaceDelimited/pipeDelimited

In-scoped cases

Path allowReserved

Support to define allowReserved for path parameter but the style and explode support for path parameter is not in-scope of this pr. The default for allowReserved would be

  • allowReserved = false
allowReserved Supported
true y
false y

Query expansion

Please note the allowReserved for query paremeter is not in scope of this pr. Except the form style we would also include the spaceDelimited and pipeDelimited mainly considering backward-compatibility. The default setting would be:

  • style = form & explode = false
Style Explode Uri Template Primitive value id = 5 Array id = [3, 4, 5] Object id = {"role": "admin", "firstName": "Alex"} Supported
form false /users{?id} /users?id=5 /users?id=3,4,5 /users?id=role,admin,firstName,Alex y
form* true* /users{?id*} /users?id=5 /users?id=3&id=4&id=5 /users?role=admin&firstName=Alex y
spaceDelimited false n/a n/a /users?id=3%204%205 n/a y
pipeDelimited false n/a n/a /users?id=3|4|5 n/a y

Out-of-scope cases

  • tsv tab separated format(no real case yet.)
  • Header expansion(header design is not changed and any support in header is out-of this pr's scope.)
  • Path with explode
  • Query with allowReserved

@MaryGao MaryGao requested a review from timovv October 25, 2024 08:36
@@ -312,7 +313,8 @@ function generateRLCIndex(file: SourceFile, model: RLCModel) {
hasSsvCollection(model) ||
hasPipeCollection(model) ||
hasTsvCollection(model) ||
hasCsvCollection(model)
hasCsvCollection(model) ||
(model.helperDetails?.parameterBuilders ?? []).length > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove the code for ssv and other not going to support collection helpers codegen logic ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i plan to remove all logic in modular pr, currently modular still have this dependency.

@@ -130,7 +172,7 @@ export declare interface QueryTsvQueryParam {
}

export declare interface QueryTsvQueryParamProperties {
colors: string;
colors: string[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this expected to get this in the tsv case even the compatibilityMode is enabled?

Copy link
Member Author

@MaryGao MaryGao Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we only keep original code for multi cases and which only happened in reality.

export declare interface QueryParametersQueryContinuationStandardRecordQueryParam {
queryParameters: QueryParametersQueryContinuationStandardRecordQueryParamProperties;
}

export declare interface QueryParametersQueryContinuationStandardRecordQueryParamProperties {
param: Record<string, number>;
param: QueryParametersQueryContinuationStandardRecordParamQueryParam;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a case where value type is array of objects?

Copy link
Member Author

@MaryGao MaryGao Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for complicated nested cases e.g objected nested array or array nested objects i don't think we have agreement on how to serialize them correctly. our core is not ready either.

i think this would be a cross-language issue and prefer to defer any discussion for them for now considering no real usage.

Comment on lines +125 to 127
assert.deepEqual(result.body, responseBody);
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the catch error part in this case? what about other cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed useless codes here. we don't need to catch any error to fail. if exception happens the case would fail directly.

i updated cases i met in this pr. but i remember i told jiaodi to remove for any new cases.

export declare type QueryPipesParameters = QueryPipesQueryParam & RequestParameters;

export declare interface QueryPipesQueryParam {
queryParameters: QueryPipesQueryParamProperties;
}

export declare interface QueryPipesQueryParamProperties {
colors: string;
colors: QueryPipesColorsQueryParam;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is not show as compatibleMode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the option to compatibilityQueryMultiFormat.

const operationFiles = await emitModularOperationsFromTypeSpec(
tspContent,
{
mustEmptyDiagnostic: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what diagnostic warning will we get? is it the query format deprecation warning? but why it's not reported before query format should be deprecated a long time ago ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bugfix and here we should report diagnostic of unable-serialized-type for header but not: https://github.com/marygao/autorest.typescript/blob/uri-template-support/packages/typespec-ts/src/utils/parameterUtils.ts#L152-L156.

so the new warning is introduced by this pr's fix.

const clientDef = await emitParameterFromTypeSpec(
`
@route("template/{+param}")
op template(param: string): void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add tests to test against the generated Routes and generated helpers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the Routes generation.

importInfo: {
internalImports: importSet,
runtimeImports: buildRuntimeImports("azure")
},
options: {
sourceFrom: "TypeSpec"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the default not TypeSpec?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we didn't set this this would be undefined. i just set it explicitly in code.

in our code we would set it as TypeSpec.

@@ -153,6 +153,16 @@ If we enable this option `clearOutputFolder` we would empty the whole output fol
clearOutputFolder: true
```

### compatibilityMode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use a new option, in the url template case, compatibilityMode is not fully backward compatible, you still drop the support for ssv and tsv, pipe etc. While in additionaly properties case, it is really backward compatible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as compatibilityQueryMultiFormat option.

@MaryGao MaryGao requested a review from qiaozha October 29, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support explode for query in RLC Support allowReserved in path for RLC
6 participants