Skip to content

Commit

Permalink
Avoid emitting empty string descriptions (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin authored Apr 11, 2024
1 parent 0203647 commit ea19b3f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
12 changes: 0 additions & 12 deletions src/autorest.bicep/package-lock.json

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

10 changes: 4 additions & 6 deletions src/autorest.bicep/src/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { chain, Dictionary, escapeRegExp, keys, orderBy, uniq } from 'lodash';
import { getFullyQualifiedType, getNameSchema, getSerializedName, NameSchema, ProviderDefinition, ResourceDefinition, ResourceDescriptor } from "./resources";
import { isEmpty } from 'lodash';
import { ScopeType } from "bicep-types";
import { AnyObjectSchema, AnySchema, ArraySchema, ByteArraySchema, ChoiceSchema, ComplexSchema, ConstantSchema, DateTimeSchema, DictionarySchema, NumberSchema, ObjectSchema, PrimitiveSchema, Property, Schema, SchemaType, SealedChoiceSchema, StringSchema, UuidSchema } from '@autorest/codemodel';
import { AnyObjectSchema, AnySchema, ArraySchema, ByteArraySchema, ChoiceSchema, ComplexSchema, ConstantSchema, DateTimeSchema, DictionarySchema, Metadata, NumberSchema, ObjectSchema, PrimitiveSchema, Property, Schema, SchemaType, SealedChoiceSchema, StringSchema, UuidSchema } from '@autorest/codemodel';
import { failure, success } from './utils';

interface SchemaData {
Expand Down Expand Up @@ -120,14 +120,12 @@ export function generateSchema(host: AutorestExtensionHost, definition: Provider
}
}

function getTypeDescription(schema: Schema | undefined) {
function getDescription(schema: Metadata | undefined) {
return schema?.language.default.description || undefined;
}

function getPropertyDescription(putProperty: Property | undefined) {
const propertyDescription = putProperty?.language.default.description;

return propertyDescription ?? getTypeDescription(putProperty?.schema);
return getDescription(putProperty) ?? getDescription(putProperty?.schema);
}

function flattenDiscriminatorSubTypes(schema: ObjectSchema | undefined) {
Expand Down Expand Up @@ -505,7 +503,7 @@ export function generateSchema(host: AutorestExtensionHost, definition: Provider
const additionalProperties = putParentDictionary ? parseType(putParentDictionary?.elementType, true) : undefined;

const definition = createObject({}, additionalProperties);
definition.description = getTypeDescription(putSchema);
definition.description = getDescription(putSchema);
if (!ancestorsToExclude) {
// cache the definition so that it can be re-used
schemaData.definitions[definitionName] = definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"type": "string"
},
"properties": {
"description": "",
"oneOf": [
{
"$ref": "#/definitions/TestType1Properties"
Expand Down Expand Up @@ -254,7 +253,6 @@
"type": "string"
},
"properties": {
"description": "",
"oneOf": [
{
"$ref": "#/definitions/TestType1Properties"
Expand Down Expand Up @@ -385,7 +383,6 @@
]
},
"password": {
"description": "",
"oneOf": [
{
"pattern": "^[a-zA-Z0-9\\.]$",
Expand Down Expand Up @@ -429,7 +426,6 @@
]
},
"uuidProperty": {
"description": "",
"oneOf": [
{
"pattern": "^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$",
Expand All @@ -446,16 +442,13 @@
"TestType1Properties": {
"properties": {
"base64EncodedBytes": {
"description": "",
"type": "string"
},
"basicString": {
"description": "Description for a basic string property.",
"type": "string"
},
"binaryBuffer": {
"description": ""
},
"binaryBuffer": {},
"encryptionProperties": {
"description": "TestType1 encryption properties",
"oneOf": [
Expand All @@ -479,7 +472,6 @@
]
},
"password": {
"description": "",
"oneOf": [
{
"pattern": "^[a-zA-Z0-9\\.]$",
Expand All @@ -491,7 +483,6 @@
]
},
"percentageProperty": {
"description": "",
"oneOf": [
{
"maximum": 100,
Expand Down Expand Up @@ -540,7 +531,6 @@
"type": "string"
},
"uuidProperty": {
"description": "",
"oneOf": [
{
"pattern": "^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$",
Expand Down

0 comments on commit ea19b3f

Please sign in to comment.