Skip to content

Commit

Permalink
fix bug of union type effect child type’s optional
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Jul 26, 2017
1 parent 18cb3fc commit 2a4327f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 28 deletions.
8 changes: 5 additions & 3 deletions demo/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@
"type": "string"
}
},
"required": [],
"additionalProperties": false,
"minProperties": 2
"required": [
"typeLiteralMember1",
"typeLiteralMember2"
],
"additionalProperties": false
},
"Interface": {
"type": "object",
Expand Down
14 changes: 0 additions & 14 deletions demo/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,18 @@ type MapType = {
*/
export type EntryType = {
optionalMember?: string;

booleanMember: boolean;

stringMember: string;

numberType: NumberType;

arrayType: ArrayType;

typeLiteral: { literal: number };

referenceType: TypeLiteral;

interfaceType: Interface;

typeUnion: TypeUnion;

interfaceExtends: InterfaceExtends;

typeIntersection: TypeIntersection;

typeUnionAndIntersection: TypeUnionAndIntersection;

mapType: MapType;

taggedField: TaggedField;

enum: Enum;
};
6 changes: 2 additions & 4 deletions demo/debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@
"type": {
"kind": "number",
"type": "number"
},
"optional": true
}
},
{
"name": "typeLiteralMember2",
"type": {
"kind": "string"
},
"optional": true
}
}
],
"minProperties": 2,
Expand Down
6 changes: 3 additions & 3 deletions online/file-size.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"indexBundleJs": "21.6 kB 5.88 kB",
"indexBundleJs": "21.7 kB 5.9 kB",
"vendorBundleJs": "1.87 MB 499 kB",
"indexBundleCss": "4.17 kB 1.25 kB",
"onlineIndexHtml": "4.91 kB 1.68 kB"
"indexBundleCss": "4.15 kB 1.25 kB",
"onlineIndexHtml": "4.89 kB 1.67 kB"
}
1 change: 0 additions & 1 deletion online/index.bundle-60461185a0d9fd3d3952083a1ec31515.js

This file was deleted.

1 change: 1 addition & 0 deletions online/index.bundle-a4281ab2b8320412055fed23328597e4.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions online/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.app{display:flex}.app *{box-sizing:border-box;margin:0;padding:0;font-family:"Lucida Grande","Lucida Sans Unicode","Hiragino Sans GB","WenQuanYi Micro Hei","Verdana,Aril",sans-serif;-webkit-font-smoothing:antialiased;user-select:none}.app .source{display:block;width:50%;padding:6px 12px;font-size:14px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;height:600px}.app .result{display:flex;flex-direction:column;width:50%}.app .result button{color:#333;background-color:#fff;display:inline-block;padding:3px 6px;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid #ccc;border-radius:4px;margin-left:3px}.app .result button:hover{background-color:#e6e6e6;border-color:#adadad;text-decoration:none}.app .result .options{margin-left:3px;margin-top:3px}.app .result .json-schema,.app .result .protobuf{display:block;padding:9.5px;margin:3px 0 10px 3px;font-size:13px;line-height:1.42857143;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;border-radius:4px;height:545px;overflow-y:auto}/*!
.app{display:flex}.app *{box-sizing:border-box;margin:0;padding:0;font-family:"Lucida Grande","Lucida Sans Unicode","Hiragino Sans GB","WenQuanYi Micro Hei","Verdana,Aril",sans-serif;-webkit-font-smoothing:antialiased}.app .source{display:block;width:50%;padding:6px 12px;font-size:14px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;height:600px}.app .result{display:flex;flex-direction:column;width:50%}.app .result button{color:#333;background-color:#fff;display:inline-block;padding:3px 6px;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid #ccc;border-radius:4px;margin-left:3px}.app .result button:hover{background-color:#e6e6e6;border-color:#adadad;text-decoration:none}.app .result .options{margin-left:3px;margin-top:3px}.app .result .json-schema,.app .result .protobuf{display:block;padding:9.5px;margin:3px 0 10px 3px;font-size:13px;line-height:1.42857143;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;border-radius:4px;height:545px;overflow-y:auto}/*!
* "Fork me on GitHub" CSS ribbon v0.2.0 | MIT License
* https:/simonwhitaker/github-fork-ribbon-css
*/.github-fork-ribbon{width:12.1em;height:12.1em;position:absolute;overflow:hidden;top:0;right:0;z-index:9999;pointer-events:none;font-size:13px;text-decoration:none;text-indent:-999999px}.github-fork-ribbon.fixed{position:fixed}.github-fork-ribbon:after,.github-fork-ribbon:before{position:absolute;display:block;width:15.38em;height:1.54em;top:3.23em;right:-3.23em;-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-ms-transform:rotate(45deg);-o-transform:rotate(45deg);transform:rotate(45deg)}.github-fork-ribbon:before{content:"";padding:.38em 0;background-color:#a00;background-image:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,0)),to(rgba(0,0,0,.15)));background-image:-webkit-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:-moz-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:-ms-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:-o-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:linear-gradient(to bottom,rgba(0,0,0,0),rgba(0,0,0,.15));-webkit-box-shadow:0 .15em .23em 0 rgba(0,0,0,.5);-moz-box-shadow:0 .15em .23em 0 rgba(0,0,0,.5);box-shadow:0 .15em .23em 0 rgba(0,0,0,.5);pointer-events:auto}.github-fork-ribbon:after{content:attr(title);color:#fff;font:700 1em "Helvetica Neue",Helvetica,Arial,sans-serif;line-height:1.54em;text-decoration:none;text-shadow:0 -.08em rgba(0,0,0,.5);text-align:center;text-indent:0;padding:.15em 0;margin:.15em 0;border-width:.08em 0;border-style:dotted;border-color:#fff;border-color:rgba(255,255,255,.7)}.github-fork-ribbon.left-bottom,.github-fork-ribbon.left-top{right:auto;left:0}.github-fork-ribbon.left-bottom,.github-fork-ribbon.right-bottom{top:auto;bottom:0}.github-fork-ribbon.left-bottom:after,.github-fork-ribbon.left-bottom:before,.github-fork-ribbon.left-top:after,.github-fork-ribbon.left-top:before{right:auto;left:-3.23em}.github-fork-ribbon.left-bottom:after,.github-fork-ribbon.left-bottom:before,.github-fork-ribbon.right-bottom:after,.github-fork-ribbon.right-bottom:before{top:auto;bottom:3.23em}.github-fork-ribbon.left-top:after,.github-fork-ribbon.left-top:before,.github-fork-ribbon.right-bottom:after,.github-fork-ribbon.right-bottom:before{-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg)}
</style>
<a class="github-fork-ribbon right-bottom" href="https:/plantain-00/types-as-schema" title="Fork me on GitHub" target="_blank">Fork me on GitHub</a>
<div id="container"></div>
<script src="./vendor.bundle-7dfcdb7a10557a59fcf7a9e3900a1591.js" crossOrigin="anonymous" integrity="sha256-zkkvU1ZfoCyVTLvtxVVzTweTjq/JyUw1t1JNvlUIv90="></script>
<script src="./index.bundle-60461185a0d9fd3d3952083a1ec31515.js" crossOrigin="anonymous" integrity="sha256-6NwnmW1EqfD1nidarEOAw9gc8Nhva2QSbua51TjRjM8="></script>
<script src="./index.bundle-a4281ab2b8320412055fed23328597e4.js" crossOrigin="anonymous" integrity="sha256-LUotVU19PdqRfppAoxdSfWDcESL31ua+0j+lK16XBVc="></script>
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class Generator {
if (maxProperties < childMembersInfo.maxProperties) {
maxProperties = childMembersInfo.maxProperties;
}
const childMembers = childMembersInfo.members;
const childMembers: Member[] = JSON.parse(JSON.stringify(childMembersInfo.members));
if (members.length === 0) {
members.push(...childMembers);
} else {
Expand Down

0 comments on commit 2a4327f

Please sign in to comment.