Skip to content

Commit

Permalink
fix: nested items with refs (#2035)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed Jun 1, 2022
1 parent a366de4 commit 51127aa
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/SecurityRequirement/OAuthFlow.tsx
Expand Up @@ -13,7 +13,7 @@ export interface OAuthFlowProps {
export function OAuthFlowComponent(props: OAuthFlowProps) {
const { type, flow, RequiredScopes } = props;
const scopesNames = Object.keys(flow?.scopes || {});
console.log('rended');

return (
<>
<SecurityRow>
Expand Down
Expand Up @@ -207,6 +207,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -465,6 +474,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -698,6 +716,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -998,6 +1025,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -1256,6 +1292,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -1489,6 +1534,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -1745,6 +1799,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -2042,6 +2105,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -2300,6 +2372,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down Expand Up @@ -2533,6 +2614,15 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
},
"rightPanel": Object {
"backgroundColor": "#263238",
"servers": Object {
"overlay": Object {
"backgroundColor": "#fafafa",
"textColor": "#263238",
},
"url": Object {
"backgroundColor": "#fff",
},
},
"textColor": "#ffffff",
"width": "40%",
},
Expand Down
30 changes: 30 additions & 0 deletions src/services/__tests__/fixtures/3.1/prefixItems.json
Expand Up @@ -133,6 +133,13 @@
]
}
},
"Case6": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/components/schemas/Tag"
}
},
"Cat": {
"type": "object",
"properties": {
Expand All @@ -148,6 +155,29 @@
"type": "string"
}
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"description": "Tag ID",
"allOf": [
{
"$ref": "#/components/schemas/Id"
}
]
},
"name": {
"description": "tag name",
"type": "string",
"minLength": 1
}
}
},
"Id": {
"type": "integer",
"format": "int64",
"readOnly": true
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/services/__tests__/fixtures/arrayItems.json
Expand Up @@ -133,6 +133,13 @@
]
}
},
"Case6": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/components/schemas/Tag"
}
},
"Cat": {
"type": "object",
"properties": {
Expand All @@ -148,6 +155,29 @@
"type": "string"
}
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"description": "Tag ID",
"allOf": [
{
"$ref": "#/components/schemas/Id"
}
]
},
"name": {
"description": "tag name",
"type": "string",
"minLength": 1
}
}
},
"Id": {
"type": "integer",
"format": "int64",
"readOnly": true
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/services/__tests__/models/Schema.test.ts
Expand Up @@ -212,6 +212,22 @@ describe('Models', () => {
]);
},
);

test.each(eachArray)(
'schemaDefinition should resolve prefixItems with additional array items',
specFixture => {
const spec = require(specFixture);
const parser = new OpenAPIParser(spec, undefined, opts);
const schema = new SchemaModel(parser, spec.components.schemas.Case6, '', opts);
expect(schema.type).toBe('array');
expect(schema.typePrefix).toBe('Array of ');
expect(schema.items?.fields).toHaveLength(2);
expect(schema.items?.pointer).toEqual('#/components/schemas/Tag');
expect(schema.isPrimitive).toBe(false);
expect(schema.items?.isPrimitive).toBe(false);
expect(schema.minItems).toBe(1);
},
);
});
});
});
3 changes: 2 additions & 1 deletion src/services/models/Schema.ts
Expand Up @@ -209,7 +209,8 @@ export class SchemaModel {
this.displayFormat = this.items?.format || '';
this.typePrefix = this.items?.typePrefix || '' + l('arrayOf');
this.title = this.title || this.items?.title || '';
this.isPrimitive = this.items?.isPrimitive || this.isPrimitive;
this.isPrimitive =
this.items?.isPrimitive !== undefined ? this.items?.isPrimitive : this.isPrimitive;

if (this.example === undefined && this.items?.example !== undefined) {
this.example = [this.items.example];
Expand Down

0 comments on commit 51127aa

Please sign in to comment.