diff --git a/src/Bicep.Types/Serialization/TypeJsonContext.cs b/src/Bicep.Types/Serialization/TypeJsonContext.cs index 666d231d..a9047fd7 100644 --- a/src/Bicep.Types/Serialization/TypeJsonContext.cs +++ b/src/Bicep.Types/Serialization/TypeJsonContext.cs @@ -15,6 +15,7 @@ namespace Azure.Bicep.Types.Serialization; [JsonSerializable(typeof(ObjectType))] [JsonSerializable(typeof(FunctionType))] [JsonSerializable(typeof(ResourceFunctionType))] +[JsonSerializable(typeof(NamespaceFunctionType))] [JsonSerializable(typeof(ResourceType))] [JsonSerializable(typeof(StringLiteralType))] [JsonSerializable(typeof(UnionType))] diff --git a/src/bicep-types-go/writers/markdown.go b/src/bicep-types-go/writers/markdown.go index c6524bf9..832397c3 100644 --- a/src/bicep-types-go/writers/markdown.go +++ b/src/bicep-types-go/writers/markdown.go @@ -330,6 +330,14 @@ func writeComplexType(md *markdownBuilder, typesList []types.Type, t types.Type, } md.writeBullet("Description", description) + if concrete.EvaluatedLanguageExpression != "" { + md.writeBullet("Evaluated language expression", fmt.Sprintf("`%s`", concrete.EvaluatedLanguageExpression)) + } + + if concrete.VisibleInFileKind != nil { + md.writeBullet("Visible only in bicep file kind", formatBicepSourceFileKind(*concrete.VisibleInFileKind)) + } + if len(concrete.Parameters) > 0 { md.writeHeading(nesting+1, "Parameters") for i, param := range concrete.Parameters { @@ -337,7 +345,14 @@ func writeComplexType(md *markdownBuilder, typesList []types.Type, t types.Type, if err != nil { return err } - md.writeNumbered(i+1, param.Name, paramTypeName) + value := paramTypeName + if flags := formatNamespaceFunctionParameterFlags(param.Flags); flags != "" { + value += fmt.Sprintf(" (%s)", flags) + } + if param.Description != "" { + value += ": " + param.Description + } + md.writeNumbered(i+1, param.Name, value) } } @@ -345,7 +360,7 @@ func writeComplexType(md *markdownBuilder, typesList []types.Type, t types.Type, if err != nil { return err } - md.writeBullet("Output", outputTypeName) + md.writeBullet("Output type", outputTypeName) md.writeNewLine() case *types.ObjectType: if includeHeader { @@ -612,6 +627,37 @@ func getScopeTypeLabels(scope types.ScopeType) []string { return result } +func formatBicepSourceFileKind(kind types.BicepSourceFileKind) string { + switch kind { + case types.BicepSourceFileKindBicepFile: + return "BicepFile" + case types.BicepSourceFileKindParamsFile: + return "ParamsFile" + default: + return fmt.Sprintf("Unknown(%d)", int(kind)) + } +} + +func formatNamespaceFunctionParameterFlags(flags types.NamespaceFunctionParameterFlags) string { + labels := []struct { + flag types.NamespaceFunctionParameterFlags + label string + }{ + {types.NamespaceFunctionParameterFlagsRequired, "Required"}, + {types.NamespaceFunctionParameterFlagsCompileTimeConstant, "CompileTimeConstant"}, + {types.NamespaceFunctionParameterFlagsDeployTimeConstant, "DeployTimeConstant"}, + } + + names := make([]string, 0, len(labels)) + for _, entry := range labels { + if flags&entry.flag == entry.flag { + names = append(names, entry.label) + } + } + + return strings.Join(names, ", ") +} + func formatPropertyFlags(flags types.TypePropertyFlags) string { labels := []struct { flag types.TypePropertyFlags diff --git a/src/bicep-types/src/writers/markdown.ts b/src/bicep-types/src/writers/markdown.ts index 7640fcf2..3c7d7c53 100644 --- a/src/bicep-types/src/writers/markdown.ts +++ b/src/bicep-types/src/writers/markdown.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { ArrayType, BuiltInType, DiscriminatedObjectType, getBuiltInTypeKindLabel, getObjectTypePropertyFlagsLabels, getScopeTypeLabels, ObjectTypeProperty, ObjectType, ResourceFunctionType, ResourceType, StringLiteralType, StringType, BicepType, TypeBaseKind, TypeIndex, TypeReference, UnionType, IntegerType, FunctionType, NamespaceFunctionType, TypeFile } from '../types'; +import { ArrayType, BuiltInType, DiscriminatedObjectType, getBuiltInTypeKindLabel, getNamespaceFunctionParameterFlagsLabels, getObjectTypePropertyFlagsLabels, getScopeTypeLabels, ObjectTypeProperty, ObjectType, ResourceFunctionType, ResourceType, StringLiteralType, StringType, BicepType, TypeBaseKind, TypeIndex, TypeReference, UnionType, IntegerType, FunctionType, NamespaceFunctionType, BicepSourceFileKind, TypeFile } from '../types'; import { groupBy, orderBy } from '../utils'; class MarkdownFile { @@ -222,14 +222,22 @@ export function writeMarkdown(types: BicepType[], fileHeading?: string) { const namespaceFunctionType = type as NamespaceFunctionType; md.writeHeading(nesting, `Namespace Function ${namespaceFunctionType.name}`); md.writeBullet("Description", namespaceFunctionType.description || "(none)"); + if (namespaceFunctionType.evaluatedLanguageExpression !== undefined) { + md.writeBullet("Evaluated language expression", `\`${namespaceFunctionType.evaluatedLanguageExpression}\``); + } + if (namespaceFunctionType.visibleInFileKind !== undefined) { + md.writeBullet("Visible only in bicep file kind", BicepSourceFileKind[namespaceFunctionType.visibleInFileKind]); + } if (namespaceFunctionType.parameters && namespaceFunctionType.parameters.length > 0) { md.writeHeading(nesting + 1, "Parameters"); for (let i = 0; i < namespaceFunctionType.parameters.length; i++) { const param = namespaceFunctionType.parameters[i]; - md.writeNumbered(i + 1, param.name, getTypeName(types, param.type)); + const flagsString = param.flags ? ` (${getNamespaceFunctionParameterFlagsLabels(param.flags).join(', ')})` : ''; + const descriptionString = param.description ? `: ${param.description}` : ''; + md.writeNumbered(i + 1, param.name, `${getTypeName(types, param.type)}${flagsString}${descriptionString}`); } } - md.writeBullet("Output", getTypeName(types, namespaceFunctionType.outputType)); + md.writeBullet("Output type", getTypeName(types, namespaceFunctionType.outputType)); md.writeNewLine(); return; diff --git a/src/bicep-types/test/integration/baselines/foo/foo/types.md b/src/bicep-types/test/integration/baselines/foo/foo/types.md index ce8cac22..a6b44b53 100644 --- a/src/bicep-types/test/integration/baselines/foo/foo/types.md +++ b/src/bicep-types/test/integration/baselines/foo/foo/types.md @@ -19,9 +19,11 @@ ## Namespace Function binding * **Description**: Binding function +* **Evaluated language expression**: `[externalInput('binding', parameters('bindingKey'))]` +* **Visible only in bicep file kind**: ParamsFile ### Parameters -1. **bindingKey**: string -* **Output**: any +1. **bindingKey**: string (Required): The binding key parameter +* **Output type**: any ## def ### Properties