Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ece21ae

Browse files
committed
refactor(api): enable no-unsafe-declaration-merging and fix errors
- Declare all fields in the classes - Remove redundant interfaces - Make classes implements their options interface - Reorder fields as the fields order is not dependent of insertion order anymore - Reorder fields in test openapi3 test https://typescript-eslint.io/rules/no-unsafe-declaration-merging/ Signed-off-by: J3m5 <5523410+J3m5@users.noreply.github.com>
1 parent b2d860f commit ece21ae

File tree

8 files changed

+88
-30
lines changed

8 files changed

+88
-30
lines changed

‎.oxlintrc.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
],
3232
"@typescript-eslint/no-explicit-any": "off",
33-
"@typescript-eslint/no-unsafe-declaration-merging": "off",
33+
"@typescript-eslint/no-unsafe-declaration-merging": "error",
3434
"eslint/arrow-body-style": ["error", "as-needed"],
3535
"eslint/curly": "error",
3636
"eslint/id-length": "off",

‎src/core/Api.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ export interface ApiOptions
88
resources?: Resource[];
99
}> {}
1010

11-
export interface Api extends ApiOptions {}
12-
export class Api {
11+
export class Api implements ApiOptions {
1312
entrypoint: string;
13+
14+
title?: string | null;
15+
resources?: Resource[] | null;
16+
1417
constructor(entrypoint: string, options: ApiOptions = {}) {
1518
this.entrypoint = entrypoint;
1619
assignSealed(this, options);

‎src/core/Field.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,29 @@ export interface FieldOptions
4040
enum?: { [key: string | number]: string | number };
4141
reference?: string | Resource;
4242
embedded?: Resource;
43-
required?: boolean;
4443
nullable?: boolean;
44+
required?: boolean;
4545
description?: string;
4646
maxCardinality?: number;
4747
deprecated?: boolean;
4848
}> {}
4949

50-
export interface Field extends FieldOptions {}
51-
export class Field {
50+
export class Field implements FieldOptions {
5251
name: string;
52+
53+
id?: string | null;
54+
range?: string | null;
55+
type?: FieldType | null;
56+
arrayType?: FieldType | null;
57+
enum?: { [key: string | number]: string | number } | null;
58+
reference?: string | Resource | null;
59+
embedded?: Resource | null;
60+
nullable?: boolean | null;
61+
required?: boolean | null;
62+
description?: string | null;
63+
maxCardinality?: number | null;
64+
deprecated?: boolean | null;
65+
5366
constructor(name: string, options: FieldOptions = {}) {
5467
this.name = name;
5568
assignSealed(this, options);

‎src/core/Operation.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ export interface OperationOptions
1212
deprecated?: boolean;
1313
}> {}
1414

15-
export interface Operation extends OperationOptions {}
16-
export class Operation {
15+
export class Operation implements OperationOptions {
1716
name: string;
1817
type: OperationType;
18+
method?: string | null;
19+
expects?: any | null;
20+
returns?: string | null;
21+
types?: string[] | null;
22+
deprecated?: boolean | null;
23+
1924
constructor(
2025
name: string,
2126
type: OperationType,

‎src/core/Parameter.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
export class Parameter {
1+
export interface ParameterOptions {
2+
variable: string;
3+
range: string | null;
4+
required: boolean;
5+
description: string;
6+
deprecated?: boolean | undefined;
7+
}
8+
9+
export class Parameter implements ParameterOptions {
210
variable: string;
311
range: string | null;
412
required: boolean;

‎src/core/Resource.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,29 @@ export interface ResourceOptions
99
id?: string;
1010
title?: string;
1111
description?: string;
12-
deprecated?: boolean;
1312
fields?: Field[];
1413
readableFields?: Field[];
1514
writableFields?: Field[];
16-
parameters?: Parameter[];
1715
getParameters?: () => Promise<Parameter[]>;
1816
operations?: Operation[];
17+
deprecated?: boolean;
18+
parameters?: Parameter[];
1919
}> {}
2020

21-
export interface Resource extends ResourceOptions {}
22-
export class Resource {
21+
export class Resource implements ResourceOptions {
2322
name: string;
2423
url: string;
24+
id?: string | null;
25+
title?: string | null;
26+
description?: string | null;
27+
fields?: Field[] | null;
28+
readableFields?: Field[] | null;
29+
writableFields?: Field[] | null;
30+
getParameters?: (() => Promise<Parameter[]>) | null;
31+
operations?: Operation[] | null;
32+
deprecated?: boolean | null;
33+
parameters?: Parameter[] | null;
34+
2535
constructor(name: string, url: string, options: ResourceOptions = {}) {
2636
this.name = name;
2737
this.url = url;

‎src/hydra/types.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ interface JsonLdType {
2323
"@type"?: Iri | Iri[];
2424
}
2525

26+
/**
27+
* A generic expanded JSON‐LD node.
28+
* • Keys are IRIs.
29+
* • Each predicate maps to an *array* of nodes or literal values.
30+
*
31+
* You can extend this interface with concrete predicates later.
32+
*/
33+
export interface JsonLdNode extends JsonLdId, JsonLdType {
34+
[predicate: Iri]:
35+
| JsonLdNode[] // linked nodes
36+
| JsonLdValue[] // literals
37+
| JsonLdId[] // references
38+
| Iri // e.g. "@id"
39+
| Iri[] // e.g. "@type"
40+
| undefined; // property may be absent
41+
}
42+
2643
export interface ExpandedOperation {
2744
"@type": ["http://www.w3.org/ns/hydra/core#Operation"];
2845
"http://www.w3.org/2000/01/rdf-schema#label": [JsonLdValue<string>];
@@ -73,7 +90,7 @@ interface ExpandedSupportedProperty {
7390
"http://www.w3.org/2002/07/owl#deprecated"?: [JsonLdValue<boolean>];
7491
}
7592

76-
export interface ExpandedClass extendsJsonLdNode{
93+
export interface ExpandedClass {
7794
"@id": string;
7895
"@type": ["http://www.w3.org/ns/hydra/core#Class"];
7996
"http://www.w3.org/2000/01/rdf-schema#label"?: [JsonLdValue<string>];

‎src/openapi3/handleJson.test.ts‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,7 @@ const parsed = [
994994
description: "",
995995
},
996996
],
997-
parameters: [
998-
{
999-
variable: "page",
1000-
range: "integer",
1001-
required: false,
1002-
description: "The collection page number",
1003-
},
1004-
],
997+
1005998
operations: [
1006999
{
10071000
name: "Retrieves a Book resource.",
@@ -1034,6 +1027,14 @@ const parsed = [
10341027
deprecated: false,
10351028
},
10361029
],
1030+
parameters: [
1031+
{
1032+
variable: "page",
1033+
range: "integer",
1034+
required: false,
1035+
description: "The collection page number",
1036+
},
1037+
],
10371038
},
10381039
{
10391040
name: "reviews",
@@ -1277,14 +1278,7 @@ const parsed = [
12771278
description: "",
12781279
},
12791280
],
1280-
parameters: [
1281-
{
1282-
variable: "page",
1283-
range: "integer",
1284-
required: false,
1285-
description: "The collection page number",
1286-
},
1287-
],
1281+
12881282
operations: [
12891283
{
12901284
name: "Retrieves a Review resource.",
@@ -1317,6 +1311,14 @@ const parsed = [
13171311
deprecated: false,
13181312
},
13191313
],
1314+
parameters: [
1315+
{
1316+
variable: "page",
1317+
range: "integer",
1318+
required: false,
1319+
description: "The collection page number",
1320+
},
1321+
],
13201322
},
13211323
];
13221324

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /