Skip to content

Commit

Permalink
Support 'default' property in JSON schemas (#2225)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin authored Jul 12, 2024
1 parent b475f29 commit fa344a1
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 54 deletions.
7 changes: 6 additions & 1 deletion src/autorest.bicep/src/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,23 @@ export function generateSchema(host: AutorestExtensionHost, definition: Provider
return {
type: 'string',
format: combinedSchema.format,
default: combinedSchema.defaultValue,
};
}

if (combinedSchema instanceof UuidSchema) {
return {
type: 'string',
pattern: '^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$'
pattern: '^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$',
default: combinedSchema.defaultValue,
};
}

if (combinedSchema instanceof StringSchema) {
return {
type: 'string',
pattern: combinedSchema.pattern,
default: combinedSchema.defaultValue,
minLength: combinedSchema.minLength,
maxLength: combinedSchema.maxLength,
};
Expand All @@ -307,6 +310,7 @@ export function generateSchema(host: AutorestExtensionHost, definition: Provider
if (combinedSchema instanceof NumberSchema) {
return {
type: combinedSchema.type,
default: combinedSchema.defaultValue,
minimum: combinedSchema.minimum,
maximum: combinedSchema.maximum,
multipleOf: combinedSchema.multipleOf,
Expand All @@ -315,6 +319,7 @@ export function generateSchema(host: AutorestExtensionHost, definition: Provider

return {
type: toBuiltInTypeKind(combinedSchema),
default: combinedSchema.defaultValue,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@
}
]
},
"intWithDefaultValue": {
"oneOf": [
{
"default": 7,
"type": "integer"
},
{
"$ref": "https://schema.management.azure.com/schemas/common/definitions.json#/definitions/expression"
}
]
},
"password": {
"oneOf": [
{
Expand Down Expand Up @@ -551,6 +562,17 @@
}
]
},
"intWithDefaultValue": {
"oneOf": [
{
"default": 7,
"type": "integer"
},
{
"$ref": "https://schema.management.azure.com/schemas/common/definitions.json#/definitions/expression"
}
]
},
"locationData": {
"description": "Metadata pertaining to the geographic location of the resource.",
"oneOf": [
Expand Down
Loading

0 comments on commit fa344a1

Please sign in to comment.