| 1 |
|
| #ifndef OA_TYPES_H |
| 2 |
|
| #define OA_TYPES_H |
| 3 |
|
| |
| 4 |
|
| /* The top-level compiled API object. An Open::API is a blessed IV pointing at |
| 5 |
|
| * this struct (the jsf_compiled_t pattern). `spec` keeps the decoded document |
| 6 |
|
| * alive for introspection; `keep` owns every compiled JSF handle (blessed SVs |
| 7 |
|
| * returned +1 by the JSF ABI) so DESTROY frees them all in one sweep. The |
| 8 |
|
| * operation table itself is built in phase 1 (oa_compile.h). */ |
| 9 |
|
| |
| 10 |
|
| typedef struct oa_api { |
| 11 |
|
| SV *spec; /* decoded OpenAPI document hashref (+1) */ |
| 12 |
|
| AV *keep; /* compiled JSF handle SVs and other keepalives */ |
| 13 |
|
| void *ops; /* oa_ops table (phase 1); NULL until compiled */ |
| 14 |
|
| SV *defs; /* components.schemas rewritten for $defs (in keep; |
| 15 |
|
| * borrowed) - shared across every wrapped schema */ |
| 16 |
|
| /* The same thing PROJECTED for a direction. `readOnly` means a property |
| 17 |
|
| * may come back in a response but should not be sent in a request, and |
| 18 |
|
| * `writeOnly` is the mirror; a `required` readOnly property is required |
| 19 |
|
| * of responses ONLY. None of that can be decided while validating, |
| 20 |
|
| * because JSF owns the traversal once a schema is compiled - so it is |
| 21 |
|
| * expanded into 2020-12 constructs here, per direction, the way |
| 22 |
|
| * `discriminator` is. A $ref from a request body has to reach the |
| 23 |
|
| * request-projected component, hence a whole projected defs block rather |
| 24 |
|
| * than a flag. Both live in `keep`; borrowed, NULL when the document has |
| 25 |
|
| * no readOnly/writeOnly anywhere. */ |
| 26 |
|
| SV *defs_req; /* readOnly properties forbidden, and un-required */ |
| 27 |
|
| SV *defs_resp; /* writeOnly properties forbidden, and un-required */ |
| 28 |
|
| /* Does the document use the flag at all? A document that does not pays |
| 29 |
|
| * nothing: no projection is built and every schema compiles down the |
| 30 |
|
| * original path. Separate from the defs above because the flag can sit in |
| 31 |
|
| * an inline body schema of a document with no components.schemas, where |
| 32 |
|
| * there is no defs block to project but the schema itself still needs it. */ |
| 33 |
|
| int proj_req; |
| 34 |
|
| int proj_resp; |
| 35 |
|
| /* The path prefix a Server Object's URL carries, already expanded, to be |
| 36 |
|
| * stripped before routing - or NULL, which is the default. OPT-IN: |
| 37 |
|
| * honouring a prefix re-routes every deployment that currently mounts so |
| 38 |
|
| * PATH_INFO already matches, and the failure mode is a silent 404 on live |
| 39 |
|
| * traffic, so it happens only when the caller asks for it. In `keep`; |
| 40 |
|
| * borrowed. */ |
| 41 |
|
| SV *prefix; |
| 42 |
|
| /* the caller asked for server URLs to be honoured. Kept separately from |
| 43 |
|
| * `prefix`, which stays NULL when the document declares no root servers - |
| 44 |
|
| * a path item or an operation may still declare its own. */ |
| 45 |
|
| int want_servers; |
| 46 |
|
| } oa_api; |
| 47 |
|
| |
| 48 |
3613 |
| static oa_api *oa_api_new(pTHX) { |
| 49 |
3613 |
| oa_api *a = (oa_api *)malloc(sizeof *a); |
| 50 |
3613 |
▶ | if (!a) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!a) return NULL; |
0 |
3613 |
3613 |
|
| 51 |
3613 |
| a->spec = NULL; |
| 52 |
3613 |
| a->keep = newAV(); |
| 53 |
3613 |
| a->ops = NULL; |
| 54 |
3613 |
| a->defs = NULL; |
| 55 |
3613 |
| a->defs_req = NULL; |
| 56 |
3613 |
| a->defs_resp = NULL; |
| 57 |
3613 |
| a->proj_req = 0; |
| 58 |
3613 |
| a->proj_resp = 0; |
| 59 |
3613 |
| a->prefix = NULL; |
| 60 |
3613 |
| a->want_servers = 0; |
| 61 |
3613 |
| return a; |
| 62 |
|
| } |
| 63 |
|
| |
| 64 |
|
| static void oa_ops_free(pTHX_ void *p); /* defined in oa_compile.h */ |
| 65 |
|
| |
| 66 |
3598 |
| static void oa_api_free(pTHX_ oa_api *a) { |
| 67 |
3598 |
▶ | if (!a) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!a) return; |
0 |
3598 |
3598 |
|
| 68 |
3598 |
| oa_ops_free(aTHX_ a->ops); /* C arrays only; SVs live in keep */ |
| 69 |
3598 |
▶ | if (a->spec) SvREFCNT_dec(a->spec); |
Branch: 1 branch
| Branch | True | False | Total |
| if (a->spec) SvREFCNT_dec(a->spec); |
3598 |
0 |
3598 |
|
| 70 |
3598 |
▶ | if (a->keep) SvREFCNT_dec((SV *)a->keep); |
Branch: 1 branch
| Branch | True | False | Total |
| if (a->keep) SvREFCNT_dec((SV *)a->keep); |
3598 |
0 |
3598 |
|
| 71 |
3598 |
| free(a); |
| 72 |
|
| } |
| 73 |
|
| |
| 74 |
|
| #endif /* OA_TYPES_H */ |