Skip to content

Commit

Permalink
tsp, internal on op won't have effect on its model, if not convenient (
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored May 17, 2024
1 parent ae326f1 commit 892c210
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 101 deletions.
53 changes: 25 additions & 28 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,18 +926,18 @@ export class CodeModelBuilder {
// track usage
if (pollingSchema) {
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Output] });
if (op.internalApi) {
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Internal] });
} else if (op.convenienceApi) {
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Public] });
if (op.convenienceApi) {
this.trackSchemaUsage(pollingSchema, {
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
});
}
}
if (finalSchema) {
this.trackSchemaUsage(finalSchema, { usage: [SchemaContext.Output] });
if (op.internalApi) {
this.trackSchemaUsage(pollingSchema, { usage: [SchemaContext.Internal] });
} else if (op.convenienceApi) {
this.trackSchemaUsage(finalSchema, { usage: [SchemaContext.Public] });
if (op.convenienceApi) {
this.trackSchemaUsage(finalSchema, {
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
});
}
}

Expand Down Expand Up @@ -1117,10 +1117,8 @@ export class CodeModelBuilder {

this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });

if (op.internalApi) {
this.trackSchemaUsage(schema, { usage: [SchemaContext.Internal] });
} else if (op.convenienceApi) {
this.trackSchemaUsage(schema, { usage: [SchemaContext.Public] });
if (op.convenienceApi) {
this.trackSchemaUsage(schema, { usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public] });
}

if (param.name.toLowerCase() === CONTENT_TYPE_KEY) {
Expand Down Expand Up @@ -1276,10 +1274,10 @@ export class CodeModelBuilder {
);

this.trackSchemaUsage(requestConditionsSchema, { usage: [SchemaContext.Input] });
if (op.internalApi) {
this.trackSchemaUsage(requestConditionsSchema, { usage: [SchemaContext.Internal] });
} else if (op.convenienceApi) {
this.trackSchemaUsage(requestConditionsSchema, { usage: [SchemaContext.Public] });
if (op.convenienceApi) {
this.trackSchemaUsage(requestConditionsSchema, {
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
});
}

// update group schema for properties
Expand Down Expand Up @@ -1352,10 +1350,9 @@ export class CodeModelBuilder {

this.trackSchemaUsage(schema, { usage: [SchemaContext.Input] });

if (op.internalApi) {
this.trackSchemaUsage(schema, { usage: [SchemaContext.Internal] });
} else if (op.convenienceApi) {
this.trackSchemaUsage(schema, { usage: [SchemaContext.Public] });
if (op.convenienceApi) {
// model/schema does not need to be Public or Internal, if it is not to be used in convenience API
this.trackSchemaUsage(schema, { usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public] });
}

if (operationIsJsonMergePatch(httpOperation)) {
Expand Down Expand Up @@ -1467,10 +1464,10 @@ export class CodeModelBuilder {
});

this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Input] });
if (op.internalApi) {
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Internal] });
} else if (op.convenienceApi) {
this.trackSchemaUsage(optionBagSchema, { usage: [SchemaContext.Public] });
if (op.convenienceApi) {
this.trackSchemaUsage(optionBagSchema, {
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
});
}

// option bag parameter
Expand Down Expand Up @@ -1656,10 +1653,10 @@ export class CodeModelBuilder {
if (response instanceof SchemaResponse) {
this.trackSchemaUsage(response.schema, { usage: [SchemaContext.Output] });

if (op.internalApi) {
this.trackSchemaUsage(response.schema, { usage: [SchemaContext.Internal] });
} else if (trackConvenienceApi) {
this.trackSchemaUsage(response.schema, { usage: [SchemaContext.Public] });
if (trackConvenienceApi) {
this.trackSchemaUsage(response.schema, {
usage: [op.internalApi ? SchemaContext.Internal : SchemaContext.Public],
});
}
}
}
Expand Down
73 changes: 0 additions & 73 deletions typespec-tests/main.tsp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ Mono<Response<BinaryData>> getInternalWithResponse(RequestOptions requestOptions
return this.serviceClient.getInternalWithResponseAsync(requestOptions);
}

/**
* The postProtocalInternal operation.
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* }
* }</pre>
*
* @param body The body parameter.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the {@link Response} on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<Response<Void>> postProtocalInternalWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.postProtocalInternalWithResponseAsync(body, requestOptions);
}

/**
* The postInternal operation.
*
Expand Down
24 changes: 24 additions & 0 deletions typespec-tests/src/main/java/com/cadl/internal/InternalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ Response<BinaryData> getInternalWithResponse(RequestOptions requestOptions) {
return this.serviceClient.getInternalWithResponse(requestOptions);
}

/**
* The postProtocalInternal operation.
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* }
* }</pre>
*
* @param body The body parameter.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Response<Void> postProtocalInternalWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.postProtocalInternalWithResponse(body, requestOptions);
}

/**
* The postInternal operation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ Mono<Response<BinaryData>> getInternal(@HostParam("endpoint") String endpoint,
@UnexpectedResponseExceptionType(HttpResponseException.class)
Response<BinaryData> getInternalSync(@HostParam("endpoint") String endpoint,
@HeaderParam("accept") String accept, RequestOptions requestOptions, Context context);

@Post("/internal/protocal-internal")
@ExpectedResponses({ 204 })
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<Response<Void>> postProtocalInternal(@HostParam("endpoint") String endpoint,
@HeaderParam("accept") String accept, @BodyParam("application/json") BinaryData body,
RequestOptions requestOptions, Context context);

@Post("/internal/protocal-internal")
@ExpectedResponses({ 204 })
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Response<Void> postProtocalInternalSync(@HostParam("endpoint") String endpoint,
@HeaderParam("accept") String accept, @BodyParam("application/json") BinaryData body,
RequestOptions requestOptions, Context context);
}

/**
Expand Down Expand Up @@ -218,4 +238,53 @@ public Response<BinaryData> getInternalWithResponse(RequestOptions requestOption
final String accept = "application/json";
return service.getInternalSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE);
}

/**
* The postProtocalInternal operation.
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* }
* }</pre>
*
* @param body The body parameter.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the {@link Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> postProtocalInternalWithResponseAsync(BinaryData body, RequestOptions requestOptions) {
final String accept = "application/json";
return FluxUtil.withContext(
context -> service.postProtocalInternal(this.client.getEndpoint(), accept, body, requestOptions, context));
}

/**
* The postProtocalInternal operation.
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* }
* }</pre>
*
* @param body The body parameter.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> postProtocalInternalWithResponse(BinaryData body, RequestOptions requestOptions) {
final String accept = "application/json";
return service.postProtocalInternalSync(this.client.getEndpoint(), accept, body, requestOptions, Context.NONE);
}
}
11 changes: 11 additions & 0 deletions typespec-tests/tsp/internal.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ union UnusedEnum {
"Weekend",
}

// ProtocolInternalModel will not be generated, as the model is not used in convenient API
model ProtocolInternalModel {
name: string;
}

@route("/internal")
interface InternalOp {
// test ApiRequest with Access.public
Expand All @@ -97,4 +102,10 @@ interface InternalOp {
@get
@access(Access.internal, "java")
getInternal(): ApiResponse;

@route("/protocal-internal")
@post
@access(Access.internal)
@convenientAPI(false)
postProtocalInternal(@body body: ProtocolInternalModel): void;
}

0 comments on commit 892c210

Please sign in to comment.