Skip to content

Commit

Permalink
Add comparisons for model schema
Browse files Browse the repository at this point in the history
  • Loading branch information
markcowl committed Jun 27, 2024
1 parent ff77297 commit cec9604
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 14 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@
"order": 2
}
},
{
"type": "node",
"request": "launch",
"name": "Compile AllProps",
"program": "${workspaceRoot}/core/packages/compiler/entrypoints/cli.js",
"args": ["compile", ".", "--emit=@azure-tools/typespec-autorest"],
"smartStep": true,
"sourceMaps": true,
"skipFiles": ["<node_internals>/**/*.js"],
"outFiles": [
"${workspaceFolder}/packages/*/dist/**/*.js",
"${workspaceFolder}/packages/*/dist-dev/**/*.js",
"${workspaceFolder}/core/packages/*/dist/**/*.js",
"${workspaceFolder}/core/packages/*/dist-dev/**/*.js"
],
"cwd": "${workspaceRoot}/packages/samples/specs/resource-manager/arm-library",
"presentation": {
"order": 2
}
},
{
"name": "Regenerate .tmlanguage",
"type": "node",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,24 @@
}
}
},
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Azure.ResourceManager.ResourceProvisioningState": {
"type": "string",
"description": "The provisioning state of a resource type.",
Expand Down Expand Up @@ -2116,7 +2134,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Employee": {
"type": "object",
"description": "A ContosoProviderHub resource",
Expand Down Expand Up @@ -655,7 +673,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Employee": {
"type": "object",
"description": "A ContosoProviderHub resource",
Expand Down Expand Up @@ -504,7 +522,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Dependent": {
"type": "object",
"description": "Concrete proxy resource types can be created by aliasing this type using a specific property type.",
Expand Down Expand Up @@ -890,7 +908,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Employee": {
"type": "object",
"description": "A ContosoProviderHub resource",
Expand Down Expand Up @@ -403,7 +421,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Employee": {
"type": "object",
"description": "A ContosoProviderHub resource",
Expand Down Expand Up @@ -441,7 +459,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Employee": {
"type": "object",
"description": "A ContosoProviderHub resource",
Expand Down Expand Up @@ -517,7 +535,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,24 @@
}
},
"definitions": {
"Azure.ResourceManager.CommonTypes.TrackedResourceUpdate": {
"type": "object",
"description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'",
"properties": {
"tags": {
"type": "object",
"description": "Resource tags.",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource"
}
]
},
"Division": {
"type": "object",
"description": "The company division",
Expand Down Expand Up @@ -609,7 +627,7 @@
},
"allOf": [
{
"$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource"
"$ref": "#/definitions/Azure.ResourceManager.CommonTypes.TrackedResourceUpdate"
}
]
},
Expand Down
11 changes: 7 additions & 4 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,12 +879,12 @@ export async function getOpenAPIForService(
}
return undefined;
}
function getSchemaOrRef(type: Type, schemaContext: SchemaContext, isDerived?: boolean): any {
function getSchemaOrRef(type: Type, schemaContext: SchemaContext): any {
let schemaNameOverride: ((name: string, visibility: Visibility) => string) | undefined =
undefined;
const ref = resolveExternalRef(type);
if (ref) {
if (isDerived || !metadataInfo.isTransformed(type, schemaContext.visibility)) {
if (!metadataInfo.isTransformed(type, schemaContext.visibility)) {
return ref;
}

Expand Down Expand Up @@ -1653,6 +1653,7 @@ export async function getOpenAPIForService(

function includeDerivedModel(model: Model): boolean {
return (
!resolveExternalRef(model) &&
!isTemplateDeclaration(model) &&
(model.templateMapper?.args === undefined ||
model.templateMapper?.args.length === 0 ||
Expand Down Expand Up @@ -1710,11 +1711,13 @@ export async function getOpenAPIForService(
modelSchema.additionalProperties = getSchemaOrRef(model.indexer.value, schemaContext);
}

const derivedModels = model.derivedModels.filter(includeDerivedModel);
const derivedModels = resolveExternalRef(model)
? []
: model.derivedModels.filter(includeDerivedModel);

// getSchemaOrRef on all children to push them into components.schemas
for (const child of derivedModels) {
getSchemaOrRef(child, schemaContext, true);
getSchemaOrRef(child, schemaContext);
}

const discriminator = getDiscriminator(program, model);
Expand Down
5 changes: 3 additions & 2 deletions packages/typespec-azure-resource-manager/lib/interfaces.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ interface ResourceInstanceOperations<
Resource extends Foundations.Resource,
Properties extends TypeSpec.Reflection.Model,
BaseParameters = DefaultBaseParameters<Resource>,
PatchModel = ResourceUpdateModel<Resource, Properties>
PatchModel extends {} = {}
>
extends ResourceRead<Resource, BaseParameters>,
ResourceCreate<Resource, BaseParameters>,
Expand Down Expand Up @@ -314,7 +314,8 @@ interface ResourceUpdateAsync<
interface ResourceUpdateSync<
Resource extends Foundations.Resource,
Properties extends TypeSpec.Reflection.Model,
BaseParameters = DefaultBaseParameters<Resource>
BaseParameters = DefaultBaseParameters<Resource>,
PatchModel extends {} = {}
> {
/**
* @dev Update a resource using the synchronous call pattern.
Expand Down

0 comments on commit cec9604

Please sign in to comment.