Skip to content

Commit fdb6862

Browse files
Don't expose foreign keys as attributes in openAPI spec (#1856)
1 parent 6df80b2 commit fdb6862

File tree

3 files changed

+4
-26
lines changed

3 files changed

+4
-26
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,10 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
868868
const required: string[] = [];
869869

870870
for (const field of fields) {
871+
if (isForeignKeyField(field) && mode !== 'read') {
872+
// foreign keys are not exposed as attributes
873+
continue;
874+
}
871875
if (isRelationshipField(field)) {
872876
let relType: string;
873877
if (mode === 'create' || mode === 'update') {

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,14 +2791,10 @@ components:
27912791
type: string
27922792
attributes:
27932793
type: object
2794-
required:
2795-
- userId
27962794
properties:
27972795
image:
27982796
type: string
27992797
nullable: true
2800-
userId:
2801-
type: string
28022798
relationships:
28032799
type: object
28042800
properties:
@@ -2830,8 +2826,6 @@ components:
28302826
image:
28312827
type: string
28322828
nullable: true
2833-
userId:
2834-
type: string
28352829
relationships:
28362830
type: object
28372831
properties:
@@ -2974,9 +2968,6 @@ components:
29742968
format: date-time
29752969
title:
29762970
type: string
2977-
authorId:
2978-
type: string
2979-
nullable: true
29802971
published:
29812972
type: boolean
29822973
viewCount:
@@ -3022,9 +3013,6 @@ components:
30223013
format: date-time
30233014
title:
30243015
type: string
3025-
authorId:
3026-
type: string
3027-
nullable: true
30283016
published:
30293017
type: boolean
30303018
viewCount:

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,15 +2797,11 @@ components:
27972797
type: string
27982798
attributes:
27992799
type: object
2800-
required:
2801-
- userId
28022800
properties:
28032801
image:
28042802
oneOf:
28052803
- type: 'null'
28062804
- type: string
2807-
userId:
2808-
type: string
28092805
relationships:
28102806
type: object
28112807
properties:
@@ -2838,8 +2834,6 @@ components:
28382834
oneOf:
28392835
- type: 'null'
28402836
- type: string
2841-
userId:
2842-
type: string
28432837
relationships:
28442838
type: object
28452839
properties:
@@ -2984,10 +2978,6 @@ components:
29842978
format: date-time
29852979
title:
29862980
type: string
2987-
authorId:
2988-
oneOf:
2989-
- type: 'null'
2990-
- type: string
29912981
published:
29922982
type: boolean
29932983
viewCount:
@@ -3034,10 +3024,6 @@ components:
30343024
format: date-time
30353025
title:
30363026
type: string
3037-
authorId:
3038-
oneOf:
3039-
- type: 'null'
3040-
- type: string
30413027
published:
30423028
type: boolean
30433029
viewCount:

0 commit comments

Comments
 (0)