Skip to content

Commit

Permalink
当 allOf/oneOf/anyOf 与 properties 同时存在时会生成错误的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Val-istar-Guo committed Dec 3, 2024
1 parent 59bd217 commit 373276f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-crews-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opendoc/sdk": patch
---

当 allOf/oneOf/anyOf 与 properties 同时存在时会生成错误的代码
6 changes: 4 additions & 2 deletions pkg/sdk/src/templates/json-schema/interface.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{~#if (h__or jsonSchema.nullable (r__not (h__or (r__equals jsonSchema.type "object") (r__isObject jsonSchema.properties) jsonSchema.additionalProperties))) }}
{{~#if (h__or jsonSchema.nullable jsonSchema.allOf jsonSchema.oneOf jsonSchema.anyOf jsonSchema.$ref jsonSchema.enum jsonSchema.const (r__includes jsonSchema.type (r__Array "string" "number" "boolean" "integer" "array")))}}
{{#if export}}export {{/if}}type {{name}} = {{> t_json_schema_shape jsonSchema}}
{{else}}
{{else if (h__or (r__equals jsonSchema.type "object") (r__isObject jsonSchema.properties) jsonSchema.additionalProperties)}}
{{!-- only pure object --}}
{{#if export}}export {{/if}}interface {{name}} {{> t_json_schema_shape jsonSchema}}
{{else}}
{{#if export}}export {{/if}}type {{name}} = {{> t_json_schema_shape jsonSchema}}
{{/if}}
16 changes: 8 additions & 8 deletions pkg/sdk/src/templates/json-schema/shape.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
{{~else if (r__isArray allOf)~}}
{{> t_json_schema_shape__all_of}}

{{~else if (h__or (r__equals type "object") (r__isObject properties) additionalProperties)~}}
{
{{> t_json_schema_shape__object}}
}

{{~else if (r__equals type "array")~}}
{{> t_json_schema_shape__array}}

{{~else if (r__equals type "number")~}}
number

Expand All @@ -36,6 +28,14 @@ string
{{~else if (r__equals type "boolean")~}}
boolean

{{~else if (r__equals type "array")~}}
{{> t_json_schema_shape__array}}

{{~else if (h__or (r__equals type "object") (r__isObject properties) additionalProperties)~}}
{
{{> t_json_schema_shape__object}}
}

{{~else~}}
any

Expand Down

0 comments on commit 373276f

Please sign in to comment.