mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-12 09:12:23 +03:00
Filter readOnly and writeOnly fields from request/response
This commit is contained in:
parent
f65dd955fa
commit
5438770267
|
@ -748,6 +748,7 @@ components:
|
||||||
Id:
|
Id:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
readOnly: true
|
||||||
Order:
|
Order:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -20,7 +20,7 @@ const renderRoot = (Component: typeof Redoc, props: { store: AppStore }) =>
|
||||||
const big = window.location.search.indexOf('big') > -1;
|
const big = window.location.search.indexOf('big') > -1;
|
||||||
const swagger = window.location.search.indexOf('swagger') > -1; //compatibility mode ?
|
const swagger = window.location.search.indexOf('swagger') > -1; //compatibility mode ?
|
||||||
|
|
||||||
const specUrl = swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'swagger.yaml';
|
const specUrl = swagger ? 'swagger.yaml' : big ? 'big-openapi.json' : 'openapi.yaml';
|
||||||
|
|
||||||
let store;
|
let store;
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ function BodyContent(props: { content: MediaContentModel }): JSX.Element {
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{({ schema }) => {
|
{({ schema }) => {
|
||||||
return <Schema key="schema" schema={schema} />;
|
return <Schema skipReadOnly={true} key="schema" schema={schema} />;
|
||||||
}}
|
}}
|
||||||
</MediaTypesSwitch>
|
</MediaTypesSwitch>
|
||||||
);
|
);
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class ResponseView extends React.Component<{ response: ResponseModel }> {
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{({ schema }) => {
|
{({ schema }) => {
|
||||||
return <Schema key="schema" schema={schema} />;
|
return <Schema skipWriteOnly={true} key="schema" schema={schema} />;
|
||||||
}}
|
}}
|
||||||
</MediaTypesSwitch>
|
</MediaTypesSwitch>
|
||||||
</ResponseDetailsWrap>
|
</ResponseDetailsWrap>
|
||||||
|
|
|
@ -62,11 +62,22 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
|
||||||
render() {
|
render() {
|
||||||
const { schema: { fields = [] }, showTitle, discriminator } = this.props;
|
const { schema: { fields = [] }, showTitle, discriminator } = this.props;
|
||||||
|
|
||||||
|
const needFilter = this.props.skipReadOnly || this.props.skipWriteOnly;
|
||||||
|
|
||||||
|
const filteredFields = needFilter
|
||||||
|
? fields.filter(item => {
|
||||||
|
return (
|
||||||
|
(this.props.skipReadOnly && !item.schema.readOnly) ||
|
||||||
|
(this.props.skipWriteOnly && !item.schema.writeOnly)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
: fields;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PropertiesTable>
|
<PropertiesTable>
|
||||||
{showTitle && <PropertiesTableCaption>{this.props.schema.title}</PropertiesTableCaption>}
|
{showTitle && <PropertiesTableCaption>{this.props.schema.title}</PropertiesTableCaption>}
|
||||||
<tbody>
|
<tbody>
|
||||||
{mapWithLast(fields, (field, isLast) =>
|
{mapWithLast(filteredFields, (field, isLast) =>
|
||||||
this.renderField(
|
this.renderField(
|
||||||
field,
|
field,
|
||||||
isLast,
|
isLast,
|
||||||
|
|
|
@ -13,6 +13,8 @@ import { ArraySchema } from './ArraySchema';
|
||||||
export interface SchemaProps {
|
export interface SchemaProps {
|
||||||
schema: SchemaModel;
|
schema: SchemaModel;
|
||||||
showTitle?: boolean;
|
showTitle?: boolean;
|
||||||
|
skipReadOnly?: boolean;
|
||||||
|
skipWriteOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
|
|
|
@ -59,6 +59,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
@ -66,6 +67,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
FieldModel {
|
FieldModel {
|
||||||
|
@ -95,6 +97,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -102,6 +105,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -123,6 +127,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"allOf": undefined,
|
"allOf": undefined,
|
||||||
"discriminator": Object {
|
"discriminator": Object {
|
||||||
|
@ -148,6 +153,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "Dog",
|
"title": "Dog",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
SchemaModel {
|
SchemaModel {
|
||||||
"_$ref": "#/components/schemas/Cat",
|
"_$ref": "#/components/schemas/Cat",
|
||||||
|
@ -187,6 +193,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -194,6 +201,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
FieldModel {
|
FieldModel {
|
||||||
|
@ -223,6 +231,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
@ -230,6 +239,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -253,6 +263,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
],
|
],
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"allOf": undefined,
|
"allOf": undefined,
|
||||||
"discriminator": Object {
|
"discriminator": Object {
|
||||||
|
@ -278,6 +289,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "Cat",
|
"title": "Cat",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"pattern": undefined,
|
"pattern": undefined,
|
||||||
|
@ -295,6 +307,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
],
|
],
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"discriminator": Object {
|
"discriminator": Object {
|
||||||
"propertyName": "type",
|
"propertyName": "type",
|
||||||
|
@ -312,6 +325,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "Pet",
|
"title": "Pet",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,6 +368,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
@ -361,6 +376,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
FieldModel {
|
FieldModel {
|
||||||
|
@ -390,6 +406,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -397,6 +414,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -418,6 +436,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
},
|
},
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"allOf": undefined,
|
"allOf": undefined,
|
||||||
"discriminator": Object {
|
"discriminator": Object {
|
||||||
|
@ -443,6 +462,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"title": "Dog",
|
"title": "Dog",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
@ -480,6 +500,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "number",
|
"type": "number",
|
||||||
|
@ -487,6 +508,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,6 +545,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
},
|
},
|
||||||
|
"readOnly": false,
|
||||||
"schema": Object {
|
"schema": Object {
|
||||||
"default": undefined,
|
"default": undefined,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -530,6 +553,7 @@ exports[`Components SchemaView discriminator should correctly render discriminat
|
||||||
"title": "",
|
"title": "",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"typePrefix": "",
|
"typePrefix": "",
|
||||||
|
"writeOnly": false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ export class SchemaModel {
|
||||||
example?: any;
|
example?: any;
|
||||||
enum: any[];
|
enum: any[];
|
||||||
default?: any;
|
default?: any;
|
||||||
|
readOnly: boolean;
|
||||||
|
writeOnly: boolean;
|
||||||
|
|
||||||
constraints: string[];
|
constraints: string[];
|
||||||
|
|
||||||
|
@ -101,6 +103,8 @@ export class SchemaModel {
|
||||||
this.displayType = this.title === '' ? this.type : `${this.title} (${this.type})`;
|
this.displayType = this.title === '' ? this.type : `${this.title} (${this.type})`;
|
||||||
this.isPrimitive = isPrimitiveType(schema);
|
this.isPrimitive = isPrimitiveType(schema);
|
||||||
this.default = schema.default;
|
this.default = schema.default;
|
||||||
|
this.readOnly = !!schema.readOnly;
|
||||||
|
this.writeOnly = !!schema.writeOnly;
|
||||||
|
|
||||||
if (this.isCircular) {
|
if (this.isCircular) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user