Skip to content

Commit

Permalink
Rename prefixKeysWithX to prefixObjectKeysWithX
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Jul 12, 2024
1 parent 98926e5 commit 2a6ada5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/nextlove/src/generators/generate-openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { embedSchemaReferences } from "./embed-schema-references"
import { mapMethodsToFernSdkMetadata } from "./fern-sdk-utils"
import { parseFrontMatter, testFrontMatter } from "../lib/front-matter"
import dedent from "dedent"
import { prefixKeysWithX } from "../utils/prefix-keys-with-x"
import { prefixObjectKeysWithX } from "../utils/prefix-object-keys-with-x"
import { dashifyObjectKeys } from "../utils/dashify-object-keys"

function replaceFirstCharToLowercase(str: string) {
Expand Down Expand Up @@ -212,7 +212,7 @@ export async function generateOpenAPI(opts: GenerateOpenAPIOpts) {
}
}

const formattedDescriptionMetadata = prefixKeysWithX(
const formattedDescriptionMetadata = prefixObjectKeysWithX(
dashifyObjectKeys(descriptionMetadata)
)

Expand Down
12 changes: 6 additions & 6 deletions packages/nextlove/src/generators/lib/zod-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import merge from "ts-deepmerge"
import { AnyZodObject, z, ZodTypeAny } from "zod"
import { parseFrontMatter, testFrontMatter } from "./front-matter"
import dedent from "dedent"
import { prefixKeysWithX } from "../utils/prefix-keys-with-x"
import { prefixObjectKeysWithX } from "../utils/prefix-object-keys-with-x"
import { dashifyObjectKeys } from "../utils/dashify-object-keys"

type AnatineSchemaObject = SchemaObject & { hideDefinitions?: string[] }
Expand Down Expand Up @@ -90,11 +90,11 @@ function parseDescription(zodRef: OpenApiZodAny): SchemaObject {
output.deprecated = true
}

Object.entries(prefixKeysWithX(dashifyObjectKeys(attributes))).forEach(
([key, value]) => {
output[key] = value
}
)
Object.entries(
prefixObjectKeysWithX(dashifyObjectKeys(attributes))
).forEach(([key, value]) => {
output[key] = value
})
}

return output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ type PrefixedObject<T> = {
[K in keyof T as `x-${string & K}`]: T[K]
}

export function prefixKeysWithX<T extends object>(obj: T): PrefixedObject<T> {
export function prefixObjectKeysWithX<T extends object>(
obj: T
): PrefixedObject<T> {
return Object.fromEntries(
Object.entries(obj).map(([key, value]) => [`x-${key}`, value])
) as PrefixedObject<T>
Expand Down

0 comments on commit 2a6ada5

Please sign in to comment.