Skip to content

Commit 38dd847

Browse files
committed
Add ext_doc_id for all proparties
1 parent 9fde665 commit 38dd847

File tree

12 files changed

+83
-598
lines changed

12 files changed

+83
-598
lines changed

compiler-rs/clients_schema/src/lib.rs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ pub struct Property {
319319
#[serde(skip_serializing_if = "Option::is_none")]
320320
pub doc_id: Option<String>,
321321

322+
#[serde(skip_serializing_if = "Option::is_none")]
323+
pub ext_doc_url: Option<String>,
324+
325+
#[serde(skip_serializing_if = "Option::is_none")]
326+
pub ext_doc_id: Option<String>,
327+
322328
#[serde(skip_serializing_if = "Option::is_none")]
323329
pub server_default: Option<ServerDefault>,
324330

@@ -360,6 +366,16 @@ impl Documented for Property {
360366
}
361367
}
362368

369+
impl ExternalDocument for Property {
370+
fn ext_doc_url(&self) -> Option<&str> {
371+
self.ext_doc_url.as_deref()
372+
}
373+
374+
fn ext_doc_id(&self) -> Option<&str> {
375+
self.ext_doc_id.as_deref()
376+
}
377+
}
378+
363379
#[derive(Debug, Clone, Serialize, Deserialize)]
364380
#[serde(untagged)]
365381
pub enum ServerDefault {
@@ -482,6 +498,13 @@ pub struct BaseType {
482498
#[serde(skip_serializing_if = "Option::is_none")]
483499
pub doc_id: Option<String>,
484500

501+
/// Link to public documentation
502+
#[serde(skip_serializing_if = "Option::is_none")]
503+
pub ext_doc_url: Option<String>,
504+
505+
#[serde(skip_serializing_if = "Option::is_none")]
506+
pub ext_doc_id: Option<String>,
507+
485508
#[serde(skip_serializing_if = "Option::is_none")]
486509
pub deprecation: Option<Deprecation>,
487510

@@ -517,6 +540,8 @@ impl BaseType {
517540
description: None,
518541
variant_name: None,
519542
spec_location: None,
543+
ext_doc_id: None,
544+
ext_doc_url: None,
520545
}
521546
}
522547
}
@@ -535,6 +560,16 @@ impl Documented for BaseType {
535560
}
536561
}
537562

563+
impl ExternalDocument for BaseType {
564+
fn ext_doc_url(&self) -> Option<&str> {
565+
self.ext_doc_url.as_deref()
566+
}
567+
568+
fn ext_doc_id(&self) -> Option<&str> {
569+
self.ext_doc_id.as_deref()
570+
}
571+
}
572+
538573
trait WithBaseType {
539574
fn base(&self) -> &BaseType;
540575
}
@@ -553,6 +588,16 @@ impl<T: WithBaseType> Documented for T {
553588
}
554589
}
555590

591+
impl<T: WithBaseType> ExternalDocument for T {
592+
fn ext_doc_url(&self) -> Option<&str> {
593+
self.base().doc_url()
594+
}
595+
596+
fn ext_doc_id(&self) -> Option<&str> {
597+
self.base().doc_id()
598+
}
599+
}
600+
556601
/// An interface type
557602
#[derive(Debug, Clone, Serialize, Deserialize)]
558603
#[serde(rename_all = "camelCase")]
@@ -815,19 +860,19 @@ pub struct Endpoint {
815860
pub doc_id: Option<String>,
816861

817862
#[serde(skip_serializing_if = "Option::is_none")]
818-
pub deprecation: Option<Deprecation>,
863+
pub ext_doc_id: Option<String>,
819864

820865
#[serde(skip_serializing_if = "Option::is_none")]
821-
pub availability: Option<Availabilities>,
866+
pub ext_doc_url: Option<String>,
822867

823868
#[serde(skip_serializing_if = "Option::is_none")]
824-
pub doc_tag: Option<String>,
869+
pub deprecation: Option<Deprecation>,
825870

826871
#[serde(skip_serializing_if = "Option::is_none")]
827-
pub ext_doc_id: Option<String>,
872+
pub availability: Option<Availabilities>,
828873

829874
#[serde(skip_serializing_if = "Option::is_none")]
830-
pub ext_doc_url: Option<String>,
875+
pub doc_tag: Option<String>,
831876

832877
/// If missing, there is not yet a request definition for this endpoint.
833878
#[serde(skip_serializing_if = "Option::is_none")]

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub fn add_endpoint(
203203
},
204204
summary: sum_desc.summary,
205205
description: sum_desc.description,
206-
external_docs: tac.convert_endpoint_external_docs(endpoint),
206+
external_docs: tac.convert_external_docs(endpoint),
207207
// external_docs: None, // Need values that differ from client purposes
208208
operation_id: None, // set in clone_operation below with operation_counter
209209
parameters,

compiler-rs/clients_schema_to_openapi/src/schemas.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,7 @@ impl<'a> TypesAndComponents<'a> {
209209
self.for_body(&response.body)
210210
}
211211

212-
pub fn convert_external_docs(&self, obj: &impl clients_schema::Documented) -> Option<ExternalDocumentation> {
213-
// FIXME: does the model contain resolved doc_id?
214-
obj.doc_url().map(|url| {
215-
let branch: &str = self
216-
.model
217-
.info
218-
.as_ref()
219-
.and_then(|i| i.version.as_deref())
220-
.unwrap_or("current");
221-
ExternalDocumentation {
222-
description: None,
223-
url: url.trim().replace("{branch}", branch),
224-
extensions: Default::default(),
225-
}
226-
})
227-
}
228-
229-
pub fn convert_endpoint_external_docs(&self, obj: &impl clients_schema::ExternalDocument) -> Option<ExternalDocumentation> {
212+
pub fn convert_external_docs(&self, obj: &impl clients_schema::ExternalDocument) -> Option<ExternalDocumentation> {
230213
// FIXME: does the model contain resolved doc_id?
231214
obj.ext_doc_url().map(|url| {
232215
let branch: &str = self
2.14 KB
Binary file not shown.

compiler-rs/openapi_to_clients_schema/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn generate_type_for_schema(
121121
})
122122
}
123123
if let Some(ref docs) = data.external_docs {
124-
base.doc_url = Some(docs.url.clone())
124+
base.ext_doc_url = Some(docs.ext_docs_url.clone())
125125
}
126126

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

compiler/src/model/metamodel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ export class Property {
126126
description?: string
127127
docUrl?: string
128128
docId?: string
129+
extDocId?: string
130+
extDocUrl?: string
129131
serverDefault?: boolean | string | number | string[] | number[]
130132
deprecation?: Deprecation
131133
availability?: Availabilities
@@ -158,6 +160,8 @@ export abstract class BaseType {
158160
/** Link to public documentation */
159161
docUrl?: string
160162
docId?: string
163+
extDocId?: string
164+
extDocUrl?: string
161165
deprecation?: Deprecation
162166
/** If this endpoint has a quirk that needs special attention, give a short explanation about it */
163167
esQuirk?: string

compiler/src/model/utils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
719719
assert(jsDocs, jsDocs.length < 2, 'Use a single multiline jsDoc block instead of multiple single line blocks')
720720

721721
const validTags = ['class_serializer', 'doc_url', 'doc_id', 'behavior', 'variants', 'variant', 'shortcut_property',
722-
'codegen_names', 'non_exhaustive', 'es_quirk', 'behavior_meta']
722+
'codegen_names', 'non_exhaustive', 'es_quirk', 'behavior_meta', 'ext_doc_id']
723723
const tags = parseJsDocTags(jsDocs)
724724
if (jsDocs.length === 1) {
725725
const description = jsDocs[0].getDescription()
@@ -748,7 +748,14 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
748748
const docUrl = docIds.find(entry => entry[0] === value.trim())
749749
assert(jsDocs, docUrl != null, `The @doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
750750
type.docUrl = docUrl[1].replace(/\r/g, '')
751-
} else if (tag === 'codegen_names') {
751+
} else if (tag === 'ext_doc_id') {
752+
assert(jsDocs, value.trim() !== '', `Type ${type.name.namespace}.${type.name.name}'s @ext_doc_id cannot be empty`)
753+
type.extDocId = value.trim()
754+
const docUrl = docIds.find(entry => entry[0] === value.trim())
755+
assert(jsDocs, docUrl != null, `The @ext_doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
756+
type.extDocUrl = docUrl[1].replace(/\r/g, '')
757+
}
758+
else if (tag === 'codegen_names') {
752759
type.codegenNames = parseCommaSeparated(value)
753760
assert(jsDocs,
754761
type.kind === 'type_alias' && type.type.kind === 'union_of' && type.type.items.length === type.codegenNames.length,
@@ -770,7 +777,7 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
770777
assert(jsDocs, jsDocs.length < 2, 'Use a single multiline jsDoc block instead of multiple single line blocks')
771778

772779
const validTags = ['prop_serializer', 'doc_url', 'aliases', 'codegen_name', 'server_default',
773-
'variant', 'doc_id', 'es_quirk', 'availability']
780+
'variant', 'doc_id', 'es_quirk', 'availability', 'ext_doc_id']
774781
const tags = parseJsDocTags(jsDocs)
775782
if (jsDocs.length === 1) {
776783
const description = jsDocs[0].getDescription()
@@ -814,6 +821,13 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
814821
if (docUrl != null) {
815822
property.docUrl = docUrl[1].replace(/\r/g, '')
816823
}
824+
} else if (tag === 'ext_doc_id') {
825+
assert(jsDocs, value.trim() !== '', `Property ${property.name}'s @ext_doc_id is cannot be empty`)
826+
property.extDocId = value
827+
const docUrl = docIds.find(entry => entry[0] === value)
828+
if (docUrl != null) {
829+
property.extDocUrl = docUrl[1].replace(/\r/g, '')
830+
}
817831
} else if (tag === 'server_default') {
818832
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}`)
819833
assert(jsDocs, !property.required, 'Default values can only be specified on optional properties')

0 commit comments

Comments
 (0)