Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenAPI] Add description to externalDocs #3030

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions compiler-rs/clients_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub trait Documented {
pub trait ExternalDocument {
fn ext_doc_id(&self) -> Option<&str>;
fn ext_doc_url(&self) -> Option<&str>;
fn ext_doc_description(&self) -> Option<&str>;
}

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

#[serde(skip_serializing_if = "Option::is_none")]
pub ext_doc_description: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub server_default: Option<ServerDefault>,

Expand Down Expand Up @@ -374,6 +378,10 @@ impl ExternalDocument for Property {
fn ext_doc_id(&self) -> Option<&str> {
self.ext_doc_id.as_deref()
}

fn ext_doc_description(&self) -> Option<&str> {
self.ext_doc_description.as_deref()
}
}

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

#[serde(skip_serializing_if = "Option::is_none")]
pub ext_doc_description: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub deprecation: Option<Deprecation>,

Expand Down Expand Up @@ -542,6 +553,7 @@ impl BaseType {
spec_location: None,
ext_doc_id: None,
ext_doc_url: None,
ext_doc_description: None,
}
}
}
Expand All @@ -568,6 +580,10 @@ impl ExternalDocument for BaseType {
fn ext_doc_id(&self) -> Option<&str> {
self.ext_doc_id.as_deref()
}

fn ext_doc_description(&self) -> Option<&str> {
self.ext_doc_description.as_deref()
}
}

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

impl<T: WithBaseType> ExternalDocument for T {
fn ext_doc_url(&self) -> Option<&str> {
self.base().doc_url()
self.base().ext_doc_url()
}

fn ext_doc_id(&self) -> Option<&str> {
self.base().doc_id()
self.base().ext_doc_id()
}

fn ext_doc_description(&self) -> Option<&str> {
self.base().ext_doc_description()
}
}

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

#[serde(skip_serializing_if = "Option::is_none")]
pub ext_doc_description: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub deprecation: Option<Deprecation>,

Expand Down Expand Up @@ -918,6 +941,10 @@ impl ExternalDocument for Endpoint {
fn ext_doc_id(&self) -> Option<&str> {
self.ext_doc_id.as_deref()
}

fn ext_doc_description(&self) -> Option<&str> {
self.ext_doc_description.as_deref()
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion compiler-rs/clients_schema_to_openapi/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<'a> TypesAndComponents<'a> {
.and_then(|i| i.version.as_deref())
.unwrap_or("current");
ExternalDocumentation {
description: None,
description: obj.ext_doc_description().as_deref(),
url: url.trim().replace("{branch}", branch),
extensions: Default::default(),
}
Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions compiler-rs/openapi_to_clients_schema/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn generate_type_for_schema(
}
if let Some(ref docs) = data.external_docs {
base.ext_doc_url = Some(docs.ext_docs_url.clone())
base.ext_doc_description = Some(docs.ext_doc_description.clone())
}

// TODO: data.readonly/writeonly -> OverloadOf?
Expand Down
10 changes: 7 additions & 3 deletions compiler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions compiler/src/model/metamodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class Property {
docId?: string
extDocId?: string
extDocUrl?: string
extDocDesc?: string
serverDefault?: boolean | string | number | string[] | number[]
deprecation?: Deprecation
availability?: Availabilities
Expand Down Expand Up @@ -162,6 +163,7 @@ export abstract class BaseType {
docId?: string
extDocId?: string
extDocUrl?: string
extDocDesc?: string
deprecation?: Deprecation
/** If this endpoint has a quirk that needs special attention, give a short explanation about it */
esQuirk?: string
Expand Down Expand Up @@ -412,6 +414,7 @@ export class Endpoint {
docId?: string
extDocId?: string
extDocUrl?: string
extDocDesc?: string
deprecation?: Deprecation
availability: Availabilities
docTag?: string
Expand Down
12 changes: 12 additions & 0 deletions compiler/src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ export function hoistRequestAnnotations (
const docUrl = docIds.find(entry => entry[0] === value.trim())
assert(jsDocs, docUrl != null, `The @ext_doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
endpoint.extDocUrl = docUrl[1].replace(/\r/g, '')
const docDesc = docUrl[2].trim()
if (docDesc != null) {
endpoint.extDocDesc = docDesc
}
} else if (tag === 'availability') {
// The @availability jsTag is different than most because it allows
// multiple values within the same docstring, hence needing to parse
Expand Down Expand Up @@ -754,6 +758,10 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
const docUrl = docIds.find(entry => entry[0] === value.trim())
assert(jsDocs, docUrl != null, `The @ext_doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
type.extDocUrl = docUrl[1].replace(/\r/g, '')
const docDesc = docUrl[2].trim()
if (docDesc != null) {
type.extDocDesc = docDesc
}
} else if (tag === 'codegen_names') {
type.codegenNames = parseCommaSeparated(value)
assert(jsDocs,
Expand Down Expand Up @@ -826,6 +834,10 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
const docUrl = docIds.find(entry => entry[0] === value)
if (docUrl != null) {
property.extDocUrl = docUrl[1].replace(/\r/g, '')
const docDesc = docUrl[2].trim()
if (docDesc != null) {
property.extDocDesc = docDesc
}
}
} else if (tag === 'server_default') {
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}`)
Expand Down
2 changes: 2 additions & 0 deletions output/schema/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading