-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathspec.rs
730 lines (659 loc) · 24.1 KB
/
spec.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
use crate::path;
use autorust_openapi::{
AdditionalProperties, CollectionFormat, DataType, MsExamples, OpenAPI, Operation, Parameter, ParameterType, PathItem, Reference,
ReferenceOr, Response, Schema, SchemaCommon, StatusCode,
};
use indexmap::{IndexMap, IndexSet};
use std::{
ffi::OsStr,
fs,
path::{Path, PathBuf},
};
/// An API specification
#[derive(Clone, Debug)]
pub struct Spec {
/// A store of all the documents for an API specification keyed on their file paths where the first one is the root document
docs: IndexMap<PathBuf, OpenAPI>,
schemas: IndexMap<RefKey, Schema>,
parameters: IndexMap<RefKey, Parameter>,
input_files_paths: IndexSet<PathBuf>,
}
impl Spec {
/// Read a list of input files as OpenApi docs with the first being the root doc
///
/// This eagerly collects all the schemas and parametes for the docs
pub fn read_files(input_files_paths: &[impl AsRef<Path>]) -> Result<Self> {
let mut docs: IndexMap<PathBuf, OpenAPI> = IndexMap::new();
for file_path in input_files_paths {
Spec::read_file(&mut docs, file_path)?;
}
let mut schemas: IndexMap<RefKey, Schema> = IndexMap::new();
let mut parameters: IndexMap<RefKey, Parameter> = IndexMap::new();
for (path, doc) in &docs {
for (name, schema) in &doc.definitions {
if let ReferenceOr::Item(schema) = schema {
let ref_key = RefKey {
file_path: path.clone(),
name: name.clone(),
};
schemas.insert(ref_key, schema.clone());
}
}
for (name, param) in &doc.parameters {
parameters.insert(
RefKey {
file_path: path.clone(),
name: name.clone(),
},
param.clone(),
);
}
}
Ok(Self {
docs,
schemas,
parameters,
input_files_paths: input_files_paths.iter().map(|f| f.as_ref().to_owned()).collect(),
})
}
/// Read a file and references too, recursively into the map
fn read_file(docs: &mut IndexMap<PathBuf, OpenAPI>, file_path: impl AsRef<Path>) -> Result<()> {
let file_path = file_path.as_ref();
if !docs.contains_key(file_path) {
let doc = openapi::parse(&file_path)?;
let ref_files = openapi::get_reference_file_paths(&file_path.to_path_buf(), &doc);
docs.insert(PathBuf::from(file_path), doc);
for ref_file in ref_files {
let child_path = path::join(&file_path, &ref_file).map_err(|source| Error::PathJoin { source })?;
Spec::read_file(docs, &child_path)?;
}
}
Ok(())
}
pub fn docs(&self) -> &IndexMap<PathBuf, OpenAPI> {
&self.docs
}
pub fn title(&self) -> Option<&str> {
let mut titles: Vec<_> = self
.docs
.values()
.map(|doc| &doc.info.title)
.filter(|t| t.is_some())
.flatten()
.collect();
titles.sort_unstable();
titles.get(0).map(|t| t.as_str())
}
pub fn consumes(&self) -> Vec<&String> {
let mut versions: Vec<_> = self
.docs()
.values()
.filter(|doc| !doc.paths().is_empty())
.map(|api| &api.consumes)
.flatten()
.collect();
versions.sort_unstable();
versions
}
/// Look for specs with operations and return the last one sorted alphabetically
pub fn api_version(&self) -> Option<String> {
let mut versions: Vec<&str> = self
.docs()
.values()
.filter(|doc| !doc.paths().is_empty())
.filter_map(|api| api.info.version.as_deref())
.collect();
versions.sort_unstable();
versions.last().map(|version| version.to_string())
}
pub fn input_docs(&self) -> impl Iterator<Item = (&PathBuf, &OpenAPI)> {
self.docs.iter().filter(move |(p, _)| self.is_input_file(p))
}
pub fn is_input_file(&self, path: impl AsRef<Path>) -> bool {
self.input_files_paths.contains(path.as_ref())
}
pub fn ref_key(&self, doc_file: impl AsRef<Path>, reference: &Reference) -> Result<RefKey> {
let doc_file = doc_file.as_ref();
let full_path = match &reference.file {
None => doc_file.to_owned(),
Some(file) => path::join(doc_file, &file).map_err(|source| Error::PathJoin { source })?,
};
let name = reference.name.clone().ok_or(Error::NoNameInReference)?;
let ref_key = RefKey {
file_path: full_path,
name,
};
Ok(ref_key)
}
/// Find the schema for a given doc path and reference
pub fn resolve_schema_ref(&self, doc_file: impl AsRef<Path>, reference: &Reference) -> Result<ResolvedSchema> {
let ref_key = self.ref_key(doc_file, reference)?;
let schema = self
.schemas
.get(&ref_key)
.ok_or_else(|| Error::SchemaNotFound { ref_key: ref_key.clone() })?
.clone();
Ok(ResolvedSchema {
ref_key: Some(ref_key),
schema,
})
}
/// Find the parameter for a given doc path and reference
pub fn resolve_parameter_ref(&self, doc_file: impl AsRef<Path>, reference: Reference) -> Result<Parameter> {
let doc_file = doc_file.as_ref();
let full_path = match reference.file {
None => doc_file.to_owned(),
Some(file) => path::join(doc_file, &file).map_err(|source| Error::PathJoin { source })?,
};
let name = reference.name.ok_or(Error::NoNameInReference)?;
let ref_key = RefKey {
file_path: full_path,
name,
};
Ok(self.parameters.get(&ref_key).ok_or(Error::ParameterNotFound { ref_key })?.clone())
}
/// Resolve a reference or schema to a resolved schema
fn resolve_schema(&self, doc_file: impl AsRef<Path>, ref_or_schema: &ReferenceOr<Schema>) -> Result<ResolvedSchema> {
match ref_or_schema {
ReferenceOr::Item(schema) => Ok(ResolvedSchema {
ref_key: None,
schema: schema.clone(),
}),
ReferenceOr::Reference { reference, .. } => self.resolve_schema_ref(doc_file, reference),
}
}
/// Resolve a collection of references or schemas to a collection of resolved schemas
pub fn resolve_schema_map(
&self,
doc_file: impl Into<PathBuf>,
ref_or_schemas: &IndexMap<String, ReferenceOr<Schema>>,
) -> Result<IndexMap<String, ResolvedSchema>> {
let mut resolved = IndexMap::new();
let doc_file = doc_file.into();
for (name, schema) in ref_or_schemas {
resolved.insert(name.clone(), self.resolve_schema(&doc_file, schema)?);
}
Ok(resolved)
}
pub fn resolve_path(&self, _doc_file: impl AsRef<Path>, path: &ReferenceOr<PathItem>) -> Result<PathItem> {
match path {
ReferenceOr::Item(path) => Ok(path.clone()),
ReferenceOr::Reference { .. } => Err(Error::NotImplemented),
}
}
pub fn resolve_path_map(&self, doc_file: &Path, paths: &IndexMap<String, ReferenceOr<PathItem>>) -> Result<IndexMap<String, PathItem>> {
let mut resolved = IndexMap::new();
for (name, path) in paths {
resolved.insert(name.clone(), self.resolve_path(doc_file, path)?);
}
Ok(resolved)
}
fn resolve_parameter(&self, doc_file: &Path, parameter: &ReferenceOr<Parameter>) -> Result<Parameter> {
match parameter {
ReferenceOr::Item(param) => Ok(param.clone()),
ReferenceOr::Reference { reference, .. } => self.resolve_parameter_ref(doc_file, reference.clone()),
}
}
fn resolve_parameters(&self, doc_file: &Path, parameters: &[ReferenceOr<Parameter>]) -> Result<Vec<WebParameter>> {
let mut resolved = Vec::new();
for param in parameters {
resolved.push(WebParameter(self.resolve_parameter(doc_file, param)?));
}
Ok(resolved)
}
// only operations from listed input files
fn operations_unresolved(&self) -> Result<Vec<WebOperationUnresolved>> {
let mut operations: Vec<WebOperationUnresolved> = Vec::new();
for (doc_file, doc) in self.docs() {
if self.is_input_file(&doc_file) {
let paths = self.resolve_path_map(doc_file, doc.paths())?;
for (path, item) in &paths {
operations.extend(path_operations_unresolved(doc_file, path, item))
}
}
}
Ok(operations)
}
// only operations from listed input files
pub fn operations(&self) -> Result<Vec<WebOperation>> {
self.operations_unresolved()?
.into_iter()
.map({
|op| {
Ok(WebOperation {
id: op.id,
path: op.path,
verb: op.verb,
parameters: self.resolve_parameters(&op.doc_file, &op.parameters)?,
responses: op.responses,
examples: op.examples,
summary: op.summary,
})
}
})
.collect()
}
}
type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("PathJoin")]
PathJoin { source: path::Error },
#[error("SchemaNotFound {} {}", ref_key.file_path.display(), ref_key.name)]
SchemaNotFound { ref_key: RefKey },
#[error("NoNameInReference")]
NoNameInReference,
#[error("ParameterNotFound")]
ParameterNotFound { ref_key: RefKey },
#[error("NotImplemented")]
NotImplemented,
#[error("ReadFile")]
ReadFile { source: std::io::Error, path: PathBuf },
#[error("DeserializeYaml")]
DeserializeYaml { source: serde_yaml::Error, path: PathBuf },
#[error("DeserializeJson")]
DeserializeJson { source: serde_json::Error, path: PathBuf },
#[error("TypeName {0}")]
TypeName(#[source] Box<crate::codegen::Error>),
#[error("creating function name: {0}")]
FunctionName(#[source] crate::identifier::Error),
#[error("ArrayExpectedToHaveItems")]
ArrayExpectedToHaveItems,
#[error("NoNameForRef")]
NoNameForRef,
}
/// a qualified reference
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RefKey {
pub file_path: PathBuf,
pub name: String,
}
#[derive(Clone)]
pub struct ResolvedSchema {
pub ref_key: Option<RefKey>,
pub schema: Schema,
}
/// Functionality related to Open API definitions
pub mod openapi {
use super::*;
/// Parse an OpenAPI object from a file located at `path`
pub fn parse(path: impl AsRef<Path>) -> Result<OpenAPI> {
let path = path.as_ref();
let bytes = fs::read(path).map_err(|source| Error::ReadFile {
source,
path: PathBuf::from(path),
})?;
let api = if path.extension() == Some(OsStr::new("yaml")) || path.extension() == Some(OsStr::new("yml")) {
serde_yaml::from_slice(&bytes).map_err(|source| Error::DeserializeYaml {
source,
path: PathBuf::from(path),
})?
} else {
serde_json::from_slice(&bytes).map_err(|source| Error::DeserializeJson {
source,
path: PathBuf::from(path),
})?
};
Ok(api)
}
/// Returns a set of referenced relative file paths from an OpenAPI specficiation
pub fn get_reference_file_paths(doc_file: impl AsRef<Path>, api: &OpenAPI) -> IndexSet<String> {
get_references(doc_file, api)
.into_iter()
.filter_map(|reference| match reference {
TypedReference::Example(_) => None,
reference => {
let reference: Reference = reference.into();
reference.file
}
})
.collect()
}
/// Returns the list of all references contained in an OpenAPI schema
pub fn get_references(doc_file: impl AsRef<Path>, api: &OpenAPI) -> Vec<TypedReference> {
let mut list = Vec::new();
// paths and operations
for (path, item) in api.paths() {
match item {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::PathItem(reference.clone())),
ReferenceOr::Item(item) => {
for operation in path_operations_unresolved(&doc_file, path, item) {
// parameters
for param in &operation.parameters {
match param {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::Parameter(reference.clone())),
ReferenceOr::Item(parameter) => match ¶meter.schema {
Some(ReferenceOr::Reference { reference, .. }) => list.push(TypedReference::Schema(reference.clone())),
Some(ReferenceOr::Item(schema)) => add_references_for_schema(&mut list, schema),
None => {}
},
}
}
// responses
for (_code, rsp) in &operation.responses {
match &rsp.schema {
Some(ReferenceOr::Reference { reference, .. }) => list.push(TypedReference::Schema(reference.clone())),
Some(ReferenceOr::Item(schema)) => add_references_for_schema(&mut list, schema),
None => {}
}
}
// examples
for (_name, example) in &operation.examples {
if let ReferenceOr::Reference { reference, .. } = example {
list.push(TypedReference::Example(reference.clone()));
}
}
}
}
}
}
// definitions
for (_name, schema) in &api.definitions {
match schema {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::Schema(reference.clone())),
ReferenceOr::Item(schema) => add_references_for_schema(&mut list, schema),
}
}
list
}
/// Get all references related to schemas for an Open API specification
pub fn get_api_schema_references(doc_file: &Path, api: &OpenAPI) -> Vec<Reference> {
get_references(doc_file, api)
.into_iter()
.filter_map(|rf| match rf {
TypedReference::Schema(rs) => Some(rs),
_ => None,
})
.collect()
}
}
// contains unresolved parameters
struct WebOperationUnresolved {
pub doc_file: PathBuf,
pub id: Option<String>,
pub path: String,
pub verb: WebVerb,
pub parameters: Vec<ReferenceOr<Parameter>>,
pub responses: IndexMap<StatusCode, Response>,
pub examples: MsExamples,
pub summary: Option<String>,
}
// contains resolved parameters
pub struct WebOperation {
pub id: Option<String>,
pub path: String,
pub verb: WebVerb,
pub parameters: Vec<WebParameter>,
pub responses: IndexMap<StatusCode, Response>,
pub examples: MsExamples,
pub summary: Option<String>,
}
impl Default for WebOperation {
fn default() -> Self {
Self {
id: Default::default(),
path: Default::default(),
verb: WebVerb::Get,
parameters: Default::default(),
responses: Default::default(),
examples: Default::default(),
summary: Default::default(),
}
}
}
pub struct WebParameter(Parameter);
impl WebParameter {
pub fn name(&self) -> &str {
self.0.name.as_str()
}
pub fn required(&self) -> bool {
self.0.required.unwrap_or(false)
}
pub fn is_bool(&self) -> bool {
matches!(self.0.common.type_, Some(DataType::Boolean))
}
pub fn collection_format(&self) -> &CollectionFormat {
self.0.collection_format.as_ref().unwrap_or(&CollectionFormat::Csv)
}
pub fn type_(&self) -> &ParameterType {
&self.0.in_
}
pub fn data_type(&self) -> &Option<DataType> {
&self.0.common.type_
}
pub fn is_array(&self) -> bool {
matches!(self.data_type(), Some(DataType::Array))
}
pub fn is_string(&self) -> bool {
matches!(self.data_type(), Some(DataType::String))
}
pub fn type_name(&self) -> Result<TypeName, Error> {
Ok(if let Some(_data_type) = self.data_type() {
get_type_name_for_schema(&self.0.common)?
} else if let Some(schema) = &self.0.schema {
get_type_name_for_schema_ref(schema)?
} else {
// eprintln!("WARN unknown param type name for {}", self.name());
TypeName::Value
})
}
pub fn type_is_ref(&self) -> Result<bool, Error> {
Ok(if let Some(data_type) = self.data_type() {
matches!(data_type, DataType::String | DataType::Object | DataType::File)
} else {
true
})
}
}
impl WebOperation {
pub fn parameters(&self) -> Vec<&WebParameter> {
self.parameters.iter().collect()
}
pub fn id_parts(&self) -> Vec<&str> {
match &self.id {
Some(id) => id.splitn(2, '_').collect(),
None => Vec::new(),
}
}
pub fn in_group(&self) -> bool {
self.id_parts().len() == 2
}
pub fn has_body_parameter(&self) -> bool {
self.parameters.iter().any(|p| p.type_() == &ParameterType::Body)
}
}
pub enum WebVerb {
Get,
Post,
Put,
Patch,
Delete,
Options,
Head,
}
impl<'a> WebVerb {
pub fn as_str(&self) -> &'static str {
match self {
WebVerb::Get => "get",
WebVerb::Post => "post",
WebVerb::Put => "put",
WebVerb::Patch => "patch",
WebVerb::Delete => "delete",
WebVerb::Options => "options",
WebVerb::Head => "head",
}
}
}
struct OperationVerb<'a> {
pub operation: Option<&'a Operation>,
pub verb: WebVerb,
}
fn path_operations_unresolved(doc_file: impl AsRef<Path>, path: &str, item: &PathItem) -> Vec<WebOperationUnresolved> {
vec![
OperationVerb {
operation: item.get.as_ref(),
verb: WebVerb::Get,
},
OperationVerb {
operation: item.post.as_ref(),
verb: WebVerb::Post,
},
OperationVerb {
operation: item.put.as_ref(),
verb: WebVerb::Put,
},
OperationVerb {
operation: item.patch.as_ref(),
verb: WebVerb::Patch,
},
OperationVerb {
operation: item.delete.as_ref(),
verb: WebVerb::Delete,
},
OperationVerb {
operation: item.options.as_ref(),
verb: WebVerb::Options,
},
OperationVerb {
operation: item.head.as_ref(),
verb: WebVerb::Head,
},
]
.into_iter()
.filter_map(|op_verb| match op_verb.operation {
Some(op) => {
let mut parameters = item.parameters.clone();
parameters.append(&mut op.parameters.clone());
Some(WebOperationUnresolved {
doc_file: doc_file.as_ref().to_path_buf(),
id: op.operation_id.clone(),
path: path.to_string(),
verb: op_verb.verb,
parameters,
responses: op.responses.clone(),
examples: op.x_ms_examples.clone(),
summary: op.summary.clone(),
})
}
None => None,
})
.collect()
}
/// A $ref reference type that knows what type of reference it is
#[derive(Clone, Debug, PartialEq)]
pub enum TypedReference {
PathItem(Reference),
Parameter(Reference),
Schema(Reference),
Example(Reference),
}
impl From<TypedReference> for Reference {
fn from(s: TypedReference) -> Reference {
match s {
TypedReference::PathItem(r) => r,
TypedReference::Parameter(r) => r,
TypedReference::Schema(r) => r,
TypedReference::Example(r) => r,
}
}
}
/// Get all schema references for a given schema
pub fn get_schema_schema_references(schema: &Schema) -> Vec<Reference> {
let mut refs = Vec::new();
add_references_for_schema(&mut refs, schema);
refs.into_iter()
.filter_map(|rf| match rf {
TypedReference::Schema(rs) => Some(rs),
_ => None,
})
.collect()
}
fn add_references_for_schema(list: &mut Vec<TypedReference>, schema: &Schema) {
for (_, schema) in &schema.properties {
match schema {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::Schema(reference.clone())),
ReferenceOr::Item(schema) => add_references_for_schema(list, schema),
}
}
if let Some(ap) = schema.additional_properties.as_ref() {
match ap {
AdditionalProperties::Boolean(_) => {}
AdditionalProperties::Schema(schema) => match schema {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::Schema(reference.clone())),
ReferenceOr::Item(schema) => add_references_for_schema(list, schema),
},
}
}
if let Some(schema) = schema.common.items.as_ref() {
match schema {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::Schema(reference.clone())),
ReferenceOr::Item(schema) => add_references_for_schema(list, schema),
}
}
for schema in &schema.all_of {
match schema {
ReferenceOr::Reference { reference, .. } => list.push(TypedReference::Schema(reference.clone())),
ReferenceOr::Item(schema) => add_references_for_schema(list, schema),
}
}
}
pub enum TypeName {
Reference(String),
Array(Box<TypeName>),
Value,
Bytes,
Int32,
Int64,
Float32,
Float64,
Boolean,
String,
}
pub fn get_type_name_for_schema(schema: &SchemaCommon) -> Result<TypeName, Error> {
Ok(if let Some(schema_type) = &schema.type_ {
let format = schema.format.as_deref();
match schema_type {
DataType::Array => {
let items = get_schema_array_items(schema)?;
let vec_items_typ = get_type_name_for_schema_ref(items)?;
TypeName::Array(Box::new(vec_items_typ))
}
DataType::Integer => {
if format == Some("int32") {
TypeName::Int32
} else {
TypeName::Int64
}
}
DataType::Number => {
if format == Some("float") {
TypeName::Float32
} else {
TypeName::Float64
}
}
DataType::String => TypeName::String,
DataType::Boolean => TypeName::Boolean,
DataType::Object => TypeName::Value,
DataType::File => TypeName::Bytes,
}
} else {
// eprintln!(
// "WARN unknown type in get_type_name_for_schema, description {:?}",
// schema.description
// );
TypeName::Value
})
}
pub fn get_type_name_for_schema_ref(schema: &ReferenceOr<Schema>) -> Result<TypeName, Error> {
Ok(match schema {
ReferenceOr::Reference { reference, .. } => {
let name = reference.name.as_ref().ok_or(Error::NoNameForRef)?;
TypeName::Reference(name.to_owned())
}
ReferenceOr::Item(schema) => get_type_name_for_schema(&schema.common)?,
})
}
pub fn get_schema_array_items(schema: &SchemaCommon) -> Result<&ReferenceOr<Schema>, Error> {
schema.items.as_ref().as_ref().ok_or(Error::ArrayExpectedToHaveItems)
}