Skip to content

Commit

Permalink
tsp, propagate usage/access to children, only for discriminated model (
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed May 11, 2024
1 parent 2371806 commit bcb3082
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
6 changes: 6 additions & 0 deletions typespec-extension/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 0.15.17 (2024-05-11)

Compatible with compiler 0.56.

- Behavior change on access/usage of non-polymorphic subclass.

## 0.15.16 (2024-05-08)

Compatible with compiler 0.56.
Expand Down
4 changes: 2 additions & 2 deletions typespec-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typespec-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-java",
"version": "0.15.16",
"version": "0.15.17",
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
"keywords": [
"TypeSpec"
Expand Down
15 changes: 6 additions & 9 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2874,20 +2874,17 @@ export class CodeModelBuilder {
schema.parents?.all?.forEach((p) => innerApplySchemaUsage(p, schemaUsage));
schema.parents?.immediate?.forEach((p) => innerApplySchemaUsage(p, schemaUsage));

schema.children?.all?.forEach((c) => innerApplySchemaUsage(c, schemaUsage));
schema.children?.immediate?.forEach((c) => innerApplySchemaUsage(c, schemaUsage));
if (schema.discriminator) {
// propagate access/usage to immediate children, if the schema is a discriminated model
// if the schema is not a discriminated model, its children likely not valid for the mode/API
// TODO: it does not handle the case that concrete model (kind: "type1") for the discriminated model have depth larger than 1 (e.g. kind: "type1" | "type2" in middle)
schema.children?.immediate?.forEach((c) => innerApplySchemaUsage(c, schemaUsage));
}

if (schema.discriminator?.property?.schema) {
innerApplySchemaUsage(schema.discriminator?.property?.schema, schemaUsage);
}
}

// Object.values(schema.discriminator?.all ?? {}).forEach((d) => {
// innerApplySchemaUsage(d, schemaUsage);
// });
// Object.values(schema.discriminator?.immediate ?? {}).forEach((d) => {
// innerApplySchemaUsage(d, schemaUsage);
// });
}
} else if (schema instanceof DictionarySchema) {
innerApplySchemaUsage(schema.elementType, schemaUsage);
Expand Down
2 changes: 1 addition & 1 deletion typespec-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.33.4",
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.16.tgz"
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.17.tgz"
},
"devDependencies": {
"@typespec/prettier-plugin-typespec": "~0.56.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package com.cadl.union.models;
package com.cadl.union.implementation.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.annotation.Generated;
import com.azure.core.util.BinaryData;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.cadl.union.models.Result;
import java.io.IOException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.azure.core.util.BinaryData;
import com.cadl.union.models.Result;
import com.cadl.union.models.SubResult;
import com.cadl.union.implementation.models.SubResult;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
Expand Down
1 change: 1 addition & 0 deletions typespec-tests/tsp/union.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ model Query {
data?: url | bytes;
}

@access(Access.internal)
@usage(Usage.input | Usage.output)
model SubResult extends Result {
text?: string;
Expand Down

0 comments on commit bcb3082

Please sign in to comment.