include/oa_types.h

filter: Statementstmt 100% 20 / 20 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 85.7% 24 / 28 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/oa_validate.h ↑ Summary include/oa_normalize.h »
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 3614 static oa_api *oa_api_new(pTHX) {
49 3614 oa_api *a = (oa_api *)malloc(sizeof *a);
50 3614 ▶ if (!a) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) return NULL; 0 3614 3614
51 3614 a->spec = NULL;
52 3614 a->keep = newAV();
53 3614 a->ops = NULL;
54 3614 a->defs = NULL;
55 3614 a->defs_req = NULL;
56 3614 a->defs_resp = NULL;
57 3614 a->proj_req = 0;
58 3614 a->proj_resp = 0;
59 3614 a->prefix = NULL;
60 3614 a->want_servers = 0;
61 3614 return a;
62 }
63  
64 static void oa_ops_free(pTHX_ void *p); /* defined in oa_compile.h */
65  
66 3599 static void oa_api_free(pTHX_ oa_api *a) {
67 3599 ▶ if (!a) return;
Branch: 1 branch
BranchTrueFalseTotal
if (!a) return; 0 3599 3599
68 3599 oa_ops_free(aTHX_ a->ops); /* C arrays only; SVs live in keep */
69 3599 ▶ if (a->spec) SvREFCNT_dec(a->spec);
Branch: 1 branch
BranchTrueFalseTotal
if (a->spec) SvREFCNT_dec(a->spec); 3599 0 3599
70 3599 ▶ if (a->keep) SvREFCNT_dec((SV *)a->keep);
Branch: 1 branch
BranchTrueFalseTotal
if (a->keep) SvREFCNT_dec((SV *)a->keep); 3599 0 3599
71 3599 free(a);
72 }
73  
74 #endif /* OA_TYPES_H */
« include/oa_validate.h ↑ Summary include/oa_normalize.h »