Skip to content

Commit ff997e7

Browse files
thomassnielsenymc9
andauthored
Mark openapi attributes as required for reads (#1772)
Co-authored-by: ymc9 <[email protected]>
1 parent 383b8fe commit ff997e7

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

packages/plugins/openapi/src/rest-generator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
874874
!(isDataModel(field.$resolvedType?.decl) && field.type.array)
875875
) {
876876
required.push(field.name);
877+
} else if (mode === 'read') {
878+
// Until we support sparse fieldsets, all fields are required for read operations
879+
required.push(field.name);
877880
}
878881
}
879882
}

packages/plugins/openapi/tests/baseline/rest-3.0.0.baseline.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,11 @@ components:
25912591
type: string
25922592
role:
25932593
$ref: '#/components/schemas/role'
2594+
required:
2595+
- createdAt
2596+
- updatedAt
2597+
- email
2598+
- role
25942599
relationships:
25952600
type: object
25962601
properties:
@@ -2761,6 +2766,9 @@ components:
27612766
nullable: true
27622767
userId:
27632768
type: string
2769+
required:
2770+
- image
2771+
- userId
27642772
relationships:
27652773
type: object
27662774
properties:
@@ -2919,6 +2927,14 @@ components:
29192927
notes:
29202928
type: string
29212929
nullable: true
2930+
required:
2931+
- createdAt
2932+
- updatedAt
2933+
- title
2934+
- authorId
2935+
- published
2936+
- viewCount
2937+
- notes
29222938
relationships:
29232939
type: object
29242940
properties:
@@ -3099,6 +3115,9 @@ components:
30993115
type: string
31003116
userId:
31013117
type: string
3118+
required:
3119+
- postId
3120+
- userId
31023121
relationships:
31033122
type: object
31043123
properties:

packages/plugins/openapi/tests/baseline/rest-3.1.0.baseline.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,6 +2596,11 @@ components:
25962596
type: string
25972597
role:
25982598
$ref: '#/components/schemas/role'
2599+
required:
2600+
- createdAt
2601+
- updatedAt
2602+
- email
2603+
- role
25992604
relationships:
26002605
type: object
26012606
properties:
@@ -2767,6 +2772,9 @@ components:
27672772
- type: string
27682773
userId:
27692774
type: string
2775+
required:
2776+
- image
2777+
- userId
27702778
relationships:
27712779
type: object
27722780
properties:
@@ -2929,6 +2937,14 @@ components:
29292937
oneOf:
29302938
- type: 'null'
29312939
- type: string
2940+
required:
2941+
- createdAt
2942+
- updatedAt
2943+
- title
2944+
- authorId
2945+
- published
2946+
- viewCount
2947+
- notes
29322948
relationships:
29332949
type: object
29342950
properties:
@@ -3113,6 +3129,9 @@ components:
31133129
type: string
31143130
userId:
31153131
type: string
3132+
required:
3133+
- postId
3134+
- userId
31163135
relationships:
31173136
type: object
31183137
properties:

0 commit comments

Comments
 (0)