Skip to content

Commit

Permalink
fix: static definitions key used
Browse files Browse the repository at this point in the history
  • Loading branch information
elyukai committed Jun 30, 2022
1 parent da50e1c commit 978a5d2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/renderers/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type Definition =
| Tuple
| Group

export interface JsonSchema extends Annotated {
export interface JsonSchema_07 extends Annotated {
$schema: string
$id: string
$ref?: string
Expand All @@ -140,6 +140,15 @@ export interface JsonSchema extends Annotated {
}
}

export interface JsonSchema_2019_09 extends Annotated {
$schema: string
$id: string
$ref?: string
$defs: {
[id: string]: Definition
}
}

const toAnnotations = (jsDoc: JSDoc.T | undefined) => ({
title: jsDoc?.tags.title,
description: jsDoc?.comment,
Expand Down Expand Up @@ -278,7 +287,7 @@ const nodeToDefinition = (spec: Spec, node: ChildNode): Definition => {

return {
...toAnnotations(node.jsDoc),
$ref: `${externalFilePath}#/definitions/${qualifiedName}`
$ref: `${externalFilePath}#/${defsKey(spec)}/${qualifiedName}`
}
}
case NodeKind.Token: {
Expand Down Expand Up @@ -323,7 +332,7 @@ const astToJsonSchema = ({ spec }: TransformerOptions): AstTransformer =>
const jsonSchema = {
$schema: schemaUri(spec),
$id: toForwardSlashAbsolutePath(relativePath),
$ref: mainType ? `#/definitions/${mainType}` : mainType,
$ref: mainType ? `#/${defsKey(spec)}/${mainType}` : mainType,
[defsKey(spec)]: Object.fromEntries(
Object.entries(file.elements)
.map(([key, node]) => [key, nodeToDefinition(spec, node)])
Expand Down

0 comments on commit 978a5d2

Please sign in to comment.