Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit b148b63

Browse files
Gabriel RaniereGabriel Raniere
Gabriel Raniere
authored and
Gabriel Raniere
committed
fix readOnly
1 parent ae74adf commit b148b63

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

src/components.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from 'openapi3-ts';
2222
import {
2323
AcessorNode,
24+
OperationType,
2425
} from './components/openapi/util';
2526
import {
2627
LocationSegments,
@@ -111,6 +112,7 @@ export namespace Components {
111112
interface DocsOpenapiExample {
112113
'indents': number;
113114
'node'?: AcessorNode;
115+
'operation': OperationType;
114116
'path': string;
115117
'spec': OpenAPIObject;
116118
}
@@ -124,6 +126,8 @@ export namespace Components {
124126
}
125127
interface DocsOpenapiSchemaNested {
126128
'canClose': boolean;
129+
'hideReadOnly': boolean;
130+
'hideWriteOnly': boolean;
127131
'node': AcessorNode;
128132
'open': boolean;
129133
'path': string;
@@ -541,6 +545,7 @@ declare namespace LocalJSX {
541545
interface DocsOpenapiExample {
542546
'indents'?: number;
543547
'node'?: AcessorNode;
548+
'operation'?: OperationType;
544549
'path'?: string;
545550
'spec'?: OpenAPIObject;
546551
}
@@ -554,6 +559,8 @@ declare namespace LocalJSX {
554559
}
555560
interface DocsOpenapiSchemaNested {
556561
'canClose'?: boolean;
562+
'hideReadOnly'?: boolean;
563+
'hideWriteOnly'?: boolean;
557564
'node'?: AcessorNode;
558565
'open'?: boolean;
559566
'path'?: string;

src/components/openapi/example.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Prop, h } from "@stencil/core";
22
import { OpenAPIObject } from "openapi3-ts";
3-
import { generateExample, getRefPath, AcessorNode } from "./util";
3+
import { generateExample, getRefPath, AcessorNode, OperationType } from "./util";
44

55
@Component({
66
tag: 'docs-openapi-example',
@@ -10,6 +10,7 @@ export class DocsOpenapiExample {
1010
@Prop() path: string
1111
@Prop() node?: AcessorNode
1212
@Prop() indents: number = 2
13+
@Prop() operation: OperationType
1314

1415
private getRootAcessorNode(): AcessorNode {
1516
if (this.node) {
@@ -28,7 +29,7 @@ export class DocsOpenapiExample {
2829

2930

3031
render() {
31-
let example = generateExample(this.spec, this.getRootAcessorNode())
32+
let example = generateExample(this.spec, this.getRootAcessorNode(), this.operation)
3233
if (!example) return
3334

3435
let json = JSON.stringify(example, null, this.indents)

src/components/openapi/schema-nested.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export class DocsOpenapiSchemaNested {
1616

1717
@Prop() open: boolean = false
1818
@Prop() canClose: boolean = true
19+
@Prop() hideReadOnly: boolean = false
20+
@Prop() hideWriteOnly: boolean = false
1921
@State() isOpen: boolean = false
2022

2123
private getRootAcessorNode(): AcessorNode {
@@ -79,7 +81,7 @@ export class DocsOpenapiSchemaNested {
7981
<span class="text">{text}</span>
8082
</button>
8183
{this.isOpen ?
82-
<docs-openapi-schema node={node} spec={this.spec}/> :
84+
<docs-openapi-schema node={node} spec={this.spec} hideReadOnly={this.hideReadOnly}/> :
8385
null}
8486
</section>
8587
)

src/components/openapi/util.ts

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export function normalizeObject(spec: OpenAPIObject, obj: SchemaObject): SchemaO
8989
return result
9090
}, {})
9191
}
92-
// console.log(out, 'cheguei aqui')
9392
if(out.anyOf){
9493
console.log(out, 'anyOf')
9594
}

src/components/page/templates/api-route.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { toHypertext } from "../to-hypertext";
33

44
import ApiServices from "../../../data/api-services.json";
55
import { OpenAPIObject } from "openapi3-ts";
6-
import { normalizeObject } from "../../openapi/util";
6+
import { normalizeObject, OperationType } from "../../openapi/util";
77

88
export default (props) => {
99
const { page } = props;
@@ -29,6 +29,7 @@ export default (props) => {
2929
service,
3030
PathSpec?.requestBody?.content?.["application/json"]?.schema
3131
),
32+
operation: "WRITE" as OperationType
3233
};
3334

3435
const response = {
@@ -37,6 +38,7 @@ export default (props) => {
3738
service,
3839
PathSpec?.responses?.["200"]?.content?.["application/json"]?.schema
3940
),
41+
operation: "READ" as OperationType
4042
};
4143

4244
console.log(page)
@@ -63,6 +65,7 @@ export default (props) => {
6365
text={requestBody.name}
6466
open={true}
6567
canClose={false}
68+
hideReadOnly = {true}
6669
/>
6770
)}
6871
</section>
@@ -71,7 +74,13 @@ export default (props) => {
7174
<h2 id="example">
7275
<a href="#example">Exemplo</a>
7376
</h2>
74-
{toHypertext(h, page.requestExample)}
77+
{Object.keys(requestBody.schema).length > 0 && (
78+
<docs-openapi-example
79+
spec={service.spec}
80+
node={requestBody}
81+
operation={requestBody.operation}
82+
/>
83+
)}
7584
</section>
7685
</section>
7786
: null}
@@ -98,7 +107,14 @@ export default (props) => {
98107
<h2 id="example">
99108
<a href="#example">Exemplo</a>
100109
</h2>
101-
{toHypertext(h, page.responseExample)}
110+
{Object.keys(response.schema).length > 0 && (
111+
<docs-openapi-example
112+
spec={service.spec}
113+
node={response}
114+
operation={response.operation}
115+
/>
116+
)}
117+
{/* {toHypertext(h, page.responseExample)} */}
102118
</section>
103119
</section>
104120
: null}

0 commit comments

Comments
 (0)