Skip to content

Commit 5c7a8b5

Browse files
committed
[OpenAPI] Add description to externalDocs
1 parent 8650a71 commit 5c7a8b5

File tree

10 files changed

+684
-632
lines changed

10 files changed

+684
-632
lines changed

compiler-rs/clients_schema/src/lib.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub trait Documented {
5858
pub trait ExternalDocument {
5959
fn ext_doc_id(&self) -> Option<&str>;
6060
fn ext_doc_url(&self) -> Option<&str>;
61+
fn ext_doc_description(&self) -> Option<&str>;
6162
}
6263

6364
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -325,6 +326,9 @@ pub struct Property {
325326
#[serde(skip_serializing_if = "Option::is_none")]
326327
pub ext_doc_id: Option<String>,
327328

329+
#[serde(skip_serializing_if = "Option::is_none")]
330+
pub ext_doc_description: Option<String>,
331+
328332
#[serde(skip_serializing_if = "Option::is_none")]
329333
pub server_default: Option<ServerDefault>,
330334

@@ -374,6 +378,10 @@ impl ExternalDocument for Property {
374378
fn ext_doc_id(&self) -> Option<&str> {
375379
self.ext_doc_id.as_deref()
376380
}
381+
382+
fn ext_doc_description(&self) -> Option<&str> {
383+
self.ext_doc_description.as_deref()
384+
}
377385
}
378386

379387
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -505,6 +513,9 @@ pub struct BaseType {
505513
#[serde(skip_serializing_if = "Option::is_none")]
506514
pub ext_doc_id: Option<String>,
507515

516+
#[serde(skip_serializing_if = "Option::is_none")]
517+
pub ext_doc_description: Option<String>,
518+
508519
#[serde(skip_serializing_if = "Option::is_none")]
509520
pub deprecation: Option<Deprecation>,
510521

@@ -542,6 +553,7 @@ impl BaseType {
542553
spec_location: None,
543554
ext_doc_id: None,
544555
ext_doc_url: None,
556+
ext_doc_description: None,
545557
}
546558
}
547559
}
@@ -568,6 +580,10 @@ impl ExternalDocument for BaseType {
568580
fn ext_doc_id(&self) -> Option<&str> {
569581
self.ext_doc_id.as_deref()
570582
}
583+
584+
fn ext_doc_description(&self) -> Option<&str> {
585+
self.ext_doc_description.as_deref()
586+
}
571587
}
572588

573589
trait WithBaseType {
@@ -590,11 +606,15 @@ impl<T: WithBaseType> Documented for T {
590606

591607
impl<T: WithBaseType> ExternalDocument for T {
592608
fn ext_doc_url(&self) -> Option<&str> {
593-
self.base().doc_url()
609+
self.base().ext_doc_url()
594610
}
595611

596612
fn ext_doc_id(&self) -> Option<&str> {
597-
self.base().doc_id()
613+
self.base().ext_doc_id()
614+
}
615+
616+
fn ext_doc_description(&self) -> Option<&str> {
617+
self.base().ext_doc_description()
598618
}
599619
}
600620

@@ -865,6 +885,9 @@ pub struct Endpoint {
865885
#[serde(skip_serializing_if = "Option::is_none")]
866886
pub ext_doc_url: Option<String>,
867887

888+
#[serde(skip_serializing_if = "Option::is_none")]
889+
pub ext_doc_description: Option<String>,
890+
868891
#[serde(skip_serializing_if = "Option::is_none")]
869892
pub deprecation: Option<Deprecation>,
870893

@@ -918,6 +941,10 @@ impl ExternalDocument for Endpoint {
918941
fn ext_doc_id(&self) -> Option<&str> {
919942
self.ext_doc_id.as_deref()
920943
}
944+
945+
fn ext_doc_description(&self) -> Option<&str> {
946+
self.ext_doc_description.as_deref()
947+
}
921948
}
922949

923950
#[derive(Debug, Clone, Serialize, Deserialize)]

compiler-rs/clients_schema_to_openapi/src/schemas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'a> TypesAndComponents<'a> {
219219
.and_then(|i| i.version.as_deref())
220220
.unwrap_or("current");
221221
ExternalDocumentation {
222-
description: None,
222+
description: obj.ext_doc_description().as_deref(),
223223
url: url.trim().replace("{branch}", branch),
224224
extensions: Default::default(),
225225
}
1.87 KB
Binary file not shown.

compiler-rs/openapi_to_clients_schema/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ fn generate_type_for_schema(
122122
}
123123
if let Some(ref docs) = data.external_docs {
124124
base.ext_doc_url = Some(docs.ext_docs_url.clone())
125+
base.ext_doc_description = Some(docs.ext_doc_description.clone())
125126
}
126127

127128
// TODO: data.readonly/writeonly -> OverloadOf?

compiler/package-lock.json

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/src/model/metamodel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export class Property {
128128
docId?: string
129129
extDocId?: string
130130
extDocUrl?: string
131+
extDocDesc?: string
131132
serverDefault?: boolean | string | number | string[] | number[]
132133
deprecation?: Deprecation
133134
availability?: Availabilities
@@ -162,6 +163,7 @@ export abstract class BaseType {
162163
docId?: string
163164
extDocId?: string
164165
extDocUrl?: string
166+
extDocDesc?: string
165167
deprecation?: Deprecation
166168
/** If this endpoint has a quirk that needs special attention, give a short explanation about it */
167169
esQuirk?: string
@@ -412,6 +414,7 @@ export class Endpoint {
412414
docId?: string
413415
extDocId?: string
414416
extDocUrl?: string
417+
extDocDesc?: string
415418
deprecation?: Deprecation
416419
availability: Availabilities
417420
docTag?: string

compiler/src/model/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ export function hoistRequestAnnotations (
691691
const docUrl = docIds.find(entry => entry[0] === value.trim())
692692
assert(jsDocs, docUrl != null, `The @ext_doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
693693
endpoint.extDocUrl = docUrl[1].replace(/\r/g, '')
694+
const docDesc = docUrl[2].trim()
695+
if (docDesc != null) {
696+
endpoint.extDocDesc = docDesc
697+
}
694698
} else if (tag === 'availability') {
695699
// The @availability jsTag is different than most because it allows
696700
// multiple values within the same docstring, hence needing to parse
@@ -754,6 +758,10 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
754758
const docUrl = docIds.find(entry => entry[0] === value.trim())
755759
assert(jsDocs, docUrl != null, `The @ext_doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
756760
type.extDocUrl = docUrl[1].replace(/\r/g, '')
761+
const docDesc = docUrl[2].trim()
762+
if (docDesc != null) {
763+
type.extDocDesc = docDesc
764+
}
757765
} else if (tag === 'codegen_names') {
758766
type.codegenNames = parseCommaSeparated(value)
759767
assert(jsDocs,
@@ -826,6 +834,10 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
826834
const docUrl = docIds.find(entry => entry[0] === value)
827835
if (docUrl != null) {
828836
property.extDocUrl = docUrl[1].replace(/\r/g, '')
837+
const docDesc = docUrl[2].trim()
838+
if (docDesc != null) {
839+
property.extDocDesc = docDesc
840+
}
829841
}
830842
} else if (tag === 'server_default') {
831843
assert(jsDocs, property.type.kind === 'instance_of' || property.type.kind === 'union_of' || property.type.kind === 'array_of', `Default values can only be configured for instance_of or union_of types, you are using ${property.type.kind}`)

output/schema/schema.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)