Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Any Object and Any distinction #4067

Merged
merged 6 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
timotheeguerin committed Apr 14, 2021
commit fc733d4244c057b844eb6f694c357ba77c778ff8
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@
],
"allOf": [
{
"$ref": "#/definitions/AnySchema"
"$ref": "#/definitions/Schema"
}
]
},
Expand Down Expand Up @@ -1899,6 +1899,12 @@
"items": {
"$ref": "#/definitions/AnySchema"
}
},
"anyObjects": {
"type": "array",
"items": {
"$ref": "#/definitions/AnyObjectSchema"
}
}
},
"defaultProperties": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ definitions:
type: object
additionalProperties: false
allOf:
- $ref: '#/definitions/AnySchema'
- $ref: '#/definitions/Schema'
required:
- language
- protocol
Expand Down Expand Up @@ -1662,6 +1662,10 @@ definitions:
type: array
items:
$ref: '#/definitions/AnySchema'
anyObjects:
type: array
items:
$ref: '#/definitions/AnyObjectSchema'
arrays:
type: array
description: a collection of items
Expand Down
8 changes: 7 additions & 1 deletion packages/libs/codemodel/.resources/model/json/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@
],
"allOf": [
{
"$ref": "./schemas.json#/definitions/AnySchema"
"$ref": "./schemas.json#/definitions/Schema"
}
]
},
Expand Down Expand Up @@ -1030,6 +1030,12 @@
"items": {
"$ref": "./schemas.json#/definitions/AnySchema"
}
},
"anyObjects": {
"type": "array",
"items": {
"$ref": "./schemas.json#/definitions/AnyObjectSchema"
}
}
},
"defaultProperties": [],
Expand Down
6 changes: 5 additions & 1 deletion packages/libs/codemodel/.resources/model/yaml/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ definitions:
type: object
additionalProperties: false
allOf:
- $ref: ./schemas.yaml#/definitions/AnySchema
- $ref: ./schemas.yaml#/definitions/Schema
required:
- language
- protocol
Expand Down Expand Up @@ -499,6 +499,10 @@ definitions:
type: array
items:
$ref: ./schemas.yaml#/definitions/AnySchema
anyObjects:
type: array
items:
$ref: ./schemas.yaml#/definitions/AnyObjectSchema
arrays:
type: array
description: a collection of items
Expand Down
15 changes: 12 additions & 3 deletions packages/libs/codemodel/src/model/common/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ConstantSchema } from "./schemas/constant";
import { OrSchema, XorSchema } from "./schemas/relationship";
import { BinarySchema } from "./schemas/binary";
import { finished } from "stream";
import { AnySchema } from "./schemas/any";
import { AnyObjectSchema, AnySchema } from "./schemas/any";

export { SchemaUsage, SchemaContext } from "./schemas/usage";

Expand Down Expand Up @@ -119,15 +119,24 @@ export interface Schemas {
groups?: Array<GroupSchema>;

any?: Array<AnySchema>;

anyObjects?: AnyObjectSchema[];
}

export class Schemas {
add<T extends Schema>(schema: T): T {
if (schema instanceof AnySchema) {
if (!(this.any && this.any[0])) {
if (!this.any?.[0]) {
this.any = [schema];
}
return <T>this.any[0];
return this.any[0] as T;
}

if (schema instanceof AnyObjectSchema) {
if (!this.anyObjects?.[0]) {
this.anyObjects = [schema];
}
return this.anyObjects[0] as T;
}

let group = `${camelCase(schema.type)}s`.replace(/rys$/g, "ries");
Expand Down
2 changes: 1 addition & 1 deletion packages/libs/codemodel/src/model/common/schemas/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class AnySchema extends Schema implements AnySchema {
}
}

export interface AnyObjectSchema extends AnySchema {
export interface AnyObjectSchema extends Schema {
type: SchemaType.AnyObject;
}

Expand Down