Skip to content

Commit 0df71b0

Browse files
tsp, multipart model naming (#2894)
* bump cadl-ranch * multipart, do not rename File model, if it is not TypeSpec.Http.File
1 parent 304d72c commit 0df71b0

34 files changed

+2417
-1483
lines changed

typespec-extension/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 0.18.4 (Unreleased)
3+
## 0.18.4 (2024-08-07)
44

55
Compatible with compiler 0.58.
66

typespec-extension/src/code-model-builder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ export class CodeModelBuilder {
20852085
nullable = true;
20862086
nonNullType = nonNullType.type;
20872087
}
2088-
let schema = this.processSchemaFromSdkType(nonNullType, "");
2088+
let schema;
20892089

20902090
let extensions: Record<string, any> | undefined = undefined;
20912091
if (this.isSecret(prop)) {
@@ -2108,7 +2108,11 @@ export class CodeModelBuilder {
21082108
// TODO: handle MultipartOptions.isMulti
21092109
if (prop.multipartOptions.isFilePart) {
21102110
schema = this.processMultipartFormDataFilePropertySchemaFromSdkType(prop);
2111+
} else {
2112+
schema = this.processSchemaFromSdkType(nonNullType, "");
21112113
}
2114+
} else {
2115+
schema = this.processSchemaFromSdkType(nonNullType, "");
21122116
}
21132117

21142118
return new Property(prop.name, prop.details ?? "", schema, {

typespec-extension/src/external-schemas.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ export function createPollOperationDetailsSchema(schemas: Schemas, stringSchema:
115115

116116
const fileDetailsMap: Map<string, ObjectSchema> = new Map();
117117

118-
function getFileSchemaName(baseName: string) {
118+
function getFileSchemaName(baseName: string, sdkModelType?: SdkModelType): string {
119+
// If the TypeSpec Model exists and is not TypeSpec.Http.File, directly use its name
120+
if (sdkModelType && sdkModelType.crossLanguageDefinitionId !== "TypeSpec.Http.File") {
121+
return baseName;
122+
}
123+
119124
// make sure suffix "FileDetails"
120125
if (baseName.toLocaleLowerCase().endsWith("filedetails")) {
121126
return pascalCase(baseName);
@@ -232,7 +237,7 @@ export function getFileDetailsSchema(
232237
*/
233238
const filePropertyName = property.name;
234239
const fileSchemaName = fileSdkType.name;
235-
const schemaName = getFileSchemaName(fileSchemaName);
240+
const schemaName = getFileSchemaName(fileSchemaName, fileSdkType);
236241
let fileDetailsSchema = fileDetailsMap.get(schemaName);
237242
if (!fileDetailsSchema) {
238243
const typeNamespace = getNamespace(property.type.__raw) ?? namespace;

typespec-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"testserver-run": "npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./cadl-ranch-coverage-java.json"
1010
},
1111
"dependencies": {
12-
"@azure-tools/cadl-ranch-specs": "0.34.10",
12+
"@azure-tools/cadl-ranch-specs": "0.35.2",
1313
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.18.4.tgz"
1414
},
1515
"devDependencies": {

typespec-tests/src/main/java/com/_specs_/azure/core/basic/BasicAsyncClient.java

Lines changed: 0 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import com._specs_.azure.core.basic.implementation.BasicClientImpl;
88
import com._specs_.azure.core.basic.implementation.JsonMergePatchHelper;
9-
import com._specs_.azure.core.basic.models.ListItemInputBody;
10-
import com._specs_.azure.core.basic.models.ListItemInputExtensibleEnum;
119
import com._specs_.azure.core.basic.models.User;
1210
import com.azure.core.annotation.Generated;
1311
import com.azure.core.annotation.ReturnType;
@@ -240,119 +238,6 @@ public PagedFlux<BinaryData> list(RequestOptions requestOptions) {
240238
return this.serviceClient.listAsync(requestOptions);
241239
}
242240

243-
/**
244-
* List with Azure.Core.Page&lt;&gt;.
245-
* <p><strong>Response Body Schema</strong></p>
246-
*
247-
* <pre>{@code
248-
* {
249-
* id: int (Required)
250-
* name: String (Optional, Required on create)
251-
* orders (Optional): [
252-
* (Optional){
253-
* id: int (Required)
254-
* userId: int (Optional, Required on create)
255-
* detail: String (Optional, Required on create)
256-
* }
257-
* ]
258-
* etag: String (Required)
259-
* }
260-
* }</pre>
261-
*
262-
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
263-
* @throws HttpResponseException thrown if the request is rejected by server.
264-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
265-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
266-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
267-
* @return paged collection of User items as paginated response with {@link PagedFlux}.
268-
*/
269-
@Generated
270-
@ServiceMethod(returns = ReturnType.COLLECTION)
271-
public PagedFlux<BinaryData> listWithPage(RequestOptions requestOptions) {
272-
return this.serviceClient.listWithPageAsync(requestOptions);
273-
}
274-
275-
/**
276-
* List with extensible enum parameter Azure.Core.Page&lt;&gt;.
277-
* <p><strong>Query Parameters</strong></p>
278-
* <table border="1">
279-
* <caption>Query Parameters</caption>
280-
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
281-
* <tr><td>another</td><td>String</td><td>No</td><td>Another query parameter. Allowed values: "First",
282-
* "Second".</td></tr>
283-
* </table>
284-
* You can add these to a request with {@link RequestOptions#addQueryParam}
285-
* <p><strong>Request Body Schema</strong></p>
286-
*
287-
* <pre>{@code
288-
* {
289-
* inputName: String (Required)
290-
* }
291-
* }</pre>
292-
*
293-
* <p><strong>Response Body Schema</strong></p>
294-
*
295-
* <pre>{@code
296-
* {
297-
* id: int (Required)
298-
* name: String (Optional, Required on create)
299-
* orders (Optional): [
300-
* (Optional){
301-
* id: int (Required)
302-
* userId: int (Optional, Required on create)
303-
* detail: String (Optional, Required on create)
304-
* }
305-
* ]
306-
* etag: String (Required)
307-
* }
308-
* }</pre>
309-
*
310-
* @param bodyInput The body of the input.
311-
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
312-
* @throws HttpResponseException thrown if the request is rejected by server.
313-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
314-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
315-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
316-
* @return paged collection of User items as paginated response with {@link PagedFlux}.
317-
*/
318-
@Generated
319-
@ServiceMethod(returns = ReturnType.COLLECTION)
320-
public PagedFlux<BinaryData> listWithParameters(BinaryData bodyInput, RequestOptions requestOptions) {
321-
return this.serviceClient.listWithParametersAsync(bodyInput, requestOptions);
322-
}
323-
324-
/**
325-
* List with custom page model.
326-
* <p><strong>Response Body Schema</strong></p>
327-
*
328-
* <pre>{@code
329-
* {
330-
* id: int (Required)
331-
* name: String (Optional, Required on create)
332-
* orders (Optional): [
333-
* (Optional){
334-
* id: int (Required)
335-
* userId: int (Optional, Required on create)
336-
* detail: String (Optional, Required on create)
337-
* }
338-
* ]
339-
* etag: String (Required)
340-
* }
341-
* }</pre>
342-
*
343-
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
344-
* @throws HttpResponseException thrown if the request is rejected by server.
345-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
346-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
347-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
348-
* @return the paginated response with {@link PagedFlux}.
349-
*/
350-
@Generated
351-
@ServiceMethod(returns = ReturnType.COLLECTION)
352-
public PagedFlux<BinaryData> listWithCustomPageModel(RequestOptions requestOptions) {
353-
return this.serviceClient.listWithCustomPageModelAsync(requestOptions);
354-
}
355-
356241
/**
357242
* Deletes a user.
358243
*
@@ -587,134 +472,6 @@ public PagedFlux<User> list() {
587472
});
588473
}
589474

590-
/**
591-
* List with Azure.Core.Page&lt;&gt;.
592-
*
593-
* @throws HttpResponseException thrown if the request is rejected by server.
594-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
595-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
596-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
597-
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
598-
* @return paged collection of User items as paginated response with {@link PagedFlux}.
599-
*/
600-
@Generated
601-
@ServiceMethod(returns = ReturnType.COLLECTION)
602-
public PagedFlux<User> listWithPage() {
603-
// Generated convenience method for listWithPage
604-
RequestOptions requestOptions = new RequestOptions();
605-
PagedFlux<BinaryData> pagedFluxResponse = listWithPage(requestOptions);
606-
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
607-
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
608-
? pagedFluxResponse.byPage().take(1)
609-
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
610-
return flux.map(pagedResponse -> new PagedResponseBase<Void, User>(pagedResponse.getRequest(),
611-
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
612-
pagedResponse.getValue()
613-
.stream()
614-
.map(protocolMethodData -> protocolMethodData.toObject(User.class))
615-
.collect(Collectors.toList()),
616-
pagedResponse.getContinuationToken(), null));
617-
});
618-
}
619-
620-
/**
621-
* List with extensible enum parameter Azure.Core.Page&lt;&gt;.
622-
*
623-
* @param bodyInput The body of the input.
624-
* @param another Another query parameter.
625-
* @throws IllegalArgumentException thrown if parameters fail the validation.
626-
* @throws HttpResponseException thrown if the request is rejected by server.
627-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
628-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
629-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
630-
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
631-
* @return paged collection of User items as paginated response with {@link PagedFlux}.
632-
*/
633-
@Generated
634-
@ServiceMethod(returns = ReturnType.COLLECTION)
635-
public PagedFlux<User> listWithParameters(ListItemInputBody bodyInput, ListItemInputExtensibleEnum another) {
636-
// Generated convenience method for listWithParameters
637-
RequestOptions requestOptions = new RequestOptions();
638-
if (another != null) {
639-
requestOptions.addQueryParam("another", another.toString(), false);
640-
}
641-
PagedFlux<BinaryData> pagedFluxResponse = listWithParameters(BinaryData.fromObject(bodyInput), requestOptions);
642-
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
643-
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
644-
? pagedFluxResponse.byPage().take(1)
645-
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
646-
return flux.map(pagedResponse -> new PagedResponseBase<Void, User>(pagedResponse.getRequest(),
647-
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
648-
pagedResponse.getValue()
649-
.stream()
650-
.map(protocolMethodData -> protocolMethodData.toObject(User.class))
651-
.collect(Collectors.toList()),
652-
pagedResponse.getContinuationToken(), null));
653-
});
654-
}
655-
656-
/**
657-
* List with extensible enum parameter Azure.Core.Page&lt;&gt;.
658-
*
659-
* @param bodyInput The body of the input.
660-
* @throws IllegalArgumentException thrown if parameters fail the validation.
661-
* @throws HttpResponseException thrown if the request is rejected by server.
662-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
663-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
664-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
665-
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
666-
* @return paged collection of User items as paginated response with {@link PagedFlux}.
667-
*/
668-
@Generated
669-
@ServiceMethod(returns = ReturnType.COLLECTION)
670-
public PagedFlux<User> listWithParameters(ListItemInputBody bodyInput) {
671-
// Generated convenience method for listWithParameters
672-
RequestOptions requestOptions = new RequestOptions();
673-
PagedFlux<BinaryData> pagedFluxResponse = listWithParameters(BinaryData.fromObject(bodyInput), requestOptions);
674-
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
675-
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
676-
? pagedFluxResponse.byPage().take(1)
677-
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
678-
return flux.map(pagedResponse -> new PagedResponseBase<Void, User>(pagedResponse.getRequest(),
679-
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
680-
pagedResponse.getValue()
681-
.stream()
682-
.map(protocolMethodData -> protocolMethodData.toObject(User.class))
683-
.collect(Collectors.toList()),
684-
pagedResponse.getContinuationToken(), null));
685-
});
686-
}
687-
688-
/**
689-
* List with custom page model.
690-
*
691-
* @throws HttpResponseException thrown if the request is rejected by server.
692-
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
693-
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
694-
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
695-
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
696-
* @return the paginated response with {@link PagedFlux}.
697-
*/
698-
@Generated
699-
@ServiceMethod(returns = ReturnType.COLLECTION)
700-
public PagedFlux<User> listWithCustomPageModel() {
701-
// Generated convenience method for listWithCustomPageModel
702-
RequestOptions requestOptions = new RequestOptions();
703-
PagedFlux<BinaryData> pagedFluxResponse = listWithCustomPageModel(requestOptions);
704-
return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> {
705-
Flux<PagedResponse<BinaryData>> flux = (continuationTokenParam == null)
706-
? pagedFluxResponse.byPage().take(1)
707-
: pagedFluxResponse.byPage(continuationTokenParam).take(1);
708-
return flux.map(pagedResponse -> new PagedResponseBase<Void, User>(pagedResponse.getRequest(),
709-
pagedResponse.getStatusCode(), pagedResponse.getHeaders(),
710-
pagedResponse.getValue()
711-
.stream()
712-
.map(protocolMethodData -> protocolMethodData.toObject(User.class))
713-
.collect(Collectors.toList()),
714-
pagedResponse.getContinuationToken(), null));
715-
});
716-
}
717-
718475
/**
719476
* Deletes a user.
720477
*

0 commit comments

Comments
 (0)