Skip to content

Commit

Permalink
feat: minProperties for strict objects
Browse files Browse the repository at this point in the history
  • Loading branch information
elyukai committed Feb 17, 2022
1 parent f54512d commit f632217
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ interface Annotated {
description?: string
}

interface ObjectBase extends Annotated {
interface ObjectConstraints {
minProperties?: number
}

interface ObjectBase extends ObjectConstraints, Annotated {
type: "object"
}

Expand All @@ -20,18 +24,14 @@ interface StrictObject extends ObjectBase {
additionalProperties: false
}

interface DictionaryConstraints {
minProperties?: number
}

interface PatternDictionary extends DictionaryConstraints, ObjectBase {
interface PatternDictionary extends ObjectBase {
patternProperties: {
[pattern: string]: Definition
}
additionalProperties: false
}

interface Dictionary extends DictionaryConstraints, ObjectBase {
interface Dictionary extends ObjectBase {
additionalProperties: Definition
}

Expand Down Expand Up @@ -132,7 +132,7 @@ const toAnnotations = (jsDoc: JSDoc.Type | undefined) => ({
type ConstraintsByType = {
number: NumberConstraints,
string: StringConstraints,
object: DictionaryConstraints,
object: ObjectConstraints,
array: ArrayConstraints,
}

Expand Down Expand Up @@ -177,6 +177,7 @@ const nodeToDefinition = (node: ChildNode): Definition => {
required: Object.entries(node.elements)
.filter(([_, config]) => config.required)
.map(([key]) => key),
...toConstraints(node.jsDoc, "object"),
additionalProperties: false
}
}
Expand Down
1 change: 1 addition & 0 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ const strictObjectBody = (
return [
LabelledList.create([
LabelledList.line("Type", "Object"),
LabelledList.line("Minimum Properties", node.jsDoc?.tags.minProperties, icode),
]),
`Key | Description | Details\n:-- | :-- | :--\n${propertiesOverview}`,
...properties
Expand Down

0 comments on commit f632217

Please sign in to comment.