Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Bicep.Types/Serialization/TypeJsonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
50 changes: 48 additions & 2 deletions src/bicep-types-go/writers/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,37 @@ 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 {
paramTypeName, err := getTypeName(md, typesList, param.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)
}
}

outputTypeName, err := getTypeName(md, typesList, concrete.OutputType)
if err != nil {
return err
}
md.writeBullet("Output", outputTypeName)
md.writeBullet("Output type", outputTypeName)
md.writeNewLine()
case *types.ObjectType:
if includeHeader {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/bicep-types/src/writers/markdown.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/bicep-types/test/integration/baselines/foo/foo/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading